sync.order.cs 665 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210
  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. using NPOI.Util;
  48. using static NPOI.HSSF.Util.HSSFColor;
  49. using BizCom.Enum;
  50. using NPOI.POIFS.Properties;
  51. using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
  52. using static SiteCore.taoObj.Api_tmc_refund_info_Obj;
  53. namespace SiteCore.Handler
  54. {
  55. public partial class sync
  56. {
  57. public void get_erp_orderlist()
  58. {
  59. string poscode = CurrentUser.UserPost.Post.Code;
  60. DataStruct dStruct = GetPostStruct();
  61. //string a = SecurityHelper.DecryptSymmetric("BnK3+504SQ8=");
  62. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\(250924170328638492)-210x140mm-10个-UV转印贴彩色模切-GL-gzb520gzb-广东省-龙井《4765947843000325546-琳19890725》.ai");
  63. //apiHelper.Api_SyncOrderByTime("598825");
  64. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  65. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  66. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  67. //banniuApiHelper.sendLogisticsInfo(null);
  68. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  69. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  70. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  71. //int sid = commonHelper.autoDistributeToSupplier(entity);
  72. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  73. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1756945416000,\"deliveryType\":\"OFFLINE\",\"discountFee\":20.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1757118213000,\"lines\":[{\"latestDeliveryTime\":1757118213000,\"mark2\":[\"DELIVERED\"],\"num\":1,\"outerId\":\"JSBHUVZYT\",\"payment\":10.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i2/490100363/O1CN01pEaojF1EYIjYhp76h_!!490100363.jpg\",\"platServiceFee\":0.0,\"price\":30.0,\"refOlId\":\"4718408366815008220\",\"refSkuId\":\"5139754537453\",\"refSpuId\":\"641811002682\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":10.0,\"singleFee\":10.0,\"spuOuterId\":\"JSBHUVZYT\",\"standards\":\"【撕膜留字 | 易撕无残留】\",\"status\":\"SHIPPED\",\"title\":\"水晶标贴UV转印贴logo定制透明标识贴纸设计金属商标烫金标签定做\",\"totalFee\":10.0,\"totalPrice\":30.0,\"totalSellPrice\":10.0}],\"logisticsOrderNo\":\"YT7568465598389\",\"mark2\":[],\"modifyTime\":1756946987000,\"openBuyerId\":\"AAEVRHraABkUZRPgSx3gFRIR\",\"openBuyerNick\":\"a**\",\"openSellerNick\":\"琳19890725\",\"orderSource\":\"SYNC\",\"orderTime\":1756945412000,\"payTime\":1756945413000,\"payment\":10.0,\"platServiceFee\":0.0,\"posCode\":\"guliang\",\"posId\":598696,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0,\"logisticList\":[{\"logisticNo\":\"YT7568465598389\",\"logisticName\":\"圆通速递\"}]},\"receivedPayment\":0.0,\"receiverCity\":\"苏州市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"吴江区\",\"receiverId\":\"871dbaa880a955e031c5061436d7a5c1$\",\"receiverState\":\"江苏省\",\"receiverTown\":\"江陵街道\",\"refOid\":\"4718408366815008220\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"寄样-不干胶-uv转印贴小尺寸字母银色黑色-aa_小f-龙井-5,寄样-不干胶-金属标字母银色黑色-aa_小f-龙井-5\",\"serviceFee\":0.0,\"shippingTime\":1756946983000,\"status\":\"SHIPPED\",\"sysTags\":[],\"totalFee\":10.0,\"totalPrice\":30.0,\"totalSellPrice\":10.0,\"type\":\"SALE\"}}");
  74. //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}}");
  75. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  76. //string res = apiHelper.API_GetWaybill("YTO-PDD-CYT", "250703-469248284251412");
  77. //preSalesHelper.dealMessageInfo("{\"bizOrder\":{\"id\":235819,\"parentId\":null,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderNo\":\"4624034580248409502\",\"shopId\":4,\"shopCode\":\"aolifu\",\"customerId\":345874,\"customerServiceId\":3184,\"thirdOrderId\":\"4624034580248409502\",\"orderPlatform\":\"TMALL\",\"openBuyerId\":\"AAEORHraABkUZRHgSx6ksuhU\",\"openBuyerNick\":\"tb278604202340\",\"openSellerNick\":\"奥丽芙旗舰店\",\"productUrl\":null,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"payAmount\":125.0,\"unrefundedAmount\":125.0,\"discountAmount\":5.0,\"csDiscountAmount\":-35.0,\"num\":13,\"province\":\"山西省\",\"city\":\"吕梁市\",\"area\":\"孝义市\",\"receiverTown\":\"孝义市\",\"address\":null,\"thirdReceiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"receiverName\":null,\"receiverMobile\":null,\"weChatId\":null,\"phone\":null,\"designContent\":\"\",\"designPics\":\"[]\",\"weChatQrPics\":\"[]\",\"addressFileUrl\":\"\",\"thirdFlag\":\"NONE\",\"remark\":null,\"sellerRemark\":\"\",\"buyerRemark\":\"\",\"timeoutRemark\":null,\"discountRemark\":null,\"status\":\"NOT_SHIPPED\",\"refundStatus\":0,\"internalStatus\":2,\"auditStatus\":null,\"auditUserId\":null,\"auditor\":null,\"customTag\":null,\"isRepurchase\":false,\"isOffline\":false,\"paymentFile\":null,\"orderTime\":\"2025-07-10 14:46:13\",\"modifyTime\":\"2025-07-10 14:46:37\",\"payTime\":\"2025-07-10 14:46:37\",\"confirmTime\":\"2025-07-10 14:51:23\",\"auditTime\":null,\"shippingTime\":null,\"finishTime\":null,\"erpCustomerServiceId\":3319,\"openBuyerID\":\"AAEORHraABkUZRHgSx6ksuhU\",\"orderFrom\":\"10\",\"receiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"bizOrderItems\":[{\"id\":310334,\"orderId\":235819,\"thirdOrderItemId\":\"4624034580248409502\",\"thirdSpuId\":\"740203900330\",\"thirdSkuId\":\"0\",\"title\":\"pvc贴纸定制防水不干胶圆形贴标自粘商标logo广告二维码标签印刷\",\"specification\":\"\",\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2433960672/O1CN01D0ZzzR1GppCHSoBjD_!!4611686018427382496-0-item_pic.jpg\",\"price\":10.0,\"sellPrice\":9.62,\"amount\":9.62,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"totalAmount\":125.0,\"num\":13,\"refundStatus\":\"NO_REFUND\"}],\"bizOrderSplits\":[{\"id\":151557,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328848\",\"splitNo\":\"C1_4624034580248409502\",\"splitInfoNo\":\"C2+1\",\"splitAmount\":52.64,\"quoteRecordId\":520208,\"quoteAmount\":40.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328848)-[C2+1]-80x20mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328848\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":40.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":80.00,\"width\":20.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"80x20mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":40.00,\"numberType\":\"\",\"isDianziOrder\":0},{\"id\":151558,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328853\",\"splitNo\":\"C2_4624034580248409502\",\"splitInfoNo\":\"C2+2\",\"splitAmount\":72.36,\"quoteRecordId\":520209,\"quoteAmount\":55.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328853)-[C2+2]-90x50mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328853\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":55.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":90.00,\"width\":50.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"90x50mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":55.00,\"numberType\":\"\",\"isDianziOrder\":0}]}}");
  78. /*string path = "C:\\Users\\231010\\Downloads\\tids.txt";
  79. string path1 = "C:\\Users\\231010\\Downloads\\tid.txt";
  80. string tids = File.ReadAllText(path);
  81. List<string> list = tids.Split(',').ToList();
  82. int index = 0;
  83. foreach (string item in list)
  84. {
  85. CeErpTrade ceErpTrade = CeErpTrade.Get(item.Replace("'", ""));
  86. try
  87. {
  88. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_nick = '{0}' or buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  89. if (string.IsNullOrEmpty(ceErpTrade.buyer_nick))
  90. {
  91. sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  92. }
  93. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  94. List<string> tidList = new List<string>();
  95. if (dataTable != null && dataTable.Rows.Count > 0)
  96. {
  97. foreach (DataRow row in dataTable.Rows)
  98. {
  99. tidList.Add("'" + row["tid"].ToString() + "'");
  100. }
  101. }
  102. if (tidList.Count > 0)
  103. {
  104. sql = string.Format("SELECT count(*) as number FROM [dbo].[CE_ErpTradeCell] WITH(NOLOCK) WHERE tid in ({0}) AND IsSample = 0 ", string.Join(",", tidList));
  105. dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  106. if (dataTable != null && dataTable.Rows.Count > 0)
  107. {
  108. int count = Convert.ToInt32(dataTable.Rows[0]["number"]);
  109. if (count > 0)
  110. {
  111. Debug.WriteLine(index++);
  112. continue;
  113. }
  114. }
  115. }
  116. File.AppendAllText(path1, ceErpTrade.tid + "\n");
  117. }
  118. catch (Exception e)
  119. {
  120. File.AppendAllText(path1, "e:" + ceErpTrade.tid + "\n");
  121. }
  122. Debug.WriteLine(index++);
  123. }*/
  124. //string a = commonHelper.convertQNMemo("48x61mm-4款各40个-铜版纸-不干胶-覆膜模切-tb963561715-金陵-顺丰到付.粘成品.6.5cm牙签-老客户改稿找金陵拉群-16发", CeErpTradeCell.GetByCtid("2879265072537265386"));
  125. List<string> lw = new List<string>();
  126. string tid = GetPostString("ctid");
  127. string date1 = GetPostString("date1");
  128. //12-1 修改
  129. string urgent = GetPostString("urgent");
  130. string back = GetPostString("back");
  131. string offlineSearch = GetPostString("offlineSearch");
  132. int paramsCount = 0;
  133. if (!string.IsNullOrWhiteSpace(urgent))
  134. {
  135. if (urgent.Equals("true"))
  136. {
  137. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  138. }
  139. }
  140. if (!string.IsNullOrWhiteSpace(back))
  141. {
  142. if (back.Equals("true"))
  143. {
  144. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  145. }
  146. }
  147. if (!string.IsNullOrWhiteSpace(offlineSearch))
  148. {
  149. if (offlineSearch.Equals("true"))
  150. {
  151. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  152. }
  153. }
  154. //end
  155. string date2 = GetPostString("date2");
  156. string buyernick = GetPostString("buyer_nick");
  157. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  158. {
  159. if (tid.Length <= 0 && buyernick.Length <= 0)
  160. {
  161. return;
  162. }
  163. }
  164. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  165. {
  166. if (tid.Length > 0)
  167. {
  168. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  169. if (ceErpTradeCell != null)
  170. {
  171. tid = ceErpTradeCell.tid;
  172. }
  173. List<string> select_tid = getTidByCtidMore(tid);
  174. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  175. }
  176. if (buyernick.Length > 0)
  177. {
  178. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  179. }
  180. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  181. if (dw.Length > 0)
  182. {
  183. lw.Add(dw);
  184. }
  185. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  186. {
  187. string usershop = CurrentUser.User.pemShop;
  188. lw.Add(string.Format("ShopId in ({0})", usershop));
  189. }
  190. }
  191. else
  192. {
  193. if (ex_psize == 0)
  194. {
  195. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  196. }
  197. if (PKey != "admin" && poscode != "SysAdmin")
  198. {
  199. string usershop = CurrentUser.User.pemShop;
  200. lw.Add(string.Format("ShopId in ({0})", usershop));
  201. paramsCount++;
  202. }
  203. }
  204. string uploaddate1 = GetPostString("uploaddate1");
  205. string uploaddate2 = GetPostString("uploaddate2");
  206. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  207. if (update.Length > 0) lw.Add(update);
  208. string deliverydate1 = GetPostString("deliverydate1");
  209. string deliverydate2 = GetPostString("deliverydate2");
  210. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  211. if (deliverydate.Length > 0)
  212. {
  213. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  214. };
  215. string shopname = GetPostString("shopname");
  216. if (shopname.Length > 0)
  217. {
  218. CeErpShop ceErpShop = CeErpShop.GetShopIdByName(shopname);
  219. if (ceErpShop != null)
  220. {
  221. lw.Add(string.Format("shopId = {0}", ceErpShop.ID));
  222. }
  223. }
  224. string addwechat = GetPostString("addwechat");
  225. if (addwechat.Length > 0)
  226. {
  227. int addWt = Convert.ToInt32(addwechat);
  228. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  229. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  230. }
  231. string customer = GetPostString("customer");
  232. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  233. string design = GetPostString("design");
  234. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  235. string orderState = GetPostString("orderState");
  236. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  237. string address = GetPostString("address");
  238. 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));
  239. string sellermemo = GetPostString("seller_memo");
  240. if (sellermemo.Length > 0)
  241. {
  242. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  243. }
  244. string otherMemo = GetPostString("otherMemo");
  245. if (otherMemo.Length > 0)
  246. {
  247. lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  248. }
  249. string backReason = GetPostString("backReason");
  250. if (backReason.Length > 0)
  251. {
  252. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  253. }
  254. string apdate1 = GetPostString("apdate1");
  255. string apdate2 = GetPostString("apdate2");
  256. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  257. if (dwap.Length > 0) lw.Add(dwap);
  258. string price1 = GetPostString("price1");
  259. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  260. string price2 = GetPostString("price2");
  261. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  262. string isoldcustomer = GetPostString("isoldcus");
  263. string spudata = GetPostString("spudata");
  264. if ("0".Equals(spudata))
  265. {
  266. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  267. }
  268. if ("1".Equals(spudata))
  269. {
  270. lw.Add(string.Format("spu_id <> ''"));
  271. }
  272. string finishdate1 = GetPostString("finishdate1");
  273. string finishdate2 = GetPostString("finishdate2");
  274. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  275. bool isFinish = false;
  276. if (finishdate.Length > 0)
  277. {
  278. lw.Add(finishdate);
  279. isFinish = true;
  280. paramsCount++;
  281. }
  282. if (isoldcustomer.Length > 0)
  283. {
  284. if ("2".Equals(isoldcustomer))
  285. {
  286. lw.Add(string.Format("VipCustomer=1"));
  287. }
  288. else
  289. {
  290. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  291. }
  292. }
  293. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  294. if (ex_psize > 0)
  295. {
  296. int UserID = CurrentUser.UserID;
  297. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  298. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  299. {
  300. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  301. }
  302. dStruct.Order = "pay_time desc";
  303. }
  304. string isNew = GetPostString("isNew");
  305. if (isNew == "true")
  306. {
  307. lw.Add(string.Format("IsNew = {0}", 1));
  308. }
  309. string overtime = GetPostString("overtime");
  310. if (overtime == "1")
  311. {
  312. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  313. }
  314. String usePost = CurrentUser.UserPost.Post.Code;
  315. if (usePost.Equals("Operation") == true)
  316. {
  317. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  318. }
  319. else
  320. {
  321. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  322. }
  323. //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";
  324. if (dStruct.PageSize == 100000)
  325. {
  326. dStruct.Order = "";
  327. }
  328. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  329. DataTable dt = null;
  330. string tablename = "view_orderlist";
  331. if (isFinish)
  332. {
  333. tablename = "view_orderlist_end";
  334. }
  335. dt = WebCache.GetData(tablename, dStruct);
  336. if (dt != null && dt.Rows.Count > 0)
  337. {
  338. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  339. foreach (DataRow dr in dt.Rows)
  340. {
  341. try
  342. {
  343. if (dr["refund_fees"] != null)
  344. {
  345. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  346. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  347. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  348. if (payment == refund_fees)
  349. {
  350. dr["refund_fees"] = Math.Round(refund_fees, 2);
  351. }
  352. else if (refund_fees == total_fee)
  353. {
  354. dr["refund_fees"] = payment;
  355. }
  356. else
  357. {
  358. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  359. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  360. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  361. }
  362. }
  363. // 对象操作
  364. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  365. ceErpTradeCell.ctid = dr["ctid"].ToString();
  366. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  367. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  368. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  369. if (dStruct.PageSize != 100000)
  370. {
  371. if (dr["DispatchSort"].ToString() == "2")
  372. {
  373. dr["gongchuang"] = 200;
  374. }
  375. else if ("外协".Equals(dr["ToType"].ToString()))
  376. {
  377. dr["gongchuang"] = 200;
  378. }
  379. else if ("内部".Equals(dr["ToType"].ToString()))
  380. {
  381. dr["gongchuang"] = -1;
  382. }
  383. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  384. {
  385. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  386. dr["gongchuang"] = response.code;
  387. }
  388. }
  389. }
  390. catch (NullReferenceException ex)
  391. {
  392. // 处理空引用异常
  393. dr["refund_fees"] = "0.00";
  394. }
  395. }
  396. }
  397. writeGridDataTableJson(dStruct.TotalCount, dt);
  398. }
  399. public void get_erp_orderlist_sumprice()
  400. {
  401. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  402. return;
  403. List<string> lw = new List<string>();
  404. string tid = GetPostString("ctid");
  405. string date1 = GetPostString("date1");
  406. string date2 = GetPostString("date2");
  407. if (tid.Length > 0 || date1.Length > 0)
  408. {
  409. lw.Add(string.Format("ctid like '%{0}%'", tid));
  410. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  411. if (dw.Length > 0) lw.Add(dw);
  412. }
  413. else
  414. {
  415. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  416. }
  417. string shopname = GetPostString("shopname");
  418. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  419. string buyernick = GetPostString("buyer_nick");
  420. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  421. string customer = GetPostString("customer");
  422. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  423. string design = GetPostString("design");
  424. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  425. string orderState = GetPostString("orderState");
  426. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  427. string address = GetPostString("address");
  428. 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));
  429. string sellermemo = GetPostString("seller_memo");
  430. if (sellermemo.Length > 0)
  431. {
  432. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  433. }
  434. string apdate1 = GetPostString("apdate1");
  435. string apdate2 = GetPostString("apdate2");
  436. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  437. if (dwap.Length > 0) lw.Add(dwap);
  438. string price1 = GetPostString("price1");
  439. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  440. string price2 = GetPostString("price2");
  441. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  442. string isoldcustomer = GetPostString("isoldcus");
  443. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  444. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  445. if (PKey != "admin")
  446. {
  447. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  448. lw.Add(string.Format("shopId in ({0})", usershop));
  449. }
  450. //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";
  451. string mainWhere = string.Join(" and ", lw.ToArray());
  452. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  453. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  454. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  455. decimal total = 0;
  456. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  457. {
  458. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  459. }
  460. var res = new
  461. {
  462. data = total
  463. };
  464. string ro_jsond = JsonConvert.SerializeObject(res);
  465. returnSuccess(ro_jsond);
  466. return;
  467. }
  468. public void get_erp_CustomerServiceGather()
  469. {
  470. string userWhere = "", orderWhere = "";
  471. List<string> lw = new List<string>();
  472. string customer = GetPostString("customer");
  473. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  474. string shopname = GetPostString("shopname");
  475. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  476. string date1 = GetPostString("date1");
  477. string date2 = GetPostString("date2");
  478. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  479. if (dw.Length > 0) lw.Add(dw);
  480. orderWhere = string.Join(" and ", lw.ToArray());
  481. 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 " +
  482. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  483. "left join " +
  484. "( " +
  485. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  486. ") as b on a.ID = b.CustomerUserId " +
  487. "left join " +
  488. "( " +
  489. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  490. ") as d on a.ID = d.CustomerUserId " +
  491. "left join " +
  492. "( " +
  493. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  494. ") as e on a.ID = e.CustomerUserId " +
  495. "left join " +
  496. "( " +
  497. " select CustomerUserId, RefundCount, RefundSum from " +
  498. " ( " +
  499. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  500. " from CE_ErpTradeRefund a " +
  501. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  502. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  503. " group by CustomerUserId " +
  504. " ) as a " +
  505. ") as f on a.ID = f.CustomerUserId " +
  506. "where a.PostCode = 'CustomerService'",
  507. userWhere, orderWhere);
  508. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  509. writeGridDataTableJson(dt.Rows.Count, dt);
  510. //writeGridDataTableJson(dt.Rows.Count, dt);
  511. }
  512. //设计汇总
  513. public void get_erp_DesignerGather()
  514. {
  515. string userWhere = "", orderWhere = "";
  516. List<string> lw = new List<string>();
  517. string Designer = GetPostString("designer");
  518. int org = GetPostInt("org");
  519. if (Designer.Length > 0)
  520. {
  521. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  522. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  523. }
  524. else if (org > 0)
  525. {
  526. userWhere = string.Format(" where OrgID ={0}", org);
  527. }
  528. string shopname = GetPostString("shopname");
  529. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  530. string state = GetPostString("state");
  531. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  532. string OrderArea = GetPostString("order_area");
  533. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  534. string date1 = GetPostString("date1");
  535. string date2 = GetPostString("date2");
  536. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  537. if (dw.Length > 0) lw.Add(dw);
  538. string UpDate1 = GetPostString("UpDate1");
  539. string UpDate2 = GetPostString("UpDate2");
  540. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  541. if (dw.Length > 0) lw.Add(dw);
  542. orderWhere = string.Join(" and ", lw.ToArray());
  543. 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 (" +
  544. "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 " +
  545. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  546. "left join " +
  547. "( " +
  548. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  549. ") as b on a.ID = b.DesignUserId " +
  550. "left join " +
  551. "( " +
  552. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  553. ") as d on a.ID = d.DesignUserId " +
  554. "left join " +
  555. "( " +
  556. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  557. ") as e on a.ID = e.DesignUserId " +
  558. "left join " +
  559. "( " +
  560. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  561. ") as g on a.ID = g.DesignUserId " +
  562. "left join " +
  563. "( " +
  564. " select CustomerUserId, RefundCount, RefundSum from " +
  565. " ( " +
  566. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  567. " from CE_ErpTradeRefund a " +
  568. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  569. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  570. " group by CustomerUserId " +
  571. " ) as a " +
  572. ") as f on a.ID = f.CustomerUserId " +
  573. "where a.PostCode = 'Designer') as z",
  574. userWhere, orderWhere);
  575. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  576. writeGridDataTableJson(dt.Rows.Count, dt);
  577. }
  578. //删除tradecell的订单
  579. public void del_erp_cellorder()
  580. {
  581. if (UrlPostParmsCheck("ctid"))
  582. {
  583. string eid = GetPostString("ctid");
  584. CeErpTradeCell.DelByCtid(eid);
  585. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  586. returnSuccessMsg("删除成功");
  587. }
  588. }
  589. public void clear_erp_refundstate()
  590. {
  591. if (UrlPostParmsCheck("ids"))
  592. {
  593. string eids = GetPostString("ids");
  594. string[] ctidList = eids.Split(',');
  595. foreach (string ctid in ctidList)
  596. {
  597. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  598. if (entity != null)
  599. {
  600. entity.IsRefund = 0;
  601. entity.Update();
  602. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  603. }
  604. else
  605. continue;
  606. }
  607. returnSuccessMsg("操作成功");
  608. return;
  609. }
  610. returnErrorMsg("缺少必要参数");
  611. }
  612. public void set_erp_urgency()
  613. {
  614. if (UrlPostParmsCheck("ctid"))
  615. {
  616. string eid = GetPostString("ctid");
  617. CeErpTradeCell entity = null;
  618. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  619. if (entity != null)
  620. {
  621. double prices = commonHelper.calculationPrice(entity);
  622. if (prices <= 100)
  623. {
  624. returnErrorMsg("此订单金额不足100元,无法加急。");
  625. return;
  626. }
  627. string utime = GetPostString("urgencytime");
  628. if (utime.Length > 0)
  629. {
  630. entity.UrgencyTime = Convert.ToDateTime(utime);
  631. }
  632. else
  633. {
  634. returnErrorMsg("请选择加急时间");
  635. return;
  636. }
  637. if (entity.OrderState <= 4)
  638. {
  639. //entity.seller_memo = entity.seller_memo + "-加急";
  640. string smemo = entity.seller_memo;
  641. int kindex = smemo.IndexOf(")");
  642. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  643. if (lastoneStr != "-")
  644. {
  645. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  646. }
  647. string prememo = smemo.Substring(0, kindex + 2);
  648. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  649. int lastkindex = lastmemo.IndexOf("(");
  650. DateTime urgtime = Convert.ToDateTime(utime);
  651. string newlastmemo = "";
  652. if (lastkindex == 0)
  653. {
  654. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  655. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  656. }
  657. else
  658. {
  659. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  660. }
  661. entity.seller_memo = prememo + newlastmemo;
  662. }
  663. entity.IsUrgency = true;
  664. entity.UpdateTime = DateTime.Now;
  665. entity.Update();
  666. ApiVo apiVo = new ApiVo();
  667. apiVo.orderNumber = entity.ctid;
  668. apiVo.actionName = "changeDesign";
  669. apiVo.orderRemarks = entity.seller_memo;
  670. apiVo.remarkSign = 3;
  671. designHelper.API_WorkCore(apiVo); //changeDesign
  672. CeErpSukuraData.createInfo(entity.ctid, 7);
  673. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  674. returnSuccessMsg("设置成功!");
  675. return;
  676. }
  677. returnErrorMsg("找不到记录");
  678. }
  679. }
  680. public void set_erp_reset()
  681. {
  682. if (UrlPostParmsCheck("ctid"))
  683. {
  684. string eid = GetPostString("ctid");
  685. CeErpTradeCell entity = null;
  686. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  687. if (entity != null)
  688. {
  689. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  690. {
  691. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  692. {
  693. returnErrorMsg("财务要求已下单已发货无法重置");
  694. return;
  695. }
  696. }
  697. entity.IsUrgency = false;
  698. entity.seller_memo = "";
  699. entity.OtherMemo = "";
  700. entity.OrderState = 0;
  701. entity.IsReturn = 0;
  702. //entity.IsRefund = 0;
  703. entity.MemoOpt = 0;
  704. entity.AfterSaleState = 0;
  705. entity.AfterSaleResponsible = "";
  706. entity.AfterSaleUserId = 0;
  707. entity.IsNeedBill = 0;
  708. entity.CustomerUserId = 0;
  709. entity.DesignUserId = 0;
  710. entity.SupplierId = 0;
  711. entity.PlaceUserId = 0;
  712. entity.ptid = "";
  713. entity.IsSample = 0;
  714. entity.IsXianHuo = 0;
  715. entity.isDianziOrder = 0;
  716. entity.DispatchSort = 0;
  717. entity.IsVerifyToSupplier = false;
  718. entity.FinishPlaceTime = null;
  719. entity.Update();
  720. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  721. if (trade != null)
  722. {
  723. trade.seller_memo = "";
  724. trade.Update();
  725. }
  726. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  727. returnSuccessMsg("重置成功!");
  728. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  729. if (desginBill != null)
  730. {
  731. desginBill.isDel = 1;
  732. desginBill.Update();
  733. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  734. }
  735. ApiVo apiVo = new ApiVo();
  736. apiVo.orderNumber = entity.ctid;
  737. apiVo.actionName = "resetDesign";
  738. designHelper.API_WorkCore(apiVo);//resetDesign
  739. return;
  740. }
  741. returnErrorMsg("找不到记录");
  742. }
  743. }
  744. public void save_erp_sellermemo()
  745. {
  746. if (UrlPostParmsCheck("ctid"))
  747. {
  748. string ctid = GetPostString("ctid");
  749. CeErpTradeCell entity = null;
  750. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  751. if (entity != null)
  752. {
  753. string memo = GetPostString("seller_memo");
  754. string qn_memo = GetPostString("qn_memo");
  755. memo = memo.Replace(" ", "");
  756. if (memo.Contains("补差"))
  757. {
  758. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  759. return;
  760. }
  761. List<string> bitList = new List<string>
  762. {
  763. "\\","/",":","*","?", "\"","<" ,">","|"
  764. };
  765. bool isIn = false;
  766. foreach (string bit in bitList)
  767. {
  768. if (memo.Contains(bit))
  769. {
  770. isIn = true;
  771. }
  772. }
  773. if (isIn)
  774. {
  775. returnErrorMsg("不能使用 一些符合作为文件名");
  776. return;
  777. }
  778. if (entity.seller_memo != memo)
  779. {
  780. if (entity.IsSample == 2)
  781. {
  782. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  783. return;
  784. }
  785. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  786. {
  787. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  788. {
  789. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  790. return;
  791. }
  792. /*if (CurrentUser.UserPost.Post.Code != "Place")
  793. {
  794. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  795. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  796. {
  797. returnErrorMsg("售前系统订单无法再此修改!");
  798. return;
  799. }
  800. }*/
  801. }
  802. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  803. }
  804. if (!string.IsNullOrEmpty(qn_memo) && !(entity.IsSample > 0 || entity.ctid.Contains("N_") || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物")))
  805. {
  806. if (entity.OrderState >= 5)
  807. {
  808. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  809. return;
  810. }
  811. string delMemo = commonHelper.convertQNMemo(qn_memo, ref entity);
  812. if (string.IsNullOrEmpty(delMemo))
  813. {
  814. returnErrorMsg("备注不规范,无法识别");
  815. return;
  816. }
  817. memo = delMemo;
  818. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统千牛修改为:" + memo, entity.OrderState, 1);
  819. }
  820. commonHelper.getCytPrice(entity);
  821. int memoopt = GetPostInt("MemoOpt");
  822. Boolean ismemoopt = false;
  823. if (memoopt > 0)
  824. {
  825. string stropt = "";
  826. if (memoopt == 1)
  827. {
  828. stropt = "“改稿”";
  829. ismemoopt = true;
  830. }
  831. else if (memoopt == 2)
  832. {
  833. stropt = "“定稿”";
  834. }
  835. else if (memoopt == 3)
  836. {
  837. stropt = "“查货”";
  838. CeErpSukuraData.createInfo(entity.ctid, 6);
  839. }
  840. entity.MemoOpt = Convert.ToInt32(memoopt);
  841. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  842. }
  843. if (entity.OrderState < 5)
  844. {
  845. memo = memo.Replace("(", "(");
  846. memo = memo.Replace(")", ")");
  847. }
  848. /* if (entity.OrderState < 3)
  849. {
  850. entity.DispatchSort = 0;
  851. }*/
  852. entity.seller_memo = memo;
  853. entity.UpdateTime = DateTime.Now;
  854. entity.Update();
  855. ApiVo apiVo = new ApiVo();
  856. apiVo.orderNumber = entity.ctid;
  857. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  858. apiVo.orderRemarks = memo;
  859. apiVo.remarkSign = memoopt;
  860. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  861. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  862. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  863. {
  864. dataHelper.api_orderBack(entity.ctid, "0", "");
  865. }
  866. if (entity.seller_memo.Contains("改稿"))
  867. {
  868. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  869. }
  870. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  871. returnSuccessMsg("保存成功!");
  872. return;
  873. }
  874. returnErrorMsg("找不到记录");
  875. }
  876. }
  877. public void ins_erp_checkorder()
  878. {
  879. if (UrlPostParmsCheck("ctid"))
  880. {
  881. string ctid = GetPostString("ctid");
  882. CeErpTradeCell entity = null;
  883. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  884. if (entity != null)
  885. {
  886. if (entity.OrderState < 6)
  887. {
  888. returnErrorMsg("下单完成后才可查货");
  889. return;
  890. }
  891. /*if (entity.OrderState > 6)
  892. {
  893. returnErrorMsg("订单已发货");
  894. return;
  895. }*/
  896. if (entity.FinishPlaceTime != null)
  897. {
  898. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  899. {
  900. returnErrorMsg("下单时间不足,无法查货");
  901. return;
  902. }
  903. }
  904. entity.MemoOpt = 3;
  905. entity.CheckOrderTime = DateTime.Now;
  906. entity.UpdateTime = DateTime.Now;
  907. entity.Update();
  908. CeErpSukuraData.createInfo(entity.ctid, 6);
  909. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  910. returnSuccessMsg("操作成功!");
  911. return;
  912. }
  913. returnErrorMsg("找不到记录");
  914. }
  915. }
  916. public void save_erp_othermemo()
  917. {
  918. if (UrlPostParmsCheck("ctid"))
  919. {
  920. string ctid = GetPostString("ctid");
  921. CeErpTradeCell entity = null;
  922. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  923. if (entity != null)
  924. {
  925. entity.OtherMemo = GetPostString("otherMemo");
  926. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  927. {
  928. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  929. StringBuilder sql = new StringBuilder();
  930. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  931. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  932. if (dt != null && dt.Rows.Count > 0)
  933. {
  934. foreach (DataRow dr in dt.Rows)
  935. {
  936. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  937. {
  938. //品类一直
  939. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  940. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  941. if (ceErpSampleCustomer == null)
  942. {
  943. ceErpSampleCustomer = new CeErpSampleCustomer();
  944. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  945. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  946. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  947. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  948. ceErpSampleCustomer.shopId = entity.ShopId;
  949. }
  950. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  951. ceErpSampleCustomer.lastTid = entity.tid;
  952. if (ceErpSampleCustomer.ID > 0)
  953. {
  954. ceErpSampleCustomer.Update();
  955. }
  956. else
  957. {
  958. ceErpSampleCustomer.Create();
  959. }
  960. }
  961. }
  962. }
  963. }
  964. //if (entity.IsOldCustomer == 1)
  965. //{
  966. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  967. //{
  968. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  969. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  970. //}
  971. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  972. //{
  973. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  974. // {
  975. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  976. // {
  977. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  978. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  979. // }
  980. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  981. // {
  982. // entity.OrderState = 2;
  983. // entity.DesignUserId = 0;
  984. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  985. // }
  986. // else
  987. // {
  988. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  989. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  990. // }
  991. // }
  992. //}
  993. //}
  994. entity.UpdateTime = DateTime.Now;
  995. entity.Update();
  996. returnSuccessMsg("保存成功!");
  997. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  998. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  999. if (entity.OtherMemo.Contains("改稿"))
  1000. {
  1001. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  1002. }
  1003. return;
  1004. }
  1005. returnErrorMsg("找不到记录");
  1006. }
  1007. }
  1008. public void save_erp_customermemo()
  1009. {
  1010. if (UrlPostParmsCheck("ctid"))
  1011. {
  1012. string ctid = GetPostString("ctid");
  1013. CeErpTradeCell entity = null;
  1014. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1015. if (entity != null)
  1016. {
  1017. entity.UpdateTime = DateTime.Now;
  1018. entity.CustomerMemo = GetPostString("CustomerMemo");
  1019. entity.Update();
  1020. ApiVo apiVo = new ApiVo();
  1021. apiVo.orderNumber = entity.ctid;
  1022. apiVo.actionName = "followRemarks";
  1023. apiVo.orderRemarks = entity.CustomerMemo;
  1024. designHelper.API_WorkCore(apiVo);//followRemarks
  1025. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  1026. returnSuccessMsg("保存成功!");
  1027. return;
  1028. }
  1029. returnErrorMsg("找不到记录");
  1030. }
  1031. }
  1032. public void upd_erp_addmemotag()
  1033. {
  1034. if (UrlPostParmsCheck("ctid"))
  1035. {
  1036. ;
  1037. string eid = GetPostString("ctid");
  1038. string sfTagstr = GetPostString("memotag");
  1039. CeErpTradeCell entity = null;
  1040. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1041. if (entity != null)
  1042. {
  1043. ApiVo apiVo = new ApiVo();
  1044. if (entity.OrderState == 0)
  1045. {
  1046. returnErrorMsg("请先领单");
  1047. return;
  1048. }
  1049. //撤销顺丰
  1050. if (sfTagstr == "撤销顺丰")
  1051. {
  1052. entity.IsSF = 0;
  1053. string reMsg = "";
  1054. string oldmemo = entity.seller_memo;
  1055. if (entity.OrderState < 5)
  1056. {
  1057. oldmemo = oldmemo.Replace("顺丰到付", "");
  1058. oldmemo = oldmemo.Replace("顺丰寄付", "");
  1059. entity.seller_memo = oldmemo;
  1060. }
  1061. else
  1062. {
  1063. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  1064. {
  1065. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  1066. }
  1067. }
  1068. entity.Update();
  1069. apiVo.orderNumber = entity.ctid;
  1070. apiVo.actionName = "orderRemarks";
  1071. apiVo.orderRemarks = entity.seller_memo;
  1072. apiVo.isSf = entity.IsSF.ToString();
  1073. designHelper.API_WorkCore(apiVo);//orderRemarks
  1074. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  1075. returnSuccessMsg("撤销成功!" + reMsg);
  1076. return;
  1077. }
  1078. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  1079. {
  1080. //string oldmemo = entity.seller_memo;
  1081. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1082. string sfStr = GetPostString("memotag");
  1083. string smemo = entity.seller_memo;
  1084. int kindex = smemo.IndexOf(")");
  1085. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1086. if (lastoneStr != "-")
  1087. {
  1088. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1089. }
  1090. string prememo = smemo.Substring(0, kindex + 2);
  1091. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1092. int lastkindex = lastmemo.IndexOf("(");
  1093. string newlastmemo = "";
  1094. if (lastkindex == 0)
  1095. {
  1096. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1097. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1098. }
  1099. else
  1100. {
  1101. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1102. }
  1103. entity.seller_memo = prememo + newlastmemo;
  1104. }
  1105. string sfTagMSg = "";
  1106. if (sfTagstr == "顺丰寄付")
  1107. {
  1108. entity.IsSF = 1;
  1109. sfTagMSg = "顺丰寄付";
  1110. }
  1111. else if (sfTagstr == "顺丰到付")
  1112. {
  1113. entity.IsSF = 2;
  1114. sfTagMSg = "顺丰到付";
  1115. }
  1116. if (entity.SupplierId == 19 && entity.OrderState == 6)
  1117. {
  1118. string deliveryWayName = "";
  1119. if (sfTagstr == "撤销顺丰")
  1120. {
  1121. sfTagstr = "普通快递";
  1122. }
  1123. if (sfTagstr == "顺丰寄付")
  1124. {
  1125. sfTagstr = "顺丰特快寄付";
  1126. }
  1127. if (sfTagstr == "顺丰到付")
  1128. {
  1129. sfTagstr = "顺丰特快到付";
  1130. }
  1131. string result = apichyHelper.updateExpressMark(entity.tid, sfTagstr);
  1132. if ("修改失败".Equals(result))
  1133. {
  1134. returnErrorMsg("修改失败");
  1135. return;
  1136. }
  1137. }
  1138. entity.Update();
  1139. apiVo = new ApiVo();
  1140. apiVo.orderNumber = entity.ctid;
  1141. apiVo.actionName = "orderRemarks";
  1142. apiVo.orderRemarks = entity.seller_memo;
  1143. apiVo.isSf = entity.IsSF.ToString();
  1144. designHelper.API_WorkCore(apiVo);//orderRemarks
  1145. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1146. returnSuccessMsg("标记成功!");
  1147. return;
  1148. }
  1149. returnErrorMsg("找不到记录");
  1150. }
  1151. }
  1152. public void upd_erp_ordertag()
  1153. {
  1154. if (UrlPostParmsCheck("ctid"))
  1155. {
  1156. string eid = GetPostString("ctid");
  1157. CeErpTradeCell entity = null;
  1158. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1159. if (entity != null)
  1160. {
  1161. int tag = GetPostInt("wechattag");
  1162. //if(tag==4 && entity.IsSample == 2)
  1163. //{
  1164. // returnErrorMsg("补差价单不能标记微信单");
  1165. // return;
  1166. //}
  1167. entity.wechatTag = tag;
  1168. entity.Update();
  1169. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1170. if (tag == 1)
  1171. {
  1172. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1173. if (cash == null)
  1174. {
  1175. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1176. cash = new CeErpReturnCash();
  1177. cash.tid = entity.tid;
  1178. cash.seller_nick = main.seller_nick;
  1179. cash.payment = trade.payment;
  1180. cash.buyer_nick = main.buyer_nick;
  1181. cash.cashstate = 0;
  1182. cash.rtype = "微信返现";
  1183. cash.returnprice = 0;
  1184. cash.created = DateTime.Now;
  1185. cash.con = "订单标记微信单";
  1186. cash.img = "";
  1187. cash.applyuserid = CurrentUser.UserID;
  1188. cash.Create();
  1189. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1190. }
  1191. else
  1192. {
  1193. cash.cashstate = 0;
  1194. cash.Update();
  1195. }
  1196. CeErpSukuraData.createInfo(entity.ctid, 9);
  1197. }
  1198. else if (tag == 2)
  1199. {
  1200. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1201. if (cash == null)
  1202. {
  1203. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1204. cash = new CeErpReturnCash();
  1205. cash.tid = entity.tid;
  1206. cash.seller_nick = main.seller_nick;
  1207. cash.payment = trade.payment;
  1208. cash.buyer_nick = main.buyer_nick;
  1209. cash.cashstate = 0;
  1210. cash.rtype = "推购返现";
  1211. cash.returnprice = 5;
  1212. cash.created = DateTime.Now;
  1213. cash.con = "订单标记推购单";
  1214. cash.img = "";
  1215. cash.applyuserid = CurrentUser.UserID;
  1216. cash.Create();
  1217. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1218. }
  1219. else
  1220. {
  1221. cash.cashstate = 0;
  1222. cash.Update();
  1223. }
  1224. CeErpSukuraData.createInfo(entity.ctid, 9);
  1225. }
  1226. else if (tag == 3)
  1227. {
  1228. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1229. if (pers == null)
  1230. {
  1231. pers = new CeErpPersuade();
  1232. pers.ctid = entity.ctid;
  1233. pers.pstate = 0;
  1234. pers.created = DateTime.Now;
  1235. pers.applyuserid = CurrentUser.UserID;
  1236. pers.Create();
  1237. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1238. }
  1239. else
  1240. {
  1241. pers.pstate = 0;
  1242. pers.Update();
  1243. }
  1244. }
  1245. else if (tag == 4 || tag == 5)
  1246. {
  1247. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1248. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1249. if (pers == null)
  1250. {
  1251. pers = CeErpStayGoods.GetByTid(entity.tid);
  1252. }
  1253. if (pers == null)
  1254. {
  1255. pers = new CeErpStayGoods();
  1256. pers.t_id = entity.tid;
  1257. pers.ctid = entity.ctid;
  1258. pers.status = "待审核";
  1259. pers.audit_type = 0;
  1260. if (tag == 4)
  1261. {
  1262. pers.stay_type = "微信推购";
  1263. }
  1264. else
  1265. {
  1266. pers.stay_type = "旺旺推购";
  1267. }
  1268. if (entity.IsXianHuo == 0)
  1269. {
  1270. pers.product_id = entity.ProductId;
  1271. }
  1272. pers.wangwang = main.buyer_nick;
  1273. pers.shop_name = main.seller_nick;
  1274. pers.creata_time = DateTime.Now;
  1275. pers.create_u_id = CurrentUser.UserID;
  1276. pers.create_u_name = CurrentUser.UserName;
  1277. pers.Create();
  1278. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1279. }
  1280. else
  1281. {
  1282. pers.ctid = entity.ctid;
  1283. pers.audit_type = 0;
  1284. pers.Update();
  1285. }
  1286. CeErpSukuraData.createInfo(entity.ctid, 10);
  1287. }
  1288. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1289. returnSuccessMsg("标记成功!");
  1290. return;
  1291. }
  1292. returnErrorMsg("找不到记录");
  1293. }
  1294. }
  1295. public void upd_erp_ordertag_cancel()
  1296. {
  1297. if (UrlPostParmsCheck("ctid"))
  1298. {
  1299. string eid = GetPostString("ctid");
  1300. CeErpTradeCell entity = null;
  1301. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1302. if (entity != null)
  1303. {
  1304. entity.wechatTag = 0;
  1305. entity.Update();
  1306. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1307. if (pers != null)
  1308. {
  1309. pers.status = "取消推购";
  1310. pers.audit_type = 3;
  1311. pers.Update();
  1312. }
  1313. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1314. returnSuccessMsg("标记成功!");
  1315. return;
  1316. }
  1317. returnErrorMsg("找不到记录");
  1318. }
  1319. }
  1320. public void upd_erp_addweichattag()
  1321. {
  1322. if (UrlPostParmsCheck("ctid"))
  1323. {
  1324. ;
  1325. string eid = GetPostString("ctid");
  1326. CeErpTradeCell entity = null;
  1327. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1328. if (entity != null)
  1329. {
  1330. if (entity.IsAddWechat > 0)
  1331. {
  1332. returnErrorMsg("此单已经标记过了");
  1333. return;
  1334. }
  1335. 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);
  1336. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1337. if (dt.Rows.Count > 0)
  1338. {
  1339. entity.IsAddWechat = 2;
  1340. }
  1341. else
  1342. {
  1343. entity.IsAddWechat = 1;
  1344. }
  1345. entity.Update();
  1346. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1347. returnSuccessMsg("标记成功!");
  1348. return;
  1349. }
  1350. returnErrorMsg("找不到记录");
  1351. }
  1352. }
  1353. public void upd_erp_getmyorder()
  1354. {
  1355. if (UrlPostParmsCheck("ctid"))
  1356. {
  1357. string eid = GetPostString("ctid");
  1358. CeErpTradeCell entity = null;
  1359. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1360. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1361. if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1362. {
  1363. returnErrorMsg("台湾客户需填写身份证号!");
  1364. return;
  1365. }
  1366. if (commonHelper.isFarAddress(father.receiver_state) && father.delivery_paymant == 0)
  1367. {
  1368. returnErrorMsg("偏远地区需要填写物流费!");
  1369. return;
  1370. }
  1371. if (entity != null)
  1372. {
  1373. if (entity.ctid.IndexOf("C") != -1)
  1374. {
  1375. StringBuilder sql = new StringBuilder();
  1376. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1377. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1378. if (dt.Rows.Count > 0)
  1379. {
  1380. decimal total = 0;
  1381. foreach (DataRow dr in dt.Rows)
  1382. {
  1383. total += Convert.ToDecimal(dr["payment"]);
  1384. }
  1385. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1386. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1387. {
  1388. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1389. return;
  1390. }
  1391. }
  1392. }
  1393. if (entity.OrderState == -1)
  1394. {
  1395. returnErrorMsg("待审核订单无法领取!");
  1396. return;
  1397. }
  1398. entity.CustomerUserId = CurrentUser.UserID;
  1399. if (entity.OrderState < 2)
  1400. {
  1401. entity.OrderState = 2;
  1402. if (entity.ShopId != 0)
  1403. {
  1404. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1405. }
  1406. }
  1407. entity.UpdateTime = DateTime.Now;
  1408. entity.Update();
  1409. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1410. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1411. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1412. {
  1413. dataHelper.api_orderBack(entity.ctid, "0", "");
  1414. }
  1415. returnSuccessMsg("领单成功!");
  1416. return;
  1417. }
  1418. returnErrorMsg("找不到记录");
  1419. }
  1420. }
  1421. public void getmyorder_from_init()
  1422. {
  1423. if (UrlPostParmsCheck("ctid"))
  1424. {
  1425. string eid = GetPostString("ctid");
  1426. CeErpTradeCell entity = null;
  1427. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1428. if (entity != null)
  1429. {
  1430. string sellerMemo = GetPostString("sellerMemo");
  1431. if (sellerMemo.Length > 0)
  1432. {
  1433. entity.seller_memo = sellerMemo;
  1434. }
  1435. string oterhMemo = GetPostString("otherMemo");
  1436. if (oterhMemo.Length > 0)
  1437. {
  1438. entity.OtherMemo = oterhMemo;
  1439. }
  1440. int urg = GetPostInt("urgency");
  1441. entity.IsUrgency = (urg == 1 ? true : false);
  1442. int wechat = GetPostInt("wechat");
  1443. int command = GetPostInt("command");
  1444. if (wechat == 1)
  1445. {
  1446. entity.wechatTag = 1;
  1447. }
  1448. if (command == 1)
  1449. {
  1450. entity.wechatTag = 2;
  1451. }
  1452. string pPro = GetPostString("pprofession");
  1453. if (pPro.Length > 0)
  1454. {
  1455. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1456. string spro = GetPostString("profession");
  1457. if (spro.Length > 0)
  1458. {
  1459. entity.ProfessionId = Convert.ToInt32(spro);
  1460. }
  1461. }
  1462. string proId = GetPostString("productId");
  1463. if (proId.Length > 0)
  1464. {
  1465. entity.ProductId = Convert.ToInt32(proId);
  1466. }
  1467. entity.Material = GetPostString("material");
  1468. entity.Craft = GetPostString("craft");
  1469. entity.CustomerUserId = CurrentUser.UserID;
  1470. if (entity.OrderState < 2)
  1471. {
  1472. entity.OrderState = 2;
  1473. if (entity.ShopId != 0)
  1474. {
  1475. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1476. }
  1477. }
  1478. entity.Update();
  1479. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1480. returnSuccessMsg("领单成功!");
  1481. return;
  1482. }
  1483. returnErrorMsg("找不到记录");
  1484. }
  1485. }
  1486. public void upd_erp_setrelationorder()
  1487. {
  1488. if (UrlPostParmsCheck("ctid"))
  1489. {
  1490. ;
  1491. string eid = GetPostString("ctid");
  1492. string ftid = GetPostString("ftid");
  1493. CeErpTradeCell entity = null;
  1494. CeErpTradeCell fentity = null;
  1495. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1496. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1497. if (fentity == null)
  1498. {
  1499. returnErrorMsg("找不到关联的主订单");
  1500. return;
  1501. }
  1502. if (entity != null)
  1503. {
  1504. if (entity.OrderState >= 5)
  1505. {
  1506. returnErrorMsg("本单已经设计完成无法关联");
  1507. return;
  1508. }
  1509. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1510. {
  1511. returnErrorMsg("线下单续审核后才能关联!");
  1512. return;
  1513. }
  1514. entity.ptid = ftid;
  1515. entity.OrderState = fentity.OrderState;
  1516. //entity.status = fentity.status;
  1517. entity.CustomerUserId = fentity.CustomerUserId;
  1518. entity.DesignUserId = fentity.DesignUserId;
  1519. entity.seller_memo = "补差价单:" + ftid;
  1520. entity.IsSample = 2;
  1521. entity.Update();
  1522. ApiVo apiVo = new ApiVo();
  1523. apiVo.orderNumber = ftid;
  1524. apiVo.payment = entity.payment;
  1525. apiVo.actionName = "repairDesign";
  1526. designHelper.API_WorkCore(apiVo);//repairDesign
  1527. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1528. returnSuccessMsg("关联成功!");
  1529. return;
  1530. }
  1531. else
  1532. returnErrorMsg("找不到记录");
  1533. }
  1534. }
  1535. public void download_erp_neworder()
  1536. {
  1537. string seller = GetPostString("seller_nick");
  1538. string tid = GetPostString("tid");
  1539. if (seller.Length <= 0 || tid.Length <= 0)
  1540. {
  1541. returnErrorMsg("数据错误");
  1542. }
  1543. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1544. //{
  1545. // returnErrorMsg("找不到店铺Sessionkey");
  1546. //}
  1547. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1548. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1549. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1550. if (res.IndexOf("refOid") == -1)
  1551. {
  1552. returnErrorMsg("下载订单数据失败");
  1553. return;
  1554. }
  1555. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1556. returnSuccessMsg("下载完成");
  1557. //tmcHelper.createNewOrder(res);
  1558. //CeErpTrade entr = null;
  1559. //entr = CeErpTrade.Get(tid);
  1560. //if (entr != null)
  1561. //{
  1562. // returnSuccess("下载成功");
  1563. // //下载成功之后,Cell表生成对应的订单;
  1564. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1565. //}
  1566. //else
  1567. //{
  1568. // returnErrorMsg("下载失败或者创建订单失败");
  1569. //}
  1570. }
  1571. public void set_erp_atersale()
  1572. {
  1573. if (UrlPostParmsCheck("ctid"))
  1574. {
  1575. string eid = GetPostString("ctid");
  1576. string reason = GetPostString("AfterSaleReason");
  1577. CeErpTradeCell entity = null;
  1578. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1579. if (entity != null)
  1580. {
  1581. /*if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1582. {
  1583. returnErrorMsg("此订单已经在售后");
  1584. return;
  1585. }*/
  1586. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1587. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1588. entity.AfterSaleTime = DateTime.Now;
  1589. entity.HandleTime = null;
  1590. entity.Update();
  1591. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1592. returnSuccessMsg("转售后成功!");
  1593. return;
  1594. }
  1595. returnErrorMsg("找不到记录");
  1596. }
  1597. }
  1598. public void set_erp_withdraw()
  1599. {
  1600. if (UrlPostParmsCheck("ctid"))
  1601. {
  1602. try
  1603. {
  1604. string eid = GetPostString("ctid");//商品id
  1605. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1606. CeWithdraw ceWithdrawSelect = null;
  1607. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1608. if (ceWithdrawSelect != null)
  1609. {
  1610. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1611. {
  1612. ceWithdrawSelect.status = -1;
  1613. ceWithdrawSelect.Update();
  1614. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1615. returnSuccessMsg("重新发起审核成功");
  1616. return;
  1617. }
  1618. else
  1619. {
  1620. returnSuccessMsg("请勿重复申请!");
  1621. return;
  1622. }
  1623. }
  1624. else
  1625. {
  1626. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1627. if (string.IsNullOrEmpty(CustomerUserId))
  1628. {
  1629. CustomerUserId = "-1";
  1630. }
  1631. int Userid = CurrentUser.UserID;//用户id
  1632. CeWithdraw ceWithdraw = new CeWithdraw();
  1633. ceWithdraw.tid = eid;
  1634. ceWithdraw.userid = Userid;
  1635. ceWithdraw.providerid = CustomerUserId;
  1636. ceWithdraw.status = 3;
  1637. ceWithdraw.creationtime = DateTime.Now;
  1638. ceWithdraw.Create();
  1639. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1640. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1641. return;
  1642. }
  1643. }
  1644. catch
  1645. {
  1646. returnErrorMsg("申请撤回订单失败");
  1647. return;
  1648. }
  1649. }
  1650. }
  1651. public void ins_erp_billinfo()
  1652. {
  1653. if (UrlPostParmsCheck("ctid"))
  1654. {
  1655. string eid = GetPostString("ctid");
  1656. CeErpTradeCell entity = null;
  1657. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1658. if (entity != null)
  1659. {
  1660. CeErpBill bill = CeErpBill.GetByTid(eid);
  1661. bool isHave = false;
  1662. if (bill != null)
  1663. {
  1664. isHave = true;
  1665. if (bill.state != 4)
  1666. {
  1667. returnErrorMsg("此单已经申请过发票了");
  1668. return;
  1669. }
  1670. }
  1671. if (entity.IsNeedBill == 0)
  1672. {
  1673. entity.IsNeedBill = 1;
  1674. }
  1675. entity.Update();
  1676. string errjson = "";
  1677. try
  1678. {
  1679. CeErpBill bill_entity = new CeErpBill();
  1680. bill_entity.tid = entity.tid;
  1681. bill_entity.title = GetPostString("title");
  1682. string taxstr = GetPostString("tax");
  1683. taxstr = taxstr.Replace(" ", "");
  1684. bill_entity.tax = taxstr;
  1685. bill_entity.bank = GetPostString("bank");
  1686. string bankacstr = GetPostString("bankac");
  1687. bankacstr = bankacstr.Replace(" ", "");
  1688. bill_entity.bankac = bankacstr;
  1689. bill_entity.address = GetPostString("address");
  1690. bill_entity.phone = GetPostString("phone");
  1691. bill_entity.price = GetPostString("price");
  1692. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1693. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1694. {
  1695. billCount += 1;
  1696. }
  1697. string prebill = "ltb";
  1698. for (int idx = 1; idx <= billCount; idx++)
  1699. {
  1700. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1701. string billoid = prebill + idx + dtstr;
  1702. bill_entity.billOrderId += billoid;
  1703. if (idx < billCount)
  1704. {
  1705. bill_entity.billOrderId += ",";
  1706. }
  1707. }
  1708. bill_entity.productId = GetPostInt("ProductName");
  1709. bill_entity.num = GetPostInt("num");
  1710. bill_entity.unit = GetPostString("unit");
  1711. bill_entity.type = GetPostString("type");
  1712. bill_entity.sendType = GetPostString("SendType");
  1713. bill_entity.email = GetPostString("email");
  1714. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1715. bill_entity.shopName = GetPostString("ShopName");
  1716. bill_entity.applymemo = GetPostString("applyMemo");
  1717. bill_entity.createTime = DateTime.Now;
  1718. bill_entity.state = 0;
  1719. bill_entity.userId = CurrentUser.UserID;
  1720. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1721. bill_entity.Create();
  1722. }
  1723. catch (Exception ex)
  1724. {
  1725. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1726. returnErrorMsg("创建发票出错!");
  1727. return;
  1728. }
  1729. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1730. returnSuccessMsg("发票申请成功!");
  1731. return;
  1732. }
  1733. returnErrorMsg("找不到记录");
  1734. }
  1735. }
  1736. public void ins_erp_neworder()
  1737. {
  1738. if (UrlPostParmsCheck("receiver_name"))
  1739. {
  1740. CeErpTrade entity = new CeErpTrade();
  1741. string plat_form = GetPostString("platform");
  1742. string preStr = "N_";
  1743. if (plat_form == "拼多多")
  1744. {
  1745. preStr = "P_";
  1746. }
  1747. else if (plat_form == "阿里巴巴")
  1748. {
  1749. preStr = "A_";
  1750. }
  1751. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1752. entity.seller_nick = GetPostString("seller_nick");
  1753. entity.buyer_nick = GetPostString("buyer_nick");
  1754. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1755. entity.total_fee = entity.payment;
  1756. entity.pay_time = DateTime.Now;
  1757. entity.status = "NOT_SHIPPED";
  1758. entity.receiver_name = GetPostString("receiver_name");
  1759. entity.receiver_mobile = GetPostString("receiver_mobile");
  1760. entity.receiver_state = GetPostString("receiver_state");
  1761. entity.receiver_city = GetPostString("receiver_city");
  1762. entity.receiver_district = GetPostString("receiver_district");
  1763. entity.receiver_address = GetPostString("receiver_address");
  1764. if (entity.receiver_state == "" || entity.receiver_city == "")
  1765. {
  1766. returnErrorMsg("收件地址不能为空");
  1767. return;
  1768. }
  1769. int shopId = 0;
  1770. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1771. if (nShop != null)
  1772. {
  1773. shopId = nShop.ID;
  1774. }
  1775. if (shopId != 34 && entity.payment == 0)
  1776. {
  1777. returnErrorMsg("公司自用的单金额才能为0");
  1778. return;
  1779. }
  1780. entity.Create();
  1781. CeErpTradeCell entitycell = new CeErpTradeCell();
  1782. entitycell.ctid = entity.tid;
  1783. entitycell.tid = entity.tid;
  1784. entitycell.ShopId = shopId;
  1785. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1786. entitycell.OrderState = 0;
  1787. entitycell.pay_time = entity.pay_time;
  1788. entitycell.IsOffLineOrder = 1;
  1789. entitycell.Create();
  1790. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1791. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1792. return;
  1793. }
  1794. }
  1795. public void ins_erp_neworder2()
  1796. {
  1797. if (UrlPostParmsCheck("receiver_name"))
  1798. {
  1799. //string plat_form = GetPostString("platform");
  1800. string preStr = "X_";
  1801. string memo = GetPostString("memo");
  1802. string productId = GetPostString("productId");
  1803. string primg = GetPostString("proofimg");
  1804. string sellerNick = GetPostString("seller_nick");
  1805. string addFrom = GetPostString("addfrom");
  1806. if (addFrom == "1")
  1807. {
  1808. preStr = "N_";
  1809. }
  1810. int shopId = 0;
  1811. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1812. if (nShop != null)
  1813. {
  1814. shopId = nShop.ID;
  1815. }
  1816. else
  1817. {
  1818. returnErrorMsg("找不到对应店铺");
  1819. return;
  1820. }
  1821. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1822. {
  1823. returnErrorMsg("必须上传付款凭证");
  1824. return;
  1825. }
  1826. CeErpTrade entity = new CeErpTrade();
  1827. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1828. entity.seller_nick = sellerNick;
  1829. entity.buyer_nick = GetPostString("buyer_nick");
  1830. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1831. entity.total_fee = entity.payment;
  1832. entity.pay_time = DateTime.Now;
  1833. entity.status = "NOT_SHIPPED";
  1834. entity.receiver_name = GetPostString("receiver_name");
  1835. entity.receiver_mobile = GetPostString("receiver_mobile");
  1836. entity.receiver_state = GetPostString("receiver_state");
  1837. entity.receiver_city = GetPostString("receiver_city");
  1838. entity.receiver_district = GetPostString("receiver_district");
  1839. entity.receiver_address = GetPostString("receiver_address");
  1840. entity.seller_memo = memo;
  1841. entity.orderFrom = 20;
  1842. entity.orderType = 15;
  1843. if (entity.receiver_state == "" || entity.receiver_city == "")
  1844. {
  1845. returnErrorMsg("收件地址不能为空");
  1846. return;
  1847. }
  1848. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1849. {
  1850. returnErrorMsg("公司自用的单金额才能为0");
  1851. return;
  1852. }
  1853. entity.Create();
  1854. string toWhere = GetPostString("towhere");
  1855. string oldOrder = GetPostString("oldOrder");
  1856. CeErpTradeCell entitycell = new CeErpTradeCell();
  1857. entitycell.ctid = entity.tid;
  1858. //唯一标识
  1859. entitycell.OrderSn = entity.tid;
  1860. string orderSn = dataHelper.getSaleOrderSn();
  1861. if (orderSn != "")
  1862. {
  1863. entitycell.OrderSn = orderSn;
  1864. }
  1865. entitycell.tid = entity.tid;
  1866. //if (preStr == "X_")
  1867. //{
  1868. entitycell.IsOffLineOrder = 1;
  1869. if ("1".Equals(oldOrder))
  1870. {
  1871. entitycell.IsOldCustomer = 1;
  1872. }
  1873. //}
  1874. entitycell.CustomerUserId = CurrentUser.UserID;
  1875. entitycell.PayProofImg = primg;
  1876. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1877. entitycell.ProductId = Convert.ToInt32(productId);
  1878. entitycell.ShopId = shopId;
  1879. entitycell.UpdateTime = DateTime.Now;
  1880. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1881. if (entitycell.ProductId > 0)
  1882. {
  1883. CeErpProduct ceErpProduct = CeErpProduct.GetById(entitycell.ProductId);
  1884. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  1885. {
  1886. entitycell.NewProduct = 1;
  1887. }
  1888. }
  1889. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1890. {
  1891. entitycell.IsXianHuo = 1;
  1892. }
  1893. entitycell.pay_time = entity.pay_time;
  1894. if (toWhere == "1")
  1895. {
  1896. entitycell.OrderState = 2;
  1897. }
  1898. else
  1899. {
  1900. entitycell.OrderState = 6;
  1901. entitycell.FinishPlaceTime = entitycell.pay_time;
  1902. }
  1903. if (shopId == 94)
  1904. {
  1905. entitycell.OrderState = 4;
  1906. entitycell.WaitDesignTime = entitycell.pay_time;
  1907. entitycell.StartDesignTime = entitycell.pay_time;
  1908. entitycell.DesignUserId = 218;
  1909. }
  1910. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1911. {
  1912. entitycell.OrderState = -1;//修改12-5
  1913. CeWithdraw ceWithdraw = new CeWithdraw();
  1914. ceWithdraw.tid = entity.tid;
  1915. ceWithdraw.providerid = "-1";
  1916. ceWithdraw.status = -1;
  1917. ceWithdraw.creationtime = DateTime.Now;
  1918. ceWithdraw.userid = 4634;
  1919. ceWithdraw.Create();
  1920. }
  1921. entitycell.Create();
  1922. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1923. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1924. {
  1925. addPlaceRegist(entitycell, CurrentUser.UserID);
  1926. }
  1927. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1928. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1929. return;
  1930. }
  1931. }
  1932. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1933. {
  1934. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1935. entity.PlactTime = tradecell.pay_time;
  1936. entity.AddUserId = userid;
  1937. entity.FileName = tradecell.seller_memo;
  1938. entity.Supplier = 24;
  1939. entity.CreateTime = DateTime.Now;
  1940. entity.Did = tradecell.ctid;
  1941. entity.tid = tradecell.tid;
  1942. entity.splitTag = tradecell.SplitTag;
  1943. entity.CurState = "未完成";
  1944. entity.Create();
  1945. }
  1946. public void get_erp_offlinelist()
  1947. {
  1948. DataStruct dStruct = GetPostStruct();
  1949. List<string> lw = new List<string>();
  1950. string tid = GetPostString("ctid");
  1951. string date1 = GetPostString("date1");
  1952. string date2 = GetPostString("date2");
  1953. if (tid.Length > 0 || date1.Length > 0)
  1954. {
  1955. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1956. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1957. if (dw.Length > 0) lw.Add(dw);
  1958. }
  1959. else
  1960. {
  1961. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1962. }
  1963. string shopname = GetPostString("shopname");
  1964. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1965. string buyernick = GetPostString("buyer_nick");
  1966. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1967. string customer = GetPostString("customer");
  1968. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1969. string design = GetPostString("design");
  1970. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1971. string orderState = GetPostString("orderState");
  1972. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1973. string address = GetPostString("address");
  1974. 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));
  1975. string sellermemo = GetPostString("seller_memo");
  1976. if (sellermemo.Length > 0)
  1977. {
  1978. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1979. }
  1980. string price1 = GetPostString("price1");
  1981. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1982. string price2 = GetPostString("price2");
  1983. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1984. //if (PKey != "admin")
  1985. //{
  1986. // string usershop = CurrentUser.User.pemShop;
  1987. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1988. //}
  1989. //if (ex_psize > 0)
  1990. //{
  1991. dStruct.Order = "pay_time desc";
  1992. //}
  1993. //else
  1994. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1995. lw.Add(string.Format("IsOffLineOrder=1"));
  1996. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1997. DataTable dt = null;
  1998. dt = WebCache.GetData("view_erptradecell", dStruct);
  1999. writeGridDataTableJson(dStruct.TotalCount, dt);
  2000. }
  2001. public void get_erp_returncashrecord()
  2002. {
  2003. DataStruct dStruct = GetPostStruct();
  2004. List<string> lw = new List<string>();
  2005. string tid = GetPostString("ctid");
  2006. if (tid.Length > 0)
  2007. {
  2008. lw.Add(string.Format("tid like '%{0}%'", tid));
  2009. dStruct.Order = "id desc";
  2010. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2011. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  2012. //writeGridDataTableJson(dStruct.TotalCount, dt);
  2013. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2014. return;
  2015. }
  2016. returnErrorMsg("id数据错误!");
  2017. }
  2018. public void ins_erp_returncashrecord()
  2019. {
  2020. if (UrlPostParmsCheck("tid"))
  2021. {
  2022. string tid = GetPostString("tid");
  2023. string retype = GetPostString("type");
  2024. StringBuilder sql = new StringBuilder();
  2025. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  2026. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2027. if (dt.Rows.Count > 0)
  2028. {
  2029. returnErrorMsg("相同返现类型记录已存在");
  2030. return;
  2031. }
  2032. CeErpReturnCash entity = new CeErpReturnCash();
  2033. entity.tid = tid;
  2034. entity.seller_nick = GetPostString("seller_nick");
  2035. string pment = GetPostString("payment");
  2036. if (pment.Length > 0)
  2037. {
  2038. entity.payment = Convert.ToDouble(pment);
  2039. }
  2040. entity.buyer_nick = GetPostString("buyer_nick");
  2041. entity.cashstate = 0;
  2042. entity.rtype = retype;
  2043. string rPrice = GetPostString("returnprice");
  2044. if (rPrice.Length > 0)
  2045. {
  2046. entity.returnprice = Convert.ToDouble(rPrice);
  2047. }
  2048. entity.created = DateTime.Now;
  2049. entity.con = GetPostString("con");
  2050. entity.img = GetPostString("img");
  2051. entity.applyuserid = CurrentUser.UserID;
  2052. entity.Create();
  2053. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  2054. returnSuccessMsg("操作成功!");
  2055. return;
  2056. }
  2057. }
  2058. public void set_erp_predelivery()
  2059. {
  2060. if (UrlPostParmsCheck("ctid"))
  2061. {
  2062. string eid = GetPostString("ctid");
  2063. CeErpTradeCell entity = null;
  2064. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2065. if (entity != null)
  2066. {
  2067. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  2068. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  2069. //{
  2070. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  2071. // return;
  2072. //}
  2073. entity.IsPreDelivery = 1;
  2074. entity.Update();
  2075. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2076. returnSuccessMsg("预发货成功!");
  2077. return;
  2078. //string shop = GetPostString("seller_nick");
  2079. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  2080. //string comName = GetPostString("comName");
  2081. //string comCode = GetPostString("comCode");
  2082. //string outSid = GetPostString("outSid");//运单号
  2083. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  2084. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  2085. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  2086. //string apires = "";
  2087. //if (deliveryType == "虚拟发货")
  2088. //{
  2089. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  2090. //}
  2091. //else
  2092. //{
  2093. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  2094. //}
  2095. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  2096. ////{
  2097. //if (apires.IndexOf("发货成功") != -1)
  2098. //{
  2099. // if (deliveryType != "虚拟发货")
  2100. // {
  2101. // //还要插入快递信息到 快递信息表
  2102. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  2103. // exinfo.tid = eid;
  2104. // exinfo.out_sid = outSid;
  2105. // exinfo.company_code = comCode;
  2106. // exinfo.company_name = comName;
  2107. // exinfo.delivery_memo = deliveryMemo;
  2108. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  2109. // exinfo.deliveryType = deliveryType;
  2110. // exinfo.Create();
  2111. // }
  2112. // returnSuccessMsg("发货成功!");
  2113. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2114. //}
  2115. //else
  2116. //{
  2117. // returnErrorMsg("淘宝发货失败!!");
  2118. //}
  2119. //return;
  2120. }
  2121. returnErrorMsg("找不到订单记录");
  2122. }
  2123. }
  2124. public void get_erp_unusuallist()
  2125. {
  2126. DataStruct dStruct = GetPostStruct();
  2127. List<string> lw = new List<string>();
  2128. string tid = GetPostString("ctid");
  2129. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2130. string shopname = GetPostString("shopname");
  2131. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2132. string buyernick = GetPostString("buyer_nick");
  2133. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2134. string ResponsibleMan = GetPostString("responsible");
  2135. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2136. string date1 = GetPostString("date1");
  2137. string date2 = GetPostString("date2");
  2138. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2139. if (dw.Length > 0) lw.Add(dw);
  2140. string price1 = GetPostString("price1");
  2141. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2142. string price2 = GetPostString("price2");
  2143. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2144. string orderState = GetPostString("orderState");
  2145. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2146. string sellermemo = GetPostString("seller_memo");
  2147. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2148. lw.Add(string.Format("UnusualTag > 0"));
  2149. lw.Add(string.Format("IsRefund<={0}", 1));
  2150. dStruct.Order = "pay_time desc";
  2151. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2152. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2153. writeGridDataTableJson(dStruct.TotalCount, dt);
  2154. }
  2155. public void set_erp_unusualtonomal()
  2156. {
  2157. if (UrlPostParmsCheck("ctid"))
  2158. {
  2159. string eid = GetPostString("ctid");
  2160. CeErpTradeCell entity = null;
  2161. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2162. if (entity != null)
  2163. {
  2164. entity.UnusualTag = -1;
  2165. entity.Update();
  2166. returnSuccessMsg("忽略成功!");
  2167. return;
  2168. }
  2169. returnErrorMsg("找不到记录");
  2170. }
  2171. }
  2172. public void ins_erp_unusualreason()
  2173. {
  2174. if (UrlPostParmsCheck("ctid"))
  2175. {
  2176. string eid = GetPostString("ctid");
  2177. CeErpTradeCell entity = null;
  2178. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2179. if (entity != null)
  2180. {
  2181. entity.MemoOpt = 4;
  2182. entity.UnusualCon = GetPostString("con");
  2183. entity.Update();
  2184. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2185. if (trade != null)
  2186. {
  2187. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2188. }
  2189. //查货是否超时
  2190. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2191. if (ceErpTradeCellExtend == null)
  2192. {
  2193. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2194. ceErpTradeCellExtend.ctid = entity.ctid;
  2195. }
  2196. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2197. {
  2198. ceErpTradeCellExtend.CheckOut += 1;
  2199. }
  2200. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2201. if (ceErpTradeCellExtend.ID > 0)
  2202. {
  2203. ceErpTradeCellExtend.Update();
  2204. }
  2205. else
  2206. {
  2207. ceErpTradeCellExtend.Create();
  2208. }
  2209. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2210. returnSuccessMsg("操作成功!");
  2211. return;
  2212. }
  2213. returnErrorMsg("找不到记录");
  2214. }
  2215. }
  2216. public void upd_erp_sampleorder()
  2217. {
  2218. if (UrlPostParmsCheck("ctid"))
  2219. {
  2220. string eid = GetPostString("ctid");
  2221. string[] eArr = eid.Split(',');
  2222. if (eArr.Length > 1)
  2223. {
  2224. List<string> eLst = new List<string>();
  2225. for (int i = 0; i < eArr.Length; i++)
  2226. {
  2227. eLst.Add("'" + eArr[i] + "'");
  2228. }
  2229. eid = string.Join(",", eLst.ToArray());
  2230. }
  2231. else
  2232. {
  2233. eid = "'" + eid + "'";
  2234. }
  2235. StringBuilder sql = new StringBuilder();
  2236. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2237. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2238. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2239. if (dt.Rows.Count > 0)
  2240. {
  2241. string errmsg = "";
  2242. foreach (DataRow dr in dt.Rows)
  2243. {
  2244. StringBuilder sqlsb = new StringBuilder();
  2245. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2246. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2247. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2248. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2249. //string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2250. /*if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2251. {
  2252. continue;
  2253. }
  2254. else
  2255. {
  2256. string emsg = commonHelper.KeepChinese(apires);
  2257. errmsg += emsg;
  2258. }*/
  2259. }
  2260. if (errmsg.Length > 0)
  2261. {
  2262. returnErrorMsg(errmsg);
  2263. return;
  2264. }
  2265. returnSuccessMsg("操作成功");
  2266. return;
  2267. }
  2268. returnErrorMsg("找不到记录");
  2269. }
  2270. }
  2271. public void upd_erp_transcustomer()
  2272. {
  2273. if (UrlPostParmsCheck("ctid"))
  2274. {
  2275. string eid = GetPostString("ctid");
  2276. int userid = GetPostInt("CustomerUserId");
  2277. CeErpTradeCell entity = null;
  2278. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2279. if (entity != null)
  2280. {
  2281. //string[] mlist = entity.seller_memo.Split('-');
  2282. //string sql = "select * from view_erpuser where id=" + userid;
  2283. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2284. //if (dt != null && dt.Rows.Count > 0)
  2285. //{
  2286. // string nmemo = "";
  2287. // for(int i = 0; i < mlist.Length - 1; i++)
  2288. // {
  2289. // nmemo += mlist[i];
  2290. // nmemo += "-";
  2291. // }
  2292. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2293. // entity.seller_memo = nmemo;
  2294. //}
  2295. entity.CustomerUserId = userid;
  2296. entity.Update();
  2297. returnSuccessMsg("操作成功!");
  2298. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2299. return;
  2300. }
  2301. returnErrorMsg("找不到记录");
  2302. }
  2303. }
  2304. public void upd_erp_transdesigner()
  2305. {
  2306. if (UrlPostParmsCheck("ctid"))
  2307. {
  2308. string eids = GetPostString("ctid");
  2309. string[] ctidList = eids.Split(',');
  2310. int userid = GetPostInt("DesignUserId");
  2311. foreach (string ctid in ctidList)
  2312. {
  2313. CeErpTradeCell entity = null;
  2314. CeErpDesignerBill entitys = null;
  2315. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2316. entitys = CeErpDesignerBill.GetByTid(ctid);
  2317. if (entity != null)
  2318. {
  2319. if (entity.OrderState > 4)
  2320. {
  2321. continue;
  2322. }
  2323. //存在退款不能流转
  2324. if (entity.IsRefund > 0)
  2325. {
  2326. continue;
  2327. }
  2328. entity.DesignUserId = userid;
  2329. entity.WaitDesignTime = DateTime.Now;
  2330. entity.Update();
  2331. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2332. }
  2333. }
  2334. returnSuccessMsg("操作成功!");
  2335. }
  2336. }
  2337. public void upd_erp_distributedesigner()
  2338. {
  2339. if (UrlPostParmsCheck("ctid"))
  2340. {
  2341. string eid = GetPostString("ctid");
  2342. int userid = GetPostInt("DesignUserId");
  2343. string[] idlist = eid.Split(',');
  2344. if (idlist.Length <= 0)
  2345. {
  2346. returnErrorMsg("订单不能为空");
  2347. return;
  2348. }
  2349. foreach (string ctid in idlist)
  2350. {
  2351. CeErpTradeCell entity = null;
  2352. CeErpDesignerBill entitys = null;
  2353. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2354. else continue;
  2355. if (entity != null)
  2356. {
  2357. if (userid == 2125 || userid == 3542)
  2358. { }
  2359. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2360. {
  2361. returnErrorMsg("金额错误的订单无法指派");
  2362. return;
  2363. }
  2364. if (entity.OrderState >= 5)
  2365. {
  2366. returnErrorMsg("已经设计完成无法指派");
  2367. return;
  2368. }
  2369. if (entity.OrderState == -1)
  2370. {
  2371. returnErrorMsg("审核中的订单无法指派");
  2372. return;
  2373. }
  2374. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2375. {
  2376. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2377. return;
  2378. }
  2379. //157赖橙帆 159林晨 73 静之颖
  2380. 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)
  2381. {
  2382. returnErrorMsg("指派设计共创无法再次指派!");
  2383. return;
  2384. }
  2385. entity.OrderState = 3;
  2386. if (entity.SupplierId == 0)
  2387. {
  2388. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2389. entity.SupplierId = suid;
  2390. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2391. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2392. }
  2393. if (userid == 2125 && entity.seller_memo != "")
  2394. {
  2395. apiDesign.API_GetPrintData_CreateOrder(entity);
  2396. }
  2397. if (userid == 3542 && entity.seller_memo != "")
  2398. {
  2399. string userPost = CurrentUser.UserPost.Post.Code;
  2400. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2401. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2402. if (response.msg != "设计共创:成功")
  2403. {
  2404. returnErrorMsg(response.msg);
  2405. return;
  2406. }
  2407. entity.DispatchSort = 2;
  2408. }
  2409. else
  2410. {
  2411. if (entity.DispatchSort == 2)
  2412. {
  2413. ApiVo apiVo = new ApiVo();
  2414. apiVo.actionName = "closeDesign";
  2415. apiVo.orderNumber = entity.ctid;
  2416. designHelper.API_WorkCore(apiVo);//closeDesign
  2417. }
  2418. entity.DispatchSort = 0;
  2419. }
  2420. entity.DesignUserId = userid;
  2421. entity.WaitDesignTime = DateTime.Now;
  2422. entity.UpdateTime = DateTime.Now;
  2423. entity.Update();
  2424. string name = commonHelper.getUserNameById(userid);
  2425. commonHelper.UpdateRelationOrder(entity.ctid);
  2426. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2427. }
  2428. }
  2429. returnSuccessMsg("操作成功!");
  2430. return;
  2431. }
  2432. }
  2433. public string getTidByCtid(string ctid)
  2434. {
  2435. string tid = "";
  2436. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2437. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2438. if (dataTable != null && dataTable.Rows.Count > 0)
  2439. {
  2440. tid = dataTable.Rows[0]["tid"].ToString();
  2441. }
  2442. return tid;
  2443. }
  2444. public List<string> getTidByCtidMore(string ctid)
  2445. {
  2446. 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);
  2447. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2448. List<string> list = new List<string>();
  2449. if (dataTable != null && dataTable.Rows.Count > 0)
  2450. {
  2451. foreach (DataRow item in dataTable.Rows)
  2452. {
  2453. list.Add("'" + item["tid"].ToString() + "'");
  2454. }
  2455. }
  2456. return list;
  2457. }
  2458. public List<string> getTidByCtidLike(string ctid)
  2459. {
  2460. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2461. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2462. List<string> list = new List<string>();
  2463. if (dataTable != null && dataTable.Rows.Count > 0)
  2464. {
  2465. foreach (DataRow item in dataTable.Rows)
  2466. {
  2467. list.Add("'" + item["tid"].ToString() + "'");
  2468. }
  2469. }
  2470. return list;
  2471. }
  2472. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2473. {
  2474. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2475. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2476. List<string> list = new List<string>();
  2477. if (dataTable != null && dataTable.Rows.Count > 0)
  2478. {
  2479. foreach (DataRow item in dataTable.Rows)
  2480. {
  2481. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2482. {
  2483. continue;
  2484. }
  2485. list.Add("'" + item["receiverId"].ToString() + "'");
  2486. }
  2487. }
  2488. return list;
  2489. }
  2490. public void get_erp_myorderlist()
  2491. {
  2492. DataStruct dStruct = GetPostStruct();
  2493. List<string> lw = new List<string>();
  2494. string tid = GetPostString("ctid");
  2495. if (tid.Length > 0)
  2496. {
  2497. string select_tid = getTidByCtid(tid);
  2498. lw.Add(string.Format("tid='{0}'", select_tid));
  2499. }
  2500. else
  2501. {
  2502. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2503. }
  2504. //12-1 修改
  2505. string urgent = GetPostString("urgent");
  2506. string back = GetPostString("back");
  2507. string offlineSearch = GetPostString("offlineSearch");
  2508. if (!string.IsNullOrWhiteSpace(urgent))
  2509. {
  2510. if (urgent.Equals("true"))
  2511. {
  2512. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2513. }
  2514. }
  2515. if (!string.IsNullOrWhiteSpace(back))
  2516. {
  2517. if (back.Equals("true"))
  2518. {
  2519. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2520. }
  2521. }
  2522. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2523. {
  2524. if (offlineSearch.Equals("true"))
  2525. {
  2526. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2527. }
  2528. }
  2529. //end
  2530. string shopname = GetPostString("shopname");
  2531. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2532. string buyernick = GetPostString("buyer_nick");
  2533. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2534. string design = GetPostString("design");
  2535. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2536. string orderState = GetPostString("orderState");
  2537. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2538. string sellermemo = GetPostString("seller_memo");
  2539. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2540. string date1 = GetPostString("date1");
  2541. string date2 = GetPostString("date2");
  2542. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2543. if (dw.Length > 0) lw.Add(dw);
  2544. string price1 = GetPostString("price1");
  2545. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2546. string price2 = GetPostString("price2");
  2547. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2548. string urgency = GetPostString("urgency");
  2549. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2550. string after = GetPostString("after");
  2551. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2552. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2553. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2554. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2555. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2556. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2557. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2558. if (dt != null && dt.Rows.Count > 0)
  2559. {
  2560. foreach (DataRow dr in dt.Rows)
  2561. {
  2562. try
  2563. {
  2564. // 对象操作
  2565. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2566. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2567. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2568. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2569. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2570. if (dStruct.PageSize != 100000)
  2571. {
  2572. if (dr["DispatchSort"].ToString() == "2")
  2573. {
  2574. dr["gongchuang"] = 200;
  2575. }
  2576. else if ("外协".Equals(dr["ToType"].ToString()))
  2577. {
  2578. dr["gongchuang"] = 200;
  2579. }
  2580. else if ("内部".Equals(dr["ToType"].ToString()))
  2581. {
  2582. dr["gongchuang"] = -1;
  2583. }
  2584. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2585. {
  2586. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2587. dr["gongchuang"] = response.code;
  2588. }
  2589. }
  2590. }
  2591. catch (NullReferenceException ex)
  2592. {
  2593. }
  2594. }
  2595. }
  2596. writeGridDataTableJson(dStruct.TotalCount, dt);
  2597. }
  2598. public void get_erp_myreturnorderlist()
  2599. {
  2600. DataStruct dStruct = GetPostStruct();
  2601. List<string> lw = new List<string>();
  2602. string tid = GetPostString("ctid");
  2603. if (tid.Length > 0)
  2604. {
  2605. string select_tid = getTidByCtid(tid);
  2606. lw.Add(string.Format("tid='{0}'", select_tid));
  2607. }
  2608. else
  2609. {
  2610. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2611. }
  2612. string shopname = GetPostString("shopname");
  2613. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2614. string buyernick = GetPostString("buyer_nick");
  2615. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2616. string design = GetPostString("design");
  2617. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2618. string orderState = GetPostString("orderState");
  2619. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2620. string sellermemo = GetPostString("seller_memo");
  2621. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2622. string date1 = GetPostString("date1");
  2623. string date2 = GetPostString("date2");
  2624. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2625. if (dw.Length > 0) lw.Add(dw);
  2626. string price1 = GetPostString("price1");
  2627. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2628. string price2 = GetPostString("price2");
  2629. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2630. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2631. {
  2632. lw.Add(string.Format("CusOrgID = 94"));
  2633. }
  2634. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2635. {
  2636. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2637. }
  2638. else
  2639. {
  2640. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2641. }
  2642. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2643. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2644. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2645. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2646. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2647. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2648. if (dt != null && dt.Rows.Count > 0)
  2649. {
  2650. foreach (DataRow dr in dt.Rows)
  2651. {
  2652. try
  2653. {
  2654. // 对象操作
  2655. if (dStruct.PageSize != 100000)
  2656. {
  2657. if (dr["DispatchSort"].ToString() == "2")
  2658. {
  2659. dr["gongchuang"] = 200;
  2660. }
  2661. else if ("外协".Equals(dr["ToType"].ToString()))
  2662. {
  2663. dr["gongchuang"] = 200;
  2664. }
  2665. else if ("内部".Equals(dr["ToType"].ToString()))
  2666. {
  2667. dr["gongchuang"] = -1;
  2668. }
  2669. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2670. {
  2671. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2672. dr["gongchuang"] = response.code;
  2673. }
  2674. }
  2675. }
  2676. catch (NullReferenceException ex)
  2677. {
  2678. // 处理空引用异常
  2679. }
  2680. }
  2681. }
  2682. writeGridDataTableJson(dStruct.TotalCount, dt);
  2683. }
  2684. public void get_erp_myorderlist_pregather()
  2685. {
  2686. string date1 = GetPostString("date1");
  2687. string date2 = GetPostString("date2");
  2688. int userId = CurrentUser.UserID; //客服id
  2689. string orderWhere = "";
  2690. List<string> lw = new List<string>();
  2691. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2692. if (dw.Length > 0) lw.Add(dw);
  2693. lw.Add(string.Format("CustomerUserId={0}", userId));
  2694. lw.Add(string.Format("OrderState<9"));
  2695. orderWhere = string.Join(" and ", lw.ToArray());
  2696. string orderWhere2 = "";
  2697. List<string> lw2 = new List<string>();
  2698. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2699. if (dw2.Length > 0) lw2.Add(dw2);
  2700. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2701. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2702. string sql = string.Format("select *" +
  2703. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2704. "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 " +
  2705. "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 " +
  2706. "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");
  2707. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2708. //writeGridDataTableJson(dt.Rows.Count, dt);
  2709. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2710. }
  2711. public void upd_erp_publishorder()
  2712. {
  2713. if (UrlPostParmsCheck("ctid"))
  2714. {
  2715. string eid = GetPostString("ctid");
  2716. CeErpTradeCell entity = null;
  2717. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2718. if (entity != null)
  2719. {
  2720. entity.OrderState = 0; //发布后,变为待抢单
  2721. entity.Update();
  2722. commonHelper.UpdateRelationOrder(entity.ctid);
  2723. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2724. returnSuccessMsg("发布成功!");
  2725. return;
  2726. }
  2727. returnErrorMsg("找不到记录");
  2728. }
  2729. }
  2730. public void get_erp_my_tiporder()
  2731. {
  2732. StringBuilder sql = new StringBuilder();
  2733. int userId = 0;
  2734. if (CurrentUser != null) userId = CurrentUser.UserID;
  2735. string posCode = CurrentUser.UserPost.Post.Code;
  2736. string isTipedAfterSaleVerify = GetPostString("af");
  2737. DataTable dt = new DataTable();
  2738. if (posCode != "Supplier")
  2739. {
  2740. if (posCode == "CustomerService" || posCode == "Director")
  2741. {
  2742. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2743. }
  2744. else if (posCode == "Place" || posCode == "PlaceMr")
  2745. {
  2746. }
  2747. else
  2748. {
  2749. string teamIds = CurrentUser.User.TeamIds;
  2750. if (teamIds == "")
  2751. {
  2752. teamIds = "0";
  2753. }
  2754. 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);
  2755. }
  2756. if (sql.Length > 0)
  2757. {
  2758. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2759. }
  2760. }
  2761. if (dt.Rows.Count <= 0)
  2762. {
  2763. string key = "aftersale_order_" + userId;
  2764. if (RedisHelper.HasKey(key))
  2765. {
  2766. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2767. dt.Columns.Add("ctid", typeof(string));
  2768. dt.Columns.Add("IsReadTag", typeof(int));
  2769. foreach (var i in list)
  2770. {
  2771. DataRow data = dt.NewRow();
  2772. data["ctid"] = i;
  2773. data["IsReadTag"] = 4;
  2774. dt.Rows.Add(data);
  2775. }
  2776. RedisHelper.StringDelete(key);
  2777. }
  2778. }
  2779. if (dt.Rows.Count <= 0)
  2780. {
  2781. sql = new StringBuilder();
  2782. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2783. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2784. }
  2785. if (posCode == "Supplier")
  2786. {
  2787. string ids = CurrentUser.User.pemVend;
  2788. if (ids != null && ids.Length > 0)
  2789. {
  2790. string[] ids_list = ids.Split(',');
  2791. foreach (var item in ids_list)
  2792. {
  2793. string key = "return_order_" + item;
  2794. if (RedisHelper.HasKey(key))
  2795. {
  2796. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2797. dt.Columns.Add("ctid", typeof(string));
  2798. dt.Columns.Add("IsReadTag", typeof(int));
  2799. foreach (var i in list)
  2800. {
  2801. DataRow data = dt.NewRow();
  2802. data["ctid"] = i;
  2803. data["IsReadTag"] = 1;
  2804. dt.Rows.Add(data);
  2805. }
  2806. RedisHelper.StringDelete(key);
  2807. }
  2808. }
  2809. }
  2810. if (dt.Rows.Count <= 0)
  2811. {
  2812. sql = new StringBuilder();
  2813. 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);
  2814. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2815. }
  2816. }
  2817. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2818. }
  2819. public void reset_erp_tiporder()
  2820. {
  2821. string ids = GetPostString("ids");
  2822. string[] ctidList = ids.Split(',');
  2823. foreach (string ctid in ctidList)
  2824. {
  2825. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2826. if (enty != null)
  2827. {
  2828. enty.IsReadTag = 0;
  2829. enty.Update();
  2830. }
  2831. }
  2832. returnSuccessMsg("成功!");
  2833. return;
  2834. }
  2835. public void get_erp_designlist()
  2836. {
  2837. DataStruct dStruct = GetPostStruct();
  2838. List<string> lw = new List<string>();
  2839. string tid = GetPostString("ctid");
  2840. if (tid.Length > 0)
  2841. {
  2842. string select_tid = getTidByCtid(tid);
  2843. lw.Add(string.Format("tid='{0}'", select_tid));
  2844. }
  2845. string shopname = GetPostString("shopname");
  2846. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2847. string buyernick = GetPostString("buyer_nick");
  2848. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2849. string customer = GetPostString("customer");
  2850. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2851. string design = GetPostString("design");
  2852. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2853. string orderState = GetPostString("orderState");
  2854. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2855. lw.Add(string.Format("OrderState<6"));
  2856. string address = GetPostString("address");
  2857. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2858. string sellermemo = GetPostString("seller_memo");
  2859. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2860. string date1 = GetPostString("date1");
  2861. string date2 = GetPostString("date2");
  2862. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2863. if (dw.Length > 0) lw.Add(dw);
  2864. string apdate1 = GetPostString("apdate1");
  2865. string apdate2 = GetPostString("apdate2");
  2866. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2867. if (dwap.Length > 0) lw.Add(dwap);
  2868. string price1 = GetPostString("price1");
  2869. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2870. string price2 = GetPostString("price2");
  2871. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2872. string designTime = GetPostString("designtime");
  2873. if (designTime.Length > 0)
  2874. {
  2875. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2876. }
  2877. string usershop = CurrentUser.User.pemShop;
  2878. if (usershop.Length > 0)
  2879. {
  2880. lw.Add(string.Format("shopId in ({0})", usershop));
  2881. }
  2882. int myOrgid = CurrentUser.UserPost.OrgID;
  2883. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2884. if (myOrgCode.IndexOf("Designer") != -1)
  2885. {
  2886. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2887. {
  2888. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2889. }
  2890. else
  2891. {
  2892. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2893. }
  2894. }
  2895. else
  2896. {
  2897. string orgId = GetPostString("designerhd");
  2898. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2899. }
  2900. if (tid.Length > 0 || buyernick.Length > 0)
  2901. {
  2902. lw.Add(string.Format("OrderState >= 3"));
  2903. }
  2904. else
  2905. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2906. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2907. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2908. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2909. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2910. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2911. if (dt != null && dt.Rows.Count > 0)
  2912. {
  2913. foreach (DataRow dr in dt.Rows)
  2914. {
  2915. try
  2916. {
  2917. // 对象操作
  2918. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2919. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2920. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2921. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2922. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2923. if (dStruct.PageSize != 100000)
  2924. {
  2925. if (dr["DispatchSort"].ToString() == "2")
  2926. {
  2927. dr["gongchuang"] = 200;
  2928. }
  2929. else if ("外协".Equals(dr["ToType"].ToString()))
  2930. {
  2931. dr["gongchuang"] = 200;
  2932. }
  2933. else if ("内部".Equals(dr["ToType"].ToString()))
  2934. {
  2935. dr["gongchuang"] = -1;
  2936. }
  2937. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2938. {
  2939. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2940. dr["gongchuang"] = response.code;
  2941. }
  2942. }
  2943. }
  2944. catch (NullReferenceException ex)
  2945. {
  2946. }
  2947. }
  2948. }
  2949. writeGridDataTableJson(dStruct.TotalCount, dt);
  2950. }
  2951. public void get_erp_mydesignlist()
  2952. {
  2953. DataStruct dStruct = GetPostStruct();
  2954. List<string> lw = new List<string>();
  2955. string tid = GetPostString("ctid");
  2956. if (tid.Length > 0)
  2957. {
  2958. string select_tid = getTidByCtid(tid);
  2959. lw.Add(string.Format("tid='{0}'", select_tid));
  2960. }
  2961. string shopname = GetPostString("shopname");
  2962. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2963. string buyernick = GetPostString("buyer_nick");
  2964. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2965. string customer = GetPostString("customer");
  2966. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2967. string orderState = GetPostString("orderState");
  2968. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2969. //lw.Add(string.Format("OrderState<6"));
  2970. string date1 = GetPostString("date1");
  2971. string date2 = GetPostString("date2");
  2972. string dw = GetDateWhere("pay_time", date1, date2);
  2973. if (dw.Length > 0) lw.Add(dw);
  2974. string apdate1 = GetPostString("apdate1");
  2975. string apdate2 = GetPostString("apdate2");
  2976. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2977. if (dwap.Length > 0) lw.Add(dwap);
  2978. string price1 = GetPostString("price1");
  2979. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2980. string price2 = GetPostString("price2");
  2981. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2982. string olddownload = GetPostString("olddown");
  2983. if (olddownload == "1")
  2984. {
  2985. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2986. }
  2987. else if (olddownload == "2")
  2988. {
  2989. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2990. }
  2991. string sellermemo = GetPostString("seller_memo");
  2992. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2993. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2994. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2995. {
  2996. if (CurrentUser.User.TeamIds.Length > 0)
  2997. {
  2998. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2999. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3000. else
  3001. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3002. }
  3003. else
  3004. {
  3005. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  3006. }
  3007. }
  3008. if (tid.Length <= 0)
  3009. {
  3010. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  3011. }
  3012. lw.Add(string.Format("IsReturn!=3"));
  3013. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  3014. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3015. string teamids = CurrentUser.User.TeamIds.ToString();
  3016. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3017. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  3018. if (dt != null && dt.Rows.Count > 0)
  3019. {
  3020. foreach (DataRow dr in dt.Rows)
  3021. {
  3022. try
  3023. {
  3024. // 对象操作
  3025. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  3026. ceErpTradeCell.ctid = dr["ctid"].ToString();
  3027. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  3028. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  3029. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  3030. if (dStruct.PageSize != 100000)
  3031. {
  3032. if (dr["DispatchSort"].ToString() == "2")
  3033. {
  3034. dr["gongchuang"] = 200;
  3035. }
  3036. else if ("外协".Equals(dr["ToType"].ToString()))
  3037. {
  3038. dr["gongchuang"] = 200;
  3039. }
  3040. else if ("内部".Equals(dr["ToType"].ToString()))
  3041. {
  3042. dr["gongchuang"] = -1;
  3043. }
  3044. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  3045. {
  3046. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  3047. dr["gongchuang"] = response.code;
  3048. }
  3049. }
  3050. }
  3051. catch (NullReferenceException ex)
  3052. {
  3053. }
  3054. }
  3055. }
  3056. writeGridDataTableJson(dStruct.TotalCount, dt);
  3057. }
  3058. public void set_erp_startdesign()
  3059. {
  3060. if (UrlPostParmsCheck("ctid"))
  3061. {
  3062. string eid = GetPostString("ctid");
  3063. CeErpTradeCell entity = null;
  3064. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3065. if (entity != null)
  3066. {
  3067. if (entity.OrderState != 3)
  3068. {
  3069. returnErrorMsg("请刷新,订单已经设计了");
  3070. return;
  3071. }
  3072. entity.StartDesignTime = DateTime.Now;
  3073. entity.OrderState = 4;
  3074. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  3075. {
  3076. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3077. entity.SupplierId = suid;
  3078. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3079. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3080. }
  3081. entity.UpdateTime = DateTime.Now;
  3082. //entity.MakeSupplier = suname;
  3083. entity.Update();
  3084. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3085. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3086. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  3087. commonHelper.getCytPrice(entity);
  3088. returnSuccessMsg("操作成功!");
  3089. return;
  3090. }
  3091. returnErrorMsg("找不到记录");
  3092. }
  3093. }
  3094. public void ins_erp_designselfmemo()
  3095. {
  3096. if (UrlPostParmsCheck("ctid"))
  3097. {
  3098. string eid = GetPostString("ctid");
  3099. string con = GetPostString("con");
  3100. CeErpTradeCell entity = null;
  3101. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3102. if (entity != null)
  3103. {
  3104. entity.DesignSelfMemo = con;
  3105. entity.Update();
  3106. returnSuccessMsg("操作成功!");
  3107. return;
  3108. }
  3109. returnErrorMsg("找不到记录");
  3110. }
  3111. }
  3112. public void ins_erp_designprice()
  3113. {
  3114. if (UrlPostParmsCheck("ctid"))
  3115. {
  3116. string eid = GetPostString("ctid");
  3117. int uid = CurrentUser.UserID;
  3118. string userName = CurrentUser.UserName;
  3119. CeErpTradeCell entity = null;
  3120. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3121. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3122. if (entitys == null)
  3123. {
  3124. entitys = new CeErpDesignerBill();
  3125. }
  3126. if (entity != null)
  3127. {
  3128. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3129. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3130. entity.StartDesignTime = DateTime.Now;
  3131. entity.OrderState = 4;
  3132. string suname = "";
  3133. if (entity.SupplierId == 0)
  3134. {
  3135. int sid = commonHelper.autoDistributeToSupplier(entity);
  3136. entity.SupplierId = sid;
  3137. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3138. }
  3139. entity.Update();
  3140. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3141. if (ceErpUserPost != null)
  3142. {
  3143. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3144. if (ceErpPost != null)
  3145. {
  3146. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3147. {
  3148. entitys.tid = entity.ctid;
  3149. entitys.oid = entity.tid;
  3150. entitys.uid = uid;
  3151. entitys.userName = userName;
  3152. entitys.designerType = 1;
  3153. entitys.designerTypeText = "内部设计师";
  3154. entitys.price = Convert.ToDouble(GetPostString("price"));
  3155. entitys.designNum = GetPostInt("designNum");
  3156. entitys.modifyNum = GetPostInt("modifyNum");
  3157. entitys.designSize = GetPostString("designSize");
  3158. entitys.modifySize = GetPostString("modifySize");
  3159. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3160. {
  3161. entitys.create_time = DateTime.Now;
  3162. entitys.create_u_id = uid;
  3163. entitys.create_u_name = userName;
  3164. entitys.Save();
  3165. }
  3166. else
  3167. {
  3168. entitys.update_time = DateTime.Now;
  3169. entitys.update_u_id = uid;
  3170. entitys.update_u_name = userName;
  3171. entitys.Update();
  3172. }
  3173. }
  3174. }
  3175. }
  3176. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3177. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3178. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3179. if (suname != "")
  3180. {
  3181. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3182. }
  3183. commonHelper.getCytPrice(entity);
  3184. returnSuccessMsg("操作成功!");
  3185. return;
  3186. }
  3187. returnErrorMsg("找不到记录");
  3188. }
  3189. }
  3190. public void upload_erp_filecomplete()
  3191. {
  3192. if (UrlPostParmsCheck("ctid"))
  3193. {
  3194. string eid = GetPostString("ctid");
  3195. CeErpTradeCell entity = null;
  3196. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3197. if (entity != null)
  3198. {
  3199. entity.OrderState = 5; //设计完成
  3200. entity.Update();
  3201. returnSuccessMsg(eid + "上传成功,设计完成!");
  3202. return;
  3203. }
  3204. returnErrorMsg("找不到订单记录");
  3205. }
  3206. }
  3207. public void get_erp_designovertimelist()
  3208. {
  3209. DataStruct dStruct = GetPostStruct();
  3210. List<string> lw = new List<string>();
  3211. string tid = GetPostString("ctid");
  3212. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3213. string shopname = GetPostString("shopname");
  3214. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3215. string buyernick = GetPostString("buyer_nick");
  3216. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3217. string ResponsibleMan = GetPostString("responsible");
  3218. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3219. string date1 = GetPostString("date1");
  3220. string date2 = GetPostString("date2");
  3221. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3222. if (dw.Length > 0) lw.Add(dw);
  3223. string price1 = GetPostString("price1");
  3224. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3225. string price2 = GetPostString("price2");
  3226. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3227. string orderState = GetPostString("orderState");
  3228. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3229. string sellermemo = GetPostString("seller_memo");
  3230. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3231. lw.Add(string.Format("UnusualTag=3"));
  3232. lw.Add(string.Format("IsRefund<={0}", 1));
  3233. dStruct.Order = "WaitDesignTime desc";
  3234. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3235. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3236. writeGridDataTableJson(dStruct.TotalCount, dt);
  3237. }
  3238. //设计管理 获取抢单大厅列表
  3239. public void get_erp_grabinglist()
  3240. {
  3241. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3242. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3243. bool oldOrder = false;
  3244. if (org != null)
  3245. {
  3246. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3247. }
  3248. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3249. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3250. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3251. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3252. //先处理订单数据
  3253. if (dt.Rows.Count > 0)
  3254. {
  3255. Dictionary<string, int> design = null;
  3256. int count = 0;
  3257. foreach (DataRow row in dt.Rows)
  3258. {
  3259. if (map.ContainsKey(row["ShopId"].ToString()))
  3260. {
  3261. map.TryGetValue(row["ShopId"].ToString(), out design);
  3262. }
  3263. else
  3264. {
  3265. design = new Dictionary<string, int>();
  3266. }
  3267. if (design.ContainsKey(row["ProductId"].ToString()))
  3268. {
  3269. design.TryGetValue(row["ProductId"].ToString(), out count);
  3270. }
  3271. count++;
  3272. design[row["ProductId"].ToString()] = count;
  3273. map[row["ShopId"].ToString()] = design;
  3274. }
  3275. }
  3276. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3277. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3278. //把店铺排序和技能排序分类
  3279. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3280. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3281. if (design_dt.Rows.Count > 0)
  3282. {
  3283. Dictionary<string, string> design = null;
  3284. List<string> shopIds = null;
  3285. foreach (DataRow row in design_dt.Rows)
  3286. {
  3287. if ("0".Equals(row["designId"].ToString()))
  3288. {
  3289. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3290. {
  3291. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3292. }
  3293. else
  3294. {
  3295. shopIds = new List<string>();
  3296. }
  3297. shopIds.Add(row["shopId"].ToString());
  3298. shop_orders[row["orders"].ToString()] = shopIds;
  3299. }
  3300. else
  3301. {
  3302. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3303. {
  3304. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3305. }
  3306. else
  3307. {
  3308. design = new Dictionary<string, string>();
  3309. }
  3310. design[row["orders"].ToString()] = row["designId"].ToString();
  3311. design_orders[row["shopId"].ToString()] = design;
  3312. }
  3313. }
  3314. //处理成key value后根据key排序
  3315. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3316. foreach (List<string> val in shop_orders.Values)
  3317. {
  3318. if (val != null)
  3319. {
  3320. foreach (string key in val)
  3321. {
  3322. if (design_orders.ContainsKey(key.ToString()))
  3323. {
  3324. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3325. }
  3326. }
  3327. }
  3328. }
  3329. }
  3330. //校验哪个优先级有订单
  3331. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3332. foreach (string key in shop_orders.Keys)
  3333. {
  3334. List<string> ids = null;
  3335. shop_orders.TryGetValue(key, out ids);
  3336. //id为shopid
  3337. foreach (string id in ids)
  3338. {
  3339. Dictionary<string, int> list = null;
  3340. Dictionary<string, string> desing = null;
  3341. map.TryGetValue(id, out list);
  3342. design_orders.TryGetValue(id, out desing);
  3343. if (list != null && desing != null)
  3344. {
  3345. foreach (var item in desing)
  3346. {
  3347. int count = 0;
  3348. if (list.ContainsKey(item.Value))
  3349. {
  3350. list.TryGetValue(item.Value, out count);
  3351. if (count > 0)
  3352. {
  3353. designIds[id] = item.Value;
  3354. break;
  3355. }
  3356. }
  3357. }
  3358. }
  3359. }
  3360. if (designIds.Count > 0)
  3361. {
  3362. break;
  3363. }
  3364. }
  3365. DataTable table = new DataTable();
  3366. table.Columns.Add("tid", typeof(string));
  3367. table.Columns.Add("ctid", typeof(string));
  3368. table.Columns.Add("seller_nick", typeof(string));
  3369. table.Columns.Add("productName", typeof(string));
  3370. table.Columns.Add("pay_time", typeof(string));
  3371. table.Columns.Add("seller_memo", typeof(string));
  3372. if (designIds.Count > 0)
  3373. {
  3374. string shopId = "";
  3375. string productId = "";
  3376. foreach (var designInfo in designIds)
  3377. {
  3378. shopId = designInfo.Key;
  3379. productId = designInfo.Value;
  3380. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3381. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3382. if (dt.Rows.Count > 0)
  3383. {
  3384. foreach (DataRow row in dt.Rows)
  3385. {
  3386. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3387. {
  3388. DataRow data = table.NewRow();
  3389. data["ctid"] = row["ctid"].ToString();
  3390. data["tid"] = row["tid"].ToString();
  3391. data["seller_nick"] = ceErpShop.ShopName;
  3392. data["pay_time"] = row["pay_time"].ToString();
  3393. data["seller_memo"] = row["seller_memo"].ToString();
  3394. data["productName"] = ceErpProduct.PType;
  3395. table.Rows.Add(data);
  3396. }
  3397. }
  3398. }
  3399. }
  3400. }
  3401. writeGridDataTableJson(table.Rows.Count, table);
  3402. }
  3403. private object rushLockObject = new object();
  3404. public void set_erp_grabingorder()
  3405. {
  3406. if (UrlPostParmsCheck("ctid"))
  3407. {
  3408. int total = CurrentUser.User.Person.Total;
  3409. int userId = CurrentUser.User.ID;
  3410. int noFinish = CurrentUser.User.Person.NoFinish;
  3411. int finalization = CurrentUser.User.Person.Finalization;
  3412. string eids = GetPostString("ctid");
  3413. string key = "RushKey_" + userId;
  3414. int count = 0;
  3415. if (erpRedis.RedisHelper.KeyExists(key))
  3416. {
  3417. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3418. if (redisCount != null)
  3419. {
  3420. count = Convert.ToInt32(redisCount);
  3421. }
  3422. }
  3423. if (count >= total)
  3424. {
  3425. returnErrorMsg("半小时内已经抢" + total + "单");
  3426. return;
  3427. }
  3428. string[] ctidlist = eids.Split(',');
  3429. if (count + ctidlist.Length > total)
  3430. {
  3431. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3432. return;
  3433. }
  3434. int itag = 0;
  3435. lock (rushLockObject)
  3436. {
  3437. if (ctidlist.Length > 0)
  3438. {
  3439. string[] dtList = new string[ctidlist.Length];
  3440. for (int i = 0; i < ctidlist.Length; i++)
  3441. {
  3442. dtList[i] = "'" + ctidlist[i] + "'";
  3443. }
  3444. 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"));
  3445. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3446. if (dt_user.Rows.Count > 0)
  3447. {
  3448. int doing = 0;//未定稿
  3449. int finish = 0;//已完成
  3450. foreach (DataRow dr in dt_user.Rows)
  3451. {
  3452. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3453. {
  3454. doing++;
  3455. }
  3456. else
  3457. {
  3458. finish++;
  3459. }
  3460. }
  3461. if (doing >= noFinish)
  3462. {
  3463. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3464. return;
  3465. }
  3466. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3467. {
  3468. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3469. return;
  3470. }
  3471. }
  3472. //校验选择单子状态
  3473. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3474. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3475. if (dt.Rows.Count > 0)
  3476. {
  3477. List<string> list = new List<string>();
  3478. foreach (DataRow dr in dt.Rows)
  3479. {
  3480. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3481. {
  3482. list.Add(dr["ctid"].ToString());
  3483. }
  3484. }
  3485. if (list.Count > 0)
  3486. {
  3487. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3488. return;
  3489. }
  3490. }
  3491. foreach (string ctid in ctidlist)
  3492. {
  3493. CeErpTradeCell entity = null;
  3494. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3495. if (entity != null)
  3496. {
  3497. entity.OrderState = 3;
  3498. entity.DesignUserId = CurrentUser.UserID;
  3499. entity.WaitDesignTime = DateTime.Now;
  3500. entity.StartDesignTime = DateTime.Now;
  3501. entity.Update();
  3502. commonHelper.UpdateRelationOrder(entity.ctid);
  3503. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3504. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3505. itag++;
  3506. }
  3507. }
  3508. }
  3509. }
  3510. count += ctidlist.Length;
  3511. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3512. if (itag == 0)
  3513. returnErrorMsg("没有找到相关订单");
  3514. else
  3515. returnSuccessMsg("抢单成功!");
  3516. return;
  3517. }
  3518. }
  3519. public void get_erp_waitorderlist()
  3520. {
  3521. DataStruct dStruct = GetPostStruct();
  3522. List<string> lw = new List<string>();
  3523. string tid = GetPostString("ctid");
  3524. if (tid.Length > 0)
  3525. {
  3526. string select_tid = getTidByCtid(tid);
  3527. lw.Add(string.Format("tid='{0}'", select_tid));
  3528. }
  3529. string shopname = GetPostString("shopname");
  3530. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3531. string buyernick = GetPostString("buyer_nick");
  3532. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3533. string customer = GetPostString("customer");
  3534. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3535. string design = GetPostString("design");
  3536. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3537. string orderState = GetPostString("orderState");
  3538. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3539. string supplier = GetPostString("supplier");
  3540. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3541. string sellermemo = GetPostString("seller_memo");
  3542. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3543. string otherMemo = GetPostString("otherMemo");
  3544. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3545. string address = GetPostString("address");
  3546. 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));
  3547. string date1 = GetPostString("date1");
  3548. string date2 = GetPostString("date2");
  3549. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3550. if (dw.Length > 0) lw.Add(dw);
  3551. string price1 = GetPostString("price1");
  3552. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3553. string price2 = GetPostString("price2");
  3554. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3555. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3556. lw.Add(string.Format("IsSample != 2 "));
  3557. lw.Add(string.Format("OrderState = 5 "));
  3558. lw.Add(string.Format("IsRefund<={0}", 1));
  3559. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3560. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3561. string pagesize = GetPostString("pagesize");
  3562. if (pagesize != null)
  3563. {
  3564. dStruct.PageSize = 200;
  3565. }
  3566. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3567. List<string> tids = new List<string>();
  3568. if (dt != null)
  3569. {
  3570. dt.Columns.Add("compenPrice", typeof(double));
  3571. foreach (DataRow dr in dt.Rows)
  3572. {
  3573. if (Convert.IsDBNull(dr["compenPrice"]))
  3574. {
  3575. dr["compenPrice"] = 0;
  3576. }
  3577. tids.Add("'" + dr["tid"].ToString() + "'");
  3578. 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();
  3579. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3580. {
  3581. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3582. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3583. entity.SupplierId = suid;
  3584. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3585. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3586. entity.Update();
  3587. }
  3588. }
  3589. }
  3590. if (tids.Count > 0)
  3591. {
  3592. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3593. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3594. if (dt_price != null && dt_price.Rows.Count > 0)
  3595. {
  3596. foreach (DataRow dr in dt_price.Rows)
  3597. {
  3598. foreach (DataRow row in dt.Rows)
  3599. {
  3600. if (row["tid"].Equals(dr["ptid"]))
  3601. {
  3602. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3603. break;
  3604. }
  3605. }
  3606. }
  3607. }
  3608. }
  3609. writeGridDataTableJson(dStruct.TotalCount, dt);
  3610. }
  3611. public void get_erp_supplierwaitorderlist()
  3612. {
  3613. DataStruct dStruct = GetPostStruct();
  3614. List<string> lw = new List<string>();
  3615. string tid = GetPostString("ctid");
  3616. if (tid.Length > 0)
  3617. {
  3618. string select_tid = getTidByCtid(tid);
  3619. lw.Add(string.Format("tid='{0}'", select_tid));
  3620. }
  3621. string shopname = GetPostString("shopname");
  3622. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3623. string sellermemo = GetPostString("seller_memo");
  3624. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3625. string date1 = GetPostString("date1");
  3626. string date2 = GetPostString("date2");
  3627. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3628. if (dw.Length > 0) lw.Add(dw);
  3629. lw.Add(string.Format("OrderState = 5 "));
  3630. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3631. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3632. {
  3633. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3634. }
  3635. string supplier = GetPostString("supplier");
  3636. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3637. {
  3638. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3639. }
  3640. lw.Add(string.Format("IsRefund<={0}", 1));
  3641. dStruct.Order = "FinishDesignTime desc";
  3642. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3643. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3644. if (dt != null)
  3645. {
  3646. foreach (DataRow dr in dt.Rows)
  3647. {
  3648. 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();
  3649. }
  3650. }
  3651. writeGridDataTableJson(dStruct.TotalCount, dt);
  3652. }
  3653. public void upd_erp_verifytosupplier()
  3654. {
  3655. if (UrlPostParmsCheck("ctid"))
  3656. {
  3657. string eids = GetPostString("ctid");
  3658. CeErpTradeCell entity = null;
  3659. string[] eidsList = eids.Split(',');
  3660. if (eidsList.Length <= 0)
  3661. {
  3662. returnErrorMsg("订单号不能空");
  3663. return;
  3664. }
  3665. List<string> tLst = new List<string>();
  3666. foreach (string ctidstr in eidsList)
  3667. {
  3668. tLst.Add("'" + ctidstr + "'");
  3669. CeErpDataSendOrderInfo.createObject(ctidstr);
  3670. }
  3671. string needtids = string.Join(",", tLst.ToArray());
  3672. StringBuilder sql = new StringBuilder();
  3673. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3674. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1},IsHaveNewOrder=0 where SupplierId!=0 AND OrderState = 5 and ctid in ({0});", needtids, CurrentUser.UserID);
  3675. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3676. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3677. returnSuccessMsg("操作成功!");
  3678. return;
  3679. /**foreach (string ctidstr in eidsList)
  3680. {
  3681. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3682. if (entity != null)
  3683. {
  3684. if (entity.SupplierId == 0)
  3685. {
  3686. continue;
  3687. }
  3688. entity.IsVerifyToSupplier = true;
  3689. if (entity.IsReturn == 1) //1是供应商打回
  3690. {
  3691. entity.IsReturn = 0;
  3692. }
  3693. entity.FinishPlaceTime = DateTime.Now;
  3694. entity.PlaceUserId = CurrentUser.UserID;
  3695. entity.Update();
  3696. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3697. }
  3698. }
  3699. returnSuccessMsg("操作成功!");
  3700. return;**/
  3701. }
  3702. }
  3703. public void upd_erp_supplierback()
  3704. {
  3705. if (UrlPostParmsCheck("ctid"))
  3706. {
  3707. string eid = GetPostString("ctid");
  3708. string reason = GetPostString("returnreason");
  3709. CeErpTradeCell entity = null;
  3710. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3711. if (entity != null)
  3712. {
  3713. string message = "操作成功!";
  3714. string isDown = "";
  3715. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3716. {
  3717. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3718. isDown = "被点击下载";
  3719. }
  3720. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3721. {
  3722. string key = "return_order_" + entity.SupplierId;
  3723. List<string> list = new List<string>();
  3724. if (RedisHelper.HasKey(key))
  3725. {
  3726. object data = RedisHelper.StringGet(key);
  3727. list = Convert.ToString(data).Split(',').ToList();
  3728. }
  3729. list.Add(eid);
  3730. RedisHelper.StringSet(key, string.Join(",", list));
  3731. }
  3732. entity.IsVerifyToSupplier = false;
  3733. entity.IsReturn = 1;
  3734. entity.IsHaveNewOrder = 0;
  3735. entity.ReturnTime = DateTime.Now;
  3736. entity.ReturnReason = reason;
  3737. if (entity.OrderState == 6)
  3738. {
  3739. entity.OrderState = 5;
  3740. }
  3741. entity.Update();
  3742. CeErpSukuraData.createInfo(entity.ctid, 5);
  3743. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3744. returnSuccessMsg(message);
  3745. return;
  3746. }
  3747. returnErrorMsg("找不到订单记录");
  3748. }
  3749. }
  3750. public void upd_erp_toaftersaleorder()
  3751. {
  3752. if (UrlPostParmsCheck("ctid"))
  3753. {
  3754. string eid = GetPostString("ctid");
  3755. string reason = GetPostString("returnreason");
  3756. CeErpTradeCell entity = null;
  3757. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3758. if (entity != null)
  3759. {
  3760. if (entity.isAfterSaleOrder != 1)
  3761. {
  3762. returnErrorMsg("带S的售后单才能打回给售后");
  3763. return;
  3764. }
  3765. if (entity.OrderState >= 5)
  3766. {
  3767. returnErrorMsg("已经设计完成了不能打回给售后");
  3768. return;
  3769. }
  3770. entity.OrderState = 0;
  3771. entity.IsReturn = 3;
  3772. entity.ReturnTime = DateTime.Now;
  3773. entity.UpdateTime = DateTime.Now;
  3774. entity.ReturnReason = reason;
  3775. entity.Update();
  3776. CeErpSukuraData.createInfo(entity.ctid, 5);
  3777. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3778. returnSuccessMsg("操作成功!");
  3779. return;
  3780. }
  3781. returnErrorMsg("找不到订单记录");
  3782. }
  3783. }
  3784. public void upd_erp_aftersaletodesign()
  3785. {
  3786. if (UrlPostParmsCheck("ctid"))
  3787. {
  3788. string eid = GetPostString("ctid");
  3789. CeErpTradeCell entity = null;
  3790. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3791. if (entity != null)
  3792. {
  3793. entity.OrderState = 3;
  3794. entity.IsReturn = 0;
  3795. entity.UpdateTime = DateTime.Now;
  3796. entity.Update();
  3797. CeErpSukuraData.createInfo(entity.ctid, 5);
  3798. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3799. returnSuccessMsg("操作成功!");
  3800. return;
  3801. }
  3802. returnErrorMsg("找不到订单记录");
  3803. }
  3804. }
  3805. public void assign_erp_supplier()
  3806. {
  3807. if (UrlPostParmsCheck("ctid"))
  3808. {
  3809. string eids = GetPostString("ctid");
  3810. int sid = GetPostInt("SupplierName");
  3811. string fromTag = GetPostString("tag");
  3812. string[] eidList = eids.Split(',');
  3813. if (eidList.Length <= 0)
  3814. {
  3815. returnErrorMsg("指派不能为空");
  3816. return;
  3817. }
  3818. string errMsg = "";
  3819. string suname = commonHelper.getSupplierNameById(sid);
  3820. foreach (string ctid in eidList)
  3821. {
  3822. CeErpTradeCell entity = null;
  3823. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3824. if (entity != null)
  3825. {
  3826. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3827. {
  3828. errMsg += (ctid + "指派失败!!!");
  3829. continue;
  3830. }
  3831. entity.SupplierId = sid;
  3832. entity.Update();
  3833. commonHelper.UpdateRelationOrder(entity.ctid);
  3834. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3835. if (entity.OrderState >= 6)
  3836. {
  3837. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3838. //{
  3839. // string msl = entity.MakeSupplier;
  3840. // string[] mslist = msl.Split(',');
  3841. // 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);
  3842. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3843. //}
  3844. //else
  3845. //{
  3846. StringBuilder sql = new StringBuilder();
  3847. 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);
  3848. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3849. //}
  3850. }
  3851. }
  3852. else
  3853. {
  3854. continue;
  3855. }
  3856. }
  3857. if (errMsg.Length > 0)
  3858. {
  3859. returnErrorMsg(errMsg);
  3860. return;
  3861. }
  3862. returnSuccessMsg("操作成功!");
  3863. return;
  3864. }
  3865. }
  3866. public void assign_erp_makesupplier()
  3867. {
  3868. if (UrlPostParmsCheck("ctid"))
  3869. {
  3870. string eids = GetPostString("ctid");
  3871. string sname = GetPostString("SupplierName");
  3872. string[] eidList = eids.Split(',');
  3873. if (eidList.Length <= 0)
  3874. {
  3875. returnErrorMsg("指派不能为空");
  3876. return;
  3877. }
  3878. List<string> tLst = new List<string>();
  3879. foreach (string ctid in eidList)
  3880. {
  3881. CeErpTradeCell entity = null;
  3882. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3883. if (entity != null)
  3884. {
  3885. entity.MakeSupplier = sname;
  3886. entity.Update();
  3887. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3888. tLst.Add("'" + ctid + "'");
  3889. }
  3890. else
  3891. {
  3892. continue;
  3893. }
  3894. }
  3895. string ctids = string.Join(",", tLst.ToArray());
  3896. StringBuilder sql2 = new StringBuilder();
  3897. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3898. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3899. returnSuccessMsg("操作成功!");
  3900. return;
  3901. }
  3902. }
  3903. public void ins_erp_returnreason()
  3904. {
  3905. if (UrlPostParmsCheck("ctid"))
  3906. {
  3907. string eid = GetPostString("ctid");
  3908. CeErpTradeCell entity = null;
  3909. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3910. string userpost = CurrentUser.UserPost.Post.Code;
  3911. if (entity != null)
  3912. {
  3913. bool isPlace = false;
  3914. if (entity.OrderState > 6)
  3915. {
  3916. returnErrorMsg("已发货无法打回!");
  3917. return;
  3918. }
  3919. if (entity.OrderState == 6)
  3920. {
  3921. isPlace = true;
  3922. }
  3923. bool isNeedUpdateCell2 = false;
  3924. if (entity.OrderState >= 6)
  3925. {
  3926. isNeedUpdateCell2 = true;
  3927. }
  3928. int returnTag = 2;
  3929. if (userpost == "Supplier")
  3930. {
  3931. returnTag = 1;
  3932. }
  3933. int toType = GetPostInt("totype");
  3934. string fromType = "3";
  3935. if (entity.OrderState < 5)
  3936. {
  3937. fromType = "3";
  3938. }
  3939. else
  3940. {
  3941. fromType = "4";
  3942. }
  3943. if (entity.IsXianHuo == 0)
  3944. {
  3945. if (returnTag == 2)
  3946. {
  3947. if (toType == 1)
  3948. {
  3949. entity.OrderState = 0;
  3950. entity.ReturnUserType = 1;
  3951. string clearman = GetPostString("clearman");
  3952. if (!string.IsNullOrEmpty(clearman))
  3953. {
  3954. entity.DesignUserId = 0;
  3955. }
  3956. }
  3957. else
  3958. {
  3959. entity.OrderState = 3;
  3960. entity.ReturnUserType = 2;
  3961. }
  3962. entity.IsReadTag = 1;
  3963. }
  3964. else if (returnTag == 1)
  3965. {
  3966. entity.OrderState = 5;
  3967. }
  3968. entity.IsVerifyToSupplier = false;
  3969. }
  3970. if (entity.IsXianHuo == 1)
  3971. {
  3972. entity.OrderState = 5;
  3973. }
  3974. entity.UnusualTag = 0;
  3975. entity.UnusualTime = null;
  3976. entity.UnusualCon = "";
  3977. entity.IsReturn = returnTag;
  3978. entity.ReturnTime = DateTime.Now;
  3979. entity.UpdateTime = DateTime.Now;
  3980. entity.ReturnReason = GetPostString("returnreason");
  3981. entity.Update();
  3982. if (entity.OrderState == 3)
  3983. {
  3984. ApiVo apiVo = new ApiVo();
  3985. apiVo.orderNumber = entity.ctid;
  3986. apiVo.actionName = "rebutDesign";
  3987. apiVo.orderRemarks = entity.ReturnReason;
  3988. designHelper.API_WorkCore(apiVo);//rebutDesign
  3989. }
  3990. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3991. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3992. {
  3993. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3994. }
  3995. CeErpSukuraData.createInfo(entity.ctid, 5);
  3996. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3997. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3998. if (isPlace)
  3999. {
  4000. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  4001. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4002. if (dth != null && dth.Rows.Count > 0)
  4003. {
  4004. dataSendOrderBean dataSendOrderBean = null;
  4005. foreach (DataRow item in dth.Rows)
  4006. {
  4007. try
  4008. {
  4009. dataSendOrderBean = new dataSendOrderBean();
  4010. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  4011. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  4012. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  4013. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  4014. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  4015. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  4016. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  4017. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  4018. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  4019. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  4020. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  4021. dataSendOrderBean.Radio1723534706288 = "打回";
  4022. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  4023. if (result != null)
  4024. {
  4025. if ("0".Equals(result.errcode))
  4026. {
  4027. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  4028. }
  4029. else
  4030. {
  4031. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  4032. }
  4033. }
  4034. }
  4035. catch (Exception ex)
  4036. {
  4037. }
  4038. }
  4039. }
  4040. }
  4041. if (isNeedUpdateCell2)
  4042. {
  4043. if (entity.MakeSupplier.IndexOf(",") != -1)
  4044. {
  4045. StringBuilder sql2 = new StringBuilder();
  4046. 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);
  4047. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4048. }
  4049. else
  4050. {
  4051. StringBuilder sql2 = new StringBuilder();
  4052. 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);
  4053. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4054. }
  4055. }
  4056. returnSuccessMsg("操作成功!");
  4057. return;
  4058. }
  4059. returnErrorMsg("找不到订单记录");
  4060. }
  4061. }
  4062. public void cyt_erp_returnreason()
  4063. {
  4064. if (UrlPostParmsCheck("ctid"))
  4065. {
  4066. string eid = GetPostString("ctid");
  4067. CeErpTradeCell entity = null;
  4068. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4069. string userpost = CurrentUser.UserPost.Post.Code;
  4070. if (entity != null)
  4071. {
  4072. if (entity.OrderState > 6)
  4073. {
  4074. returnErrorMsg("已发货无法打回!");
  4075. return;
  4076. }
  4077. JObject jsonObject = new JObject
  4078. {
  4079. { "Userid", "77886" },
  4080. { "Pwd", "lt666888" },
  4081. { "LTOrderId",eid }
  4082. };
  4083. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  4084. JObject jsonObjects = JObject.Parse(response);
  4085. string msg = (string)jsonObjects["msg"];
  4086. if (msg != "取消成功")
  4087. {
  4088. returnErrorMsg(msg);
  4089. return;
  4090. }
  4091. bool isNeedUpdateCell2 = false;
  4092. if (entity.OrderState >= 6)
  4093. {
  4094. isNeedUpdateCell2 = true;
  4095. }
  4096. int returnTag = 2;
  4097. if (userpost == "Supplier")
  4098. {
  4099. returnTag = 1;
  4100. }
  4101. if (entity.IsXianHuo == 0)
  4102. {
  4103. if (returnTag == 2)
  4104. {
  4105. int toType = GetPostInt("totype");
  4106. if (toType == 1)
  4107. {
  4108. entity.OrderState = 0;
  4109. entity.ReturnUserType = 1;
  4110. }
  4111. else
  4112. {
  4113. entity.OrderState = 4;
  4114. entity.ReturnUserType = 2;
  4115. }
  4116. entity.IsReadTag = 1;
  4117. }
  4118. else if (returnTag == 1)
  4119. {
  4120. entity.OrderState = 5;
  4121. }
  4122. entity.IsVerifyToSupplier = false;
  4123. }
  4124. entity.UnusualTag = 0;
  4125. entity.UnusualTime = null;
  4126. entity.UnusualCon = "";
  4127. entity.IsReturn = returnTag;
  4128. entity.ReturnTime = DateTime.Now;
  4129. entity.ReturnReason = GetPostString("returnreason");
  4130. entity.Update();
  4131. if (entity.OrderState == 4)
  4132. {
  4133. ApiVo apiVo = new ApiVo();
  4134. apiVo.orderNumber = entity.ctid;
  4135. apiVo.actionName = "rebutDesign";
  4136. apiVo.orderRemarks = entity.ReturnReason;
  4137. designHelper.API_WorkCore(apiVo);//rebutDesign
  4138. }
  4139. CeErpSukuraData.createInfo(entity.ctid, 5);
  4140. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4141. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4142. if (isNeedUpdateCell2)
  4143. {
  4144. if (entity.MakeSupplier.IndexOf(",") != -1)
  4145. {
  4146. StringBuilder sql2 = new StringBuilder();
  4147. 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);
  4148. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4149. }
  4150. else
  4151. {
  4152. StringBuilder sql2 = new StringBuilder();
  4153. 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);
  4154. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4155. }
  4156. }
  4157. returnSuccessMsg("操作成功!");
  4158. return;
  4159. }
  4160. returnErrorMsg("找不到订单记录");
  4161. }
  4162. }
  4163. public void upd_erp_xianhuoreturntag()
  4164. {
  4165. if (UrlPostParmsCheck("ctid"))
  4166. {
  4167. string eids = GetPostString("ctid");
  4168. string[] ctids = eids.Split(',');
  4169. foreach (string ctid in ctids)
  4170. {
  4171. CeErpTradeCell entity = null;
  4172. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4173. if (entity != null)
  4174. {
  4175. entity.IsReturn = 0;
  4176. entity.Update();
  4177. CeErpSukuraData.createInfo(entity.ctid, 5);
  4178. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4179. }
  4180. }
  4181. returnSuccessMsg("操作成功!");
  4182. return;
  4183. }
  4184. }
  4185. public void get_erp_waitdeliverylist()
  4186. {
  4187. DataStruct dStruct = GetPostStruct();
  4188. List<string> lw = new List<string>();
  4189. string tid = GetPostString("ctid");
  4190. if (tid.Length > 0)
  4191. {
  4192. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4193. if (tid.Length > 5)
  4194. {
  4195. List<string> tids = getTidByCtidLike(tid);
  4196. if (tids.Count > 0 && tids.Count < 10)
  4197. {
  4198. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4199. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4200. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4201. {
  4202. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4203. }*/
  4204. }
  4205. }
  4206. lw.Add(tid_sql);
  4207. }
  4208. string shopname = GetPostString("shopname");
  4209. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4210. string buyernick = GetPostString("buyer_nick");
  4211. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4212. //if (tid.Length == 0 && buyernick.Length == 0)
  4213. //{
  4214. // lw.Add(string.Format("IsRefund<={0}", 1));
  4215. //}
  4216. string customer = GetPostString("customer");
  4217. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4218. string design = GetPostString("design");
  4219. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4220. string orderState = GetPostString("orderState");
  4221. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4222. string address = GetPostString("address");
  4223. 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));
  4224. string sellermemo = GetPostString("seller_memo");
  4225. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4226. string supplier = GetPostString("supplier");
  4227. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4228. string OrderArea = GetPostString("order_area");
  4229. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4230. string placedate1 = GetPostString("placedate1");
  4231. string placedate2 = GetPostString("placedate2");
  4232. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4233. if (fdw.Length > 0) lw.Add(fdw);
  4234. string price1 = GetPostString("price1");
  4235. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4236. string price2 = GetPostString("price2");
  4237. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4238. string unusualCon = GetPostString("unusualcon");
  4239. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4240. string otherMemo = GetPostString("otherMemo");
  4241. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4242. string posTag = CurrentUser.UserPost.Post.Code;
  4243. if (posTag == "Supplier")
  4244. {
  4245. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4246. }
  4247. else
  4248. {
  4249. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4250. {
  4251. string usershop = CurrentUser.User.pemShop;
  4252. lw.Add(string.Format("ShopId in ({0})", usershop));
  4253. }
  4254. }
  4255. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4256. lw.Add(string.Format("type != 'PDD' "));
  4257. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4258. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4259. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4260. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4261. writeGridDataTableJson(dStruct.TotalCount, dt);
  4262. }
  4263. public void get_erp_changedeliverylist()
  4264. {
  4265. DataStruct dStruct = GetPostStruct();
  4266. List<string> lw = new List<string>();
  4267. string tid = GetPostString("ctid");
  4268. if (tid.Length > 0)
  4269. {
  4270. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4271. if (tid.Length > 5)
  4272. {
  4273. List<string> tids = getTidByCtidLike(tid);
  4274. if (tids.Count > 0 && tids.Count < 10)
  4275. {
  4276. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4277. }
  4278. }
  4279. lw.Add(tid_sql);
  4280. }
  4281. string shopname = GetPostString("shopname");
  4282. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4283. string buyernick = GetPostString("buyer_nick");
  4284. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4285. //if (tid.Length == 0 && buyernick.Length == 0)
  4286. //{
  4287. // lw.Add(string.Format("IsRefund<={0}", 1));
  4288. //}
  4289. string customer = GetPostString("customer");
  4290. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4291. string design = GetPostString("design");
  4292. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4293. string orderState = GetPostString("orderState");
  4294. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4295. string address = GetPostString("address");
  4296. if (address.Length > 0) lw.Add(string.Format("(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));
  4297. string sellermemo = GetPostString("seller_memo");
  4298. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4299. string supplier = GetPostString("supplier");
  4300. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4301. string OrderArea = GetPostString("order_area");
  4302. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4303. string placedate1 = GetPostString("placedate1");
  4304. string placedate2 = GetPostString("placedate2");
  4305. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4306. if (fdw.Length > 0) lw.Add(fdw);
  4307. string price1 = GetPostString("price1");
  4308. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4309. string price2 = GetPostString("price2");
  4310. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4311. string unusualCon = GetPostString("unusualcon");
  4312. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4313. string otherMemo = GetPostString("otherMemo");
  4314. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4315. string posTag = CurrentUser.UserPost.Post.Code;
  4316. if (posTag == "Supplier")
  4317. {
  4318. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4319. }
  4320. else
  4321. {
  4322. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4323. {
  4324. string usershop = CurrentUser.User.pemShop;
  4325. lw.Add(string.Format("ShopId in ({0})", usershop));
  4326. }
  4327. }
  4328. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4329. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4330. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4331. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4332. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4333. /*if (tid.Length > 0)
  4334. {
  4335. List<string> tids = new List<string>();
  4336. if (dt != null && dt.Rows.Count > 0)
  4337. {
  4338. foreach (DataRow item in dt.Rows)
  4339. {
  4340. tids.Add("'" + item["tid"] + "'");
  4341. }
  4342. }
  4343. if (tids.Count > 0)
  4344. {
  4345. lw.RemoveAt(0);
  4346. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4347. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4348. dt = WebCache.GetData("view_erptradecell", dStruct);
  4349. }
  4350. }*/
  4351. writeGridDataTableJson(dStruct.TotalCount, dt);
  4352. }
  4353. public void get_erp_pddderiving()
  4354. {
  4355. DataStruct dStruct = GetPostStruct();
  4356. List<string> lw = new List<string>();
  4357. string tid = GetPostString("ctid");
  4358. if (tid.Length > 0)
  4359. {
  4360. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4361. if (tid.Length > 5)
  4362. {
  4363. List<string> tids = getTidByCtidLike(tid);
  4364. if (tids.Count > 0 && tids.Count < 10)
  4365. {
  4366. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4367. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4368. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4369. {
  4370. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4371. }*/
  4372. }
  4373. }
  4374. lw.Add(tid_sql);
  4375. }
  4376. string shopname = GetPostString("shopname");
  4377. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4378. string buyernick = GetPostString("buyer_nick");
  4379. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4380. //if (tid.Length == 0 && buyernick.Length == 0)
  4381. //{
  4382. // lw.Add(string.Format("IsRefund<={0}", 1));
  4383. //}
  4384. string customer = GetPostString("customer");
  4385. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4386. string design = GetPostString("design");
  4387. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4388. string orderState = GetPostString("orderState");
  4389. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4390. string address = GetPostString("address");
  4391. 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));
  4392. string sellermemo = GetPostString("seller_memo");
  4393. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4394. string supplier = GetPostString("supplier");
  4395. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4396. string OrderArea = GetPostString("order_area");
  4397. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4398. string placedate1 = GetPostString("placedate1");
  4399. string placedate2 = GetPostString("placedate2");
  4400. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4401. if (fdw.Length > 0) lw.Add(fdw);
  4402. string price1 = GetPostString("price1");
  4403. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4404. string price2 = GetPostString("price2");
  4405. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4406. string unusualCon = GetPostString("unusualcon");
  4407. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4408. string posTag = CurrentUser.UserPost.Post.Code;
  4409. if (posTag == "Supplier")
  4410. {
  4411. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4412. }
  4413. else
  4414. {
  4415. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4416. {
  4417. string usershop = CurrentUser.User.pemShop;
  4418. lw.Add(string.Format("ShopId in ({0})", usershop));
  4419. }
  4420. }
  4421. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4422. lw.Add(string.Format("type = 'PDD' "));
  4423. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4424. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4425. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4426. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4427. /*if (tid.Length > 0)
  4428. {
  4429. List<string> tids = new List<string>();
  4430. if (dt != null && dt.Rows.Count > 0)
  4431. {
  4432. foreach (DataRow item in dt.Rows)
  4433. {
  4434. tids.Add("'" + item["tid"] + "'");
  4435. }
  4436. }
  4437. if (tids.Count > 0)
  4438. {
  4439. lw.RemoveAt(0);
  4440. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4441. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4442. dt = WebCache.GetData("view_erptradecell", dStruct);
  4443. }
  4444. }*/
  4445. writeGridDataTableJson(dStruct.TotalCount, dt);
  4446. }
  4447. public void get_erp_jdderiving()
  4448. {
  4449. DataStruct dStruct = GetPostStruct();
  4450. List<string> lw = new List<string>();
  4451. string tid = GetPostString("ctid");
  4452. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4453. string shopname = GetPostString("shopname");
  4454. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4455. string buyernick = GetPostString("buyer_nick");
  4456. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4457. //if (tid.Length == 0 && buyernick.Length == 0)
  4458. //{
  4459. // lw.Add(string.Format("IsRefund<={0}", 1));
  4460. //}
  4461. string customer = GetPostString("customer");
  4462. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4463. string design = GetPostString("design");
  4464. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4465. string orderState = GetPostString("orderState");
  4466. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4467. string address = GetPostString("address");
  4468. if (address.Length > 0) lw.Add(string.Format("(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));
  4469. string sellermemo = GetPostString("seller_memo");
  4470. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4471. string supplier = GetPostString("supplier");
  4472. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4473. string OrderArea = GetPostString("order_area");
  4474. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4475. string placedate1 = GetPostString("placedate1");
  4476. string placedate2 = GetPostString("placedate2");
  4477. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4478. if (fdw.Length > 0) lw.Add(fdw);
  4479. string price1 = GetPostString("price1");
  4480. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4481. string price2 = GetPostString("price2");
  4482. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4483. string unusualCon = GetPostString("unusualcon");
  4484. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4485. string posTag = CurrentUser.UserPost.Post.Code;
  4486. if (posTag == "Supplier")
  4487. {
  4488. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4489. }
  4490. lw.Add(string.Format("OrderState = 6 "));
  4491. lw.Add(string.Format("type = 'JD' "));
  4492. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4493. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4494. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4495. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4496. writeGridDataTableJson(dStruct.TotalCount, dt);
  4497. }
  4498. public void get_erp_demoorderlist()
  4499. {
  4500. DataStruct dStruct = GetPostStruct();
  4501. List<string> lw = new List<string>();
  4502. string tid = GetPostString("ctid");
  4503. if (tid.Length > 0)
  4504. {
  4505. string select_tid = getTidByCtid(tid);
  4506. lw.Add(string.Format("tid='{0}'", select_tid));
  4507. }
  4508. string shopname = GetPostString("shopname");
  4509. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4510. string buyernick = GetPostString("buyer_nick");
  4511. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4512. string customer = GetPostString("customer");
  4513. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4514. string design = GetPostString("design");
  4515. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4516. string orderState = GetPostString("orderState");
  4517. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4518. string address = GetPostString("address");
  4519. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4520. string sellermemo = GetPostString("seller_memo");
  4521. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4522. string supplier = GetPostString("supplier");
  4523. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4524. string OrderArea = GetPostString("order_area");
  4525. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4526. string date1 = GetPostString("date1");
  4527. string date2 = GetPostString("date2");
  4528. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4529. if (dw.Length > 0) lw.Add(dw);
  4530. string price1 = GetPostString("price1");
  4531. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4532. string price2 = GetPostString("price2");
  4533. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4534. string posTag = CurrentUser.UserPost.Post.Code;
  4535. if (posTag == "Supplier")
  4536. {
  4537. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4538. }
  4539. //lw.Add(string.Format("OrderState = 6 "));
  4540. lw.Add(string.Format("IsSample={0}", 3));
  4541. lw.Add(string.Format("IsRefund<={0}", 1));
  4542. dStruct.Order = "pay_time desc";
  4543. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4544. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4545. writeGridDataTableJson(dStruct.TotalCount, dt);
  4546. }
  4547. public void save_erp_checkmemo()
  4548. {
  4549. if (UrlPostParmsCheck("ctid"))
  4550. {
  4551. string ctid = GetPostString("ctid");
  4552. CeErpTradeCell entity = null;
  4553. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4554. if (entity != null)
  4555. {
  4556. entity.CheckMemo = GetPostString("CheckMemo");
  4557. entity.Update();
  4558. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4559. if (trade != null)
  4560. {
  4561. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4562. }
  4563. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4564. returnSuccessMsg("保存成功!");
  4565. return;
  4566. }
  4567. returnErrorMsg("找不到记录");
  4568. }
  4569. }
  4570. public void get_erp_returnlist()
  4571. {
  4572. DataStruct dStruct = GetPostStruct();
  4573. List<string> lw = new List<string>();
  4574. string tid = GetPostString("ctid");
  4575. if (tid.Length > 0)
  4576. {
  4577. string select_tid = getTidByCtid(tid);
  4578. lw.Add(string.Format("tid='{0}'", select_tid));
  4579. }
  4580. string shopname = GetPostString("shopname");
  4581. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4582. string buyernick = GetPostString("buyer_nick");
  4583. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4584. string customer = GetPostString("customer");
  4585. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4586. string design = GetPostString("design");
  4587. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4588. string orderState = GetPostString("orderState");
  4589. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4590. string address = GetPostString("address");
  4591. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4592. string sellermemo = GetPostString("seller_memo");
  4593. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4594. string supplier = GetPostString("supplier");
  4595. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4596. string date1 = GetPostString("date1");
  4597. string date2 = GetPostString("date2");
  4598. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4599. if (dw.Length > 0) lw.Add(dw);
  4600. string bdate1 = GetPostString("backdate1");
  4601. string bdate2 = GetPostString("backdate2");
  4602. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4603. if (dw_back.Length > 0) lw.Add(dw_back);
  4604. string price1 = GetPostString("price1");
  4605. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4606. string price2 = GetPostString("price2");
  4607. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4608. lw.Add(string.Format("IsReturn>0"));
  4609. lw.Add(string.Format("IsXianHuo=0"));
  4610. lw.Add(string.Format("IsReturn!=3"));
  4611. string backtype = GetPostString("backtype");
  4612. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4613. dStruct.Order = "FinishDesignTime desc";
  4614. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4615. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4616. writeGridDataTableJson(dStruct.TotalCount, dt);
  4617. }
  4618. public void get_erp_today_sumreturn()
  4619. {
  4620. DataStruct dStruct = GetPostStruct();
  4621. List<string> lw = new List<string>();
  4622. string bdate1 = GetPostString("returnTimeS");
  4623. string bdate2 = GetPostString("returnTimeE");
  4624. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4625. if (dw_back.Length > 0) lw.Add(dw_back);
  4626. lw.Add(string.Format("IsReturn=0"));
  4627. lw.Add(string.Format("IsXianHuo=0"));
  4628. string mainWhere = string.Join(" and ", lw.ToArray());
  4629. string sql = "";
  4630. if (dw_back.Length > 0)
  4631. {
  4632. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4633. }
  4634. else
  4635. {
  4636. 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 + "'";
  4637. }
  4638. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4639. decimal total = 0, today_finish = 0;
  4640. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4641. {
  4642. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4643. }
  4644. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4645. {
  4646. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4647. }
  4648. var res = new
  4649. {
  4650. data = total,
  4651. data1 = today_finish,
  4652. };
  4653. string ro_jsond = JsonConvert.SerializeObject(res);
  4654. returnSuccess(ro_jsond);
  4655. return;
  4656. }
  4657. public void get_erp_allreturnlist()
  4658. {
  4659. DataStruct dStruct = GetPostStruct();
  4660. List<string> lw = new List<string>();
  4661. string tid = GetPostString("ctid");
  4662. if (tid.Length > 0)
  4663. {
  4664. string select_tid = getTidByCtid(tid);
  4665. lw.Add(string.Format("tid='{0}'", select_tid));
  4666. }
  4667. string shopname = GetPostString("shopname");
  4668. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4669. string buyernick = GetPostString("buyer_nick");
  4670. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4671. string customer = GetPostString("customer");
  4672. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4673. string design = GetPostString("design");
  4674. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4675. string orderState = GetPostString("orderState");
  4676. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4677. string address = GetPostString("address");
  4678. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4679. string sellermemo = GetPostString("seller_memo");
  4680. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4681. string supplier = GetPostString("supplier");
  4682. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4683. string date1 = GetPostString("date1");
  4684. string date2 = GetPostString("date2");
  4685. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4686. if (dw.Length > 0) lw.Add(dw);
  4687. string bdate1 = GetPostString("backdate1");
  4688. string bdate2 = GetPostString("backdate2");
  4689. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4690. if (dw_back.Length > 0) lw.Add(dw_back);
  4691. string price1 = GetPostString("price1");
  4692. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4693. string price2 = GetPostString("price2");
  4694. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4695. string backreason = GetPostString("backreason");
  4696. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4697. lw.Add(string.Format("IsXianHuo=0"));
  4698. lw.Add(string.Format("ReturnTime != ''"));
  4699. string backtype = GetPostString("backtype");
  4700. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4701. string posTag = CurrentUser.UserPost.Post.Code;
  4702. if (posTag == "Supplier")
  4703. {
  4704. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4705. }
  4706. else
  4707. {
  4708. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4709. {
  4710. string usershop = CurrentUser.User.pemShop;
  4711. lw.Add(string.Format("ShopId in ({0})", usershop));
  4712. }
  4713. }
  4714. dStruct.Order = "FinishDesignTime desc";
  4715. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4716. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4717. writeGridDataTableJson(dStruct.TotalCount, dt);
  4718. }
  4719. public void get_erp_aftersalereturnlist()
  4720. {
  4721. DataStruct dStruct = GetPostStruct();
  4722. List<string> lw = new List<string>();
  4723. string tid = GetPostString("ctid");
  4724. if (tid.Length > 0)
  4725. {
  4726. string select_tid = getTidByCtid(tid);
  4727. lw.Add(string.Format("tid='{0}'", select_tid));
  4728. }
  4729. string shopname = GetPostString("shopname");
  4730. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4731. string buyernick = GetPostString("buyer_nick");
  4732. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4733. string customer = GetPostString("customer");
  4734. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4735. string design = GetPostString("design");
  4736. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4737. string orderState = GetPostString("orderState");
  4738. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4739. string address = GetPostString("address");
  4740. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4741. string sellermemo = GetPostString("seller_memo");
  4742. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4743. string supplier = GetPostString("supplier");
  4744. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4745. string date1 = GetPostString("date1");
  4746. string date2 = GetPostString("date2");
  4747. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4748. if (dw.Length > 0) lw.Add(dw);
  4749. string bdate1 = GetPostString("backdate1");
  4750. string bdate2 = GetPostString("backdate2");
  4751. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4752. if (dw_back.Length > 0) lw.Add(dw_back);
  4753. string price1 = GetPostString("price1");
  4754. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4755. string price2 = GetPostString("price2");
  4756. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4757. lw.Add(string.Format("IsReturn=3"));
  4758. string backtype = GetPostString("backtype");
  4759. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4760. string backreason = GetPostString("backreason");
  4761. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4762. dStruct.Order = "ReturnTime desc";
  4763. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4764. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4765. writeGridDataTableJson(dStruct.TotalCount, dt);
  4766. }
  4767. public void get_erp_xianhuoreturnlist()
  4768. {
  4769. DataStruct dStruct = GetPostStruct();
  4770. List<string> lw = new List<string>();
  4771. string tid = GetPostString("ctid");
  4772. if (tid.Length > 0)
  4773. {
  4774. string select_tid = getTidByCtid(tid);
  4775. lw.Add(string.Format("tid='{0}'", select_tid));
  4776. }
  4777. string shopname = GetPostString("shopname");
  4778. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4779. string buyernick = GetPostString("buyer_nick");
  4780. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4781. string customer = GetPostString("customer");
  4782. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4783. string design = GetPostString("design");
  4784. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4785. string orderState = GetPostString("orderState");
  4786. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4787. string address = GetPostString("address");
  4788. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4789. string sellermemo = GetPostString("seller_memo");
  4790. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4791. string supplier = GetPostString("supplier");
  4792. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4793. string OrderArea = GetPostString("order_area");
  4794. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  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 price1 = GetPostString("price1");
  4800. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4801. string price2 = GetPostString("price2");
  4802. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4803. string posTag = CurrentUser.UserPost.Post.Code;
  4804. if (posTag == "Supplier")
  4805. {
  4806. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4807. }
  4808. lw.Add(string.Format("OrderState=6 "));
  4809. lw.Add(string.Format("IsXianHuo=1 "));
  4810. lw.Add(string.Format("IsReturn>0 "));
  4811. lw.Add(string.Format("IsReturn!=3"));
  4812. lw.Add(string.Format("IsRefund<={0}", 1));
  4813. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4814. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4815. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4816. writeGridDataTableJson(dStruct.TotalCount, dt);
  4817. }
  4818. public void set_erp_orderdelivery()
  4819. {
  4820. if (UrlPostParmsCheck("ctid"))
  4821. {
  4822. string eid = GetPostString("ctid");
  4823. CeErpTradeCell entity = null;
  4824. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4825. if (entity != null)
  4826. {
  4827. if (entity.OrderState >= 7)
  4828. {
  4829. returnErrorMsg("此单已发货,无需重复发货");
  4830. return;
  4831. }
  4832. if (entity.OrderState != 6)
  4833. {
  4834. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4835. return;
  4836. }
  4837. string shop = GetPostString("seller_nick");
  4838. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4839. string comName = GetPostString("comName");
  4840. string comCode = GetPostString("comCode");
  4841. string outSid = GetPostString("outSid");
  4842. string deliveryType = GetPostString("deliveryType");
  4843. string deliveryMemo = GetPostString("deliveryMemo");
  4844. outSid = outSid.Trim();
  4845. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4846. if (mainEn == null)
  4847. {
  4848. returnErrorMsg("找不到原始订单记录");
  4849. return;
  4850. }
  4851. bool isInitOrderDeliv = false;
  4852. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4853. {
  4854. isInitOrderDeliv = true;
  4855. }
  4856. string apires = "";
  4857. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4858. 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)
  4859. {
  4860. apires = "发货成功true";
  4861. }
  4862. else
  4863. {
  4864. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4865. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid, entity.ctid);
  4866. }
  4867. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4868. {
  4869. entity.OrderState = 7;//发货后订单已发货
  4870. entity.OutSid = outSid;
  4871. entity.MemoOpt = 0;
  4872. entity.UpdateTime = DateTime.Now;
  4873. entity.FinishDeliveryTime = DateTime.Now;
  4874. entity.Update();
  4875. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4876. commonHelper.UpdateRelationOrder(entity.ctid);
  4877. //还要插入快递信息到 快递信息表
  4878. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4879. exinfo.tid = eid;
  4880. exinfo.out_sid = outSid;
  4881. exinfo.company_code = comCode;
  4882. exinfo.company_name = comName;
  4883. exinfo.delivery_memo = deliveryMemo;
  4884. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4885. exinfo.deliveryType = deliveryType;
  4886. exinfo.printUser = CurrentUser.UserName;
  4887. exinfo.print_time = DateTime.Now;
  4888. exinfo.Create();
  4889. returnSuccessMsg("发货操作成功!");
  4890. commonHelper.UpdateRelationOrder(entity.ctid);
  4891. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4892. CeErpSukuraData.createInfo(entity.ctid, 4);
  4893. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  4894. {
  4895. commonHelper.sendCytExpress(exinfo);
  4896. }
  4897. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4898. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid + ",备注:" + deliveryMemo, entity.OrderState);
  4899. }
  4900. else
  4901. {
  4902. string errmsg = commonHelper.KeepChinese(apires);
  4903. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4904. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4905. }
  4906. return;
  4907. }
  4908. returnErrorMsg("找不到订单记录");
  4909. }
  4910. }
  4911. public void set_erp_multidelivery()
  4912. {
  4913. string eids = GetPostString("tids");
  4914. string[] eidList = eids.Split(',');
  4915. if (eidList.Length <= 0)
  4916. {
  4917. returnErrorMsg("发货不能为空");
  4918. return;
  4919. }
  4920. foreach (string ctid in eidList)
  4921. {
  4922. if (ctid.Length <= 0) continue;
  4923. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4924. if (expInfo != null)
  4925. {
  4926. StringBuilder sql = new StringBuilder();
  4927. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4928. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4929. if (dt.Rows.Count > 0)
  4930. {
  4931. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4932. {
  4933. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4934. expInfo.state = "异常";
  4935. expInfo.isMultiDelivery = 1;
  4936. expInfo.Update();
  4937. continue;
  4938. }
  4939. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4940. {
  4941. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4942. expInfo.state = "异常";
  4943. expInfo.Update();
  4944. continue;
  4945. }
  4946. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4947. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4948. bool isInitOrderDeliv = false;
  4949. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4950. {
  4951. isInitOrderDeliv = true;
  4952. expInfo.isMultiDelivery = 1;
  4953. }
  4954. if (ctid.IndexOf("N") != -1)
  4955. {
  4956. StringBuilder sqlbucha = new StringBuilder();
  4957. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4958. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4959. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4960. commonHelper.UpdateRelationOrder(ctid);
  4961. expInfo.delivery_memo = "发货成功";
  4962. expInfo.state = "发货成功";
  4963. expInfo.isMultiDelivery = 1;
  4964. expInfo.Update();
  4965. }
  4966. else
  4967. {
  4968. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4969. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid, ctid);
  4970. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4971. {
  4972. expInfo.delivery_memo = "发货成功";
  4973. expInfo.state = "发货成功";
  4974. expInfo.isMultiDelivery = 1;
  4975. expInfo.Update();
  4976. commonHelper.UpdateRelationOrder(ctid);
  4977. CeErpSukuraData.createInfo(ctid, 4);
  4978. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4979. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4980. }
  4981. else
  4982. {
  4983. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4984. expInfo.state = "异常";
  4985. expInfo.Update();
  4986. }
  4987. }
  4988. }
  4989. }
  4990. }
  4991. returnSuccessMsg("操作完成");
  4992. }
  4993. public void reset_erp_memoopt()
  4994. {
  4995. if (UrlPostParmsCheck("ctid"))
  4996. {
  4997. string eid = GetPostString("ctid");
  4998. CeErpTradeCell entity = null;
  4999. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5000. if (entity != null)
  5001. {
  5002. string stropt = "";
  5003. if (entity.MemoOpt == 1)
  5004. {
  5005. stropt = "“改稿”";
  5006. }
  5007. else if (entity.MemoOpt == 2)
  5008. {
  5009. stropt = "“定稿”";
  5010. }
  5011. else if (entity.MemoOpt == 3)
  5012. {
  5013. stropt = "“完成查货”";
  5014. CeErpSukuraData.createInfo(entity.ctid, 6);
  5015. }
  5016. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  5017. entity.UpdateTime = DateTime.Now;
  5018. entity.MemoOpt = 0;
  5019. entity.Update();
  5020. returnSuccessMsg("操作成功!");
  5021. return;
  5022. }
  5023. returnErrorMsg("找不到记录");
  5024. }
  5025. }
  5026. public void get_erp_deliveryunusual()
  5027. {
  5028. DataStruct dStruct = GetPostStruct();
  5029. List<string> lw = new List<string>();
  5030. string tid = GetPostString("ctid");
  5031. if (tid.Length > 0)
  5032. {
  5033. string select_tid = getTidByCtid(tid);
  5034. lw.Add(string.Format("tid='{0}'", select_tid));
  5035. }
  5036. string shopname = GetPostString("shopname");
  5037. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5038. string buyernick = GetPostString("buyer_nick");
  5039. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5040. string customer = GetPostString("customer");
  5041. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5042. string design = GetPostString("design");
  5043. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5044. string sellermemo = GetPostString("seller_memo");
  5045. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5046. string supplier = GetPostString("supplier");
  5047. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5048. string date1 = GetPostString("date1");
  5049. string date2 = GetPostString("date2");
  5050. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5051. if (dw.Length > 0) lw.Add(dw);
  5052. string placedate1 = GetPostString("placedate1");
  5053. string placedate2 = GetPostString("placedate2");
  5054. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5055. if (dw_place.Length > 0) lw.Add(dw_place);
  5056. string price1 = GetPostString("price1");
  5057. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5058. string price2 = GetPostString("price2");
  5059. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5060. string unusualCon = GetPostString("unusualcon");
  5061. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  5062. string posTag = CurrentUser.UserPost.Post.Code;
  5063. if (posTag == "Supplier")
  5064. {
  5065. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5066. }
  5067. lw.Add(string.Format("OrderState = 6"));
  5068. lw.Add(string.Format("UnusualTag = 5"));
  5069. lw.Add(string.Format("IsRefund<={0}", 1));
  5070. dStruct.Order = "FinishPlaceTime desc";
  5071. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5072. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5073. writeGridDataTableJson(dStruct.TotalCount, dt);
  5074. }
  5075. public void get_erp_deliveryedlist()
  5076. {
  5077. DataStruct dStruct = GetPostStruct();
  5078. List<string> lw = new List<string>();
  5079. string tid = GetPostString("ctid");
  5080. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5081. string shopname = GetPostString("shopname");
  5082. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5083. string buyernick = GetPostString("buyer_nick");
  5084. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5085. string customer = GetPostString("customer");
  5086. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5087. string design = GetPostString("design");
  5088. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5089. string sellermemo = GetPostString("seller_memo");
  5090. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5091. string logistics = GetPostString("logistics");
  5092. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5093. string date1 = GetPostString("date1");
  5094. string date2 = GetPostString("date2");
  5095. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5096. //if (dw.Length > 0) lw.Add(dw);
  5097. string placedate1 = GetPostString("placedate1");
  5098. string placedate2 = GetPostString("placedate2");
  5099. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5100. if (fdw.Length > 0) lw.Add(fdw);
  5101. string devdate1 = GetPostString("deliverydate1");
  5102. string devdate2 = GetPostString("deliverydate2");
  5103. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5104. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5105. string price1 = GetPostString("price1");
  5106. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5107. string price2 = GetPostString("price2");
  5108. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5109. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5110. {
  5111. if (tid.Length > 0)
  5112. {
  5113. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5114. if (tid.Length > 5)
  5115. {
  5116. List<string> tids = getTidByCtidLike(tid);
  5117. if (tids.Count > 0 && tids.Count < 10)
  5118. {
  5119. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5120. }
  5121. }
  5122. lw.Add(tid_sql);
  5123. }
  5124. if (buyernick.Length > 0)
  5125. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5126. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5127. if (dw.Length > 0) lw.Add(dw);
  5128. }
  5129. else
  5130. {
  5131. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  5132. }
  5133. string posTag = CurrentUser.UserPost.Post.Code;
  5134. if (posTag == "Supplier")
  5135. {
  5136. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5137. }
  5138. else
  5139. {
  5140. string supplier = GetPostString("supplier");
  5141. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5142. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  5143. {
  5144. string usershop = CurrentUser.User.pemShop;
  5145. lw.Add(string.Format("ShopId in ({0})", usershop));
  5146. }
  5147. }
  5148. lw.Add(string.Format(" OrderState IN (7, 8)"));
  5149. lw.Add(string.Format("type != 'PDD' "));
  5150. lw.Add(string.Format("IsRefund!={0}", 2));
  5151. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5152. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5153. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5154. /*if (tid.Length > 0)
  5155. {
  5156. List<string> tids = new List<string>();
  5157. if (dt != null && dt.Rows.Count > 0)
  5158. {
  5159. foreach (DataRow item in dt.Rows)
  5160. {
  5161. tids.Add("'" + item["tid"] + "'");
  5162. }
  5163. }
  5164. if (tids.Count > 0)
  5165. {
  5166. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5167. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5168. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5169. dt = WebCache.GetData("view_erptradecell", dStruct);
  5170. }
  5171. }*/
  5172. if (dt != null)
  5173. {
  5174. foreach (DataRow dr in dt.Rows)
  5175. {
  5176. 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();
  5177. }
  5178. }
  5179. writeGridDataTableJson(dStruct.TotalCount, dt);
  5180. }
  5181. public void get_erp_pdddeliveryed()
  5182. {
  5183. DataStruct dStruct = GetPostStruct();
  5184. List<string> lw = new List<string>();
  5185. string tid = GetPostString("ctid");
  5186. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5187. string shopname = GetPostString("shopname");
  5188. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5189. string buyernick = GetPostString("buyer_nick");
  5190. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5191. string customer = GetPostString("customer");
  5192. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5193. string design = GetPostString("design");
  5194. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5195. string sellermemo = GetPostString("seller_memo");
  5196. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5197. string logistics = GetPostString("logistics");
  5198. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5199. string date1 = GetPostString("date1");
  5200. string date2 = GetPostString("date2");
  5201. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5202. //if (dw.Length > 0) lw.Add(dw);
  5203. string placedate1 = GetPostString("placedate1");
  5204. string placedate2 = GetPostString("placedate2");
  5205. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5206. if (fdw.Length > 0) lw.Add(fdw);
  5207. string devdate1 = GetPostString("deliverydate1");
  5208. string devdate2 = GetPostString("deliverydate2");
  5209. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5210. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5211. string price1 = GetPostString("price1");
  5212. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5213. string price2 = GetPostString("price2");
  5214. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5215. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5216. {
  5217. if (tid.Length > 0)
  5218. {
  5219. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5220. if (tid.Length > 5)
  5221. {
  5222. List<string> tids = getTidByCtidLike(tid);
  5223. if (tids.Count > 0 && tids.Count < 10)
  5224. {
  5225. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5226. }
  5227. }
  5228. lw.Add(tid_sql);
  5229. }
  5230. if (buyernick.Length > 0)
  5231. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5232. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5233. if (dw.Length > 0) lw.Add(dw);
  5234. }
  5235. else
  5236. {
  5237. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5238. }
  5239. string posTag = CurrentUser.UserPost.Post.Code;
  5240. if (posTag == "Supplier")
  5241. {
  5242. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5243. }
  5244. else
  5245. {
  5246. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  5247. {
  5248. string usershop = CurrentUser.User.pemShop;
  5249. lw.Add(string.Format("ShopId in ({0})", usershop));
  5250. }
  5251. string supplier = GetPostString("supplier");
  5252. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5253. }
  5254. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5255. lw.Add(string.Format("type = 'PDD' "));
  5256. lw.Add(string.Format("IsRefund!={0}", 2));
  5257. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5258. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5259. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5260. /* if (tid.Length > 0)
  5261. {
  5262. List<string> tids = new List<string>();
  5263. if (dt != null && dt.Rows.Count > 0)
  5264. {
  5265. foreach (DataRow item in dt.Rows)
  5266. {
  5267. tids.Add("'" + item["tid"] + "'");
  5268. }
  5269. }
  5270. if (tids.Count > 0)
  5271. {
  5272. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5273. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5274. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5275. dt = WebCache.GetData("view_erptradecell", dStruct);
  5276. }
  5277. }*/
  5278. foreach (DataRow dr in dt.Rows)
  5279. {
  5280. 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();
  5281. }
  5282. writeGridDataTableJson(dStruct.TotalCount, dt);
  5283. }
  5284. public void get_erp_jddeliveryed()
  5285. {
  5286. DataStruct dStruct = GetPostStruct();
  5287. List<string> lw = new List<string>();
  5288. string tid = GetPostString("ctid");
  5289. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5290. string shopname = GetPostString("shopname");
  5291. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5292. string buyernick = GetPostString("buyer_nick");
  5293. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5294. string customer = GetPostString("customer");
  5295. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5296. string design = GetPostString("design");
  5297. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5298. string sellermemo = GetPostString("seller_memo");
  5299. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5300. string date1 = GetPostString("date1");
  5301. string date2 = GetPostString("date2");
  5302. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5303. //if (dw.Length > 0) lw.Add(dw);
  5304. string placedate1 = GetPostString("placedate1");
  5305. string placedate2 = GetPostString("placedate2");
  5306. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5307. if (fdw.Length > 0) lw.Add(fdw);
  5308. string devdate1 = GetPostString("deliverydate1");
  5309. string devdate2 = GetPostString("deliverydate2");
  5310. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5311. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5312. string price1 = GetPostString("price1");
  5313. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5314. string price2 = GetPostString("price2");
  5315. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5316. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5317. {
  5318. if (tid.Length > 0)
  5319. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5320. if (buyernick.Length > 0)
  5321. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5322. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5323. if (dw.Length > 0) lw.Add(dw);
  5324. }
  5325. else
  5326. {
  5327. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5328. }
  5329. string posTag = CurrentUser.UserPost.Post.Code;
  5330. if (posTag == "Supplier")
  5331. {
  5332. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5333. }
  5334. else
  5335. {
  5336. string supplier = GetPostString("supplier");
  5337. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5338. }
  5339. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5340. lw.Add(string.Format("type = 'JD' "));
  5341. lw.Add(string.Format("IsRefund!={0}", 2));
  5342. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5343. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5344. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5345. foreach (DataRow dr in dt.Rows)
  5346. {
  5347. 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();
  5348. }
  5349. writeGridDataTableJson(dStruct.TotalCount, dt);
  5350. }
  5351. public void get_erp_allplacelist()
  5352. {
  5353. DataStruct dStruct = GetPostStruct();
  5354. List<string> lw = new List<string>();
  5355. string tid = GetPostString("ctid");
  5356. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5357. string shopname = GetPostString("shopname");
  5358. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5359. string buyernick = GetPostString("buyer_nick");
  5360. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5361. string customer = GetPostString("customer");
  5362. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5363. string design = GetPostString("design");
  5364. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5365. string sellermemo = GetPostString("seller_memo");
  5366. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5367. string supplier = GetPostString("supplier");
  5368. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5369. string date1 = GetPostString("date1");
  5370. string date2 = GetPostString("date2");
  5371. string pldate1 = GetPostString("placedate1");
  5372. string pldate2 = GetPostString("placedate2");
  5373. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5374. //if (dw.Length > 0) lw.Add(dw);
  5375. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5376. {
  5377. if (tid.Length > 0)
  5378. {
  5379. string select_tid = getTidByCtid(tid);
  5380. lw.Add(string.Format("tid='{0}'", select_tid));
  5381. }
  5382. if (buyernick.Length > 0)
  5383. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5384. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5385. if (dw.Length > 0) lw.Add(dw);
  5386. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5387. if (dw_place.Length > 0) lw.Add(dw_place);
  5388. }
  5389. else
  5390. {
  5391. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5392. {
  5393. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5394. }
  5395. }
  5396. string price1 = GetPostString("price1");
  5397. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5398. string price2 = GetPostString("price2");
  5399. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5400. string posTag = CurrentUser.UserPost.Post.Code;
  5401. if (posTag == "Supplier")
  5402. {
  5403. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5404. }
  5405. lw.Add(string.Format("OrderState >= 6"));
  5406. lw.Add(string.Format("IsSample != 2 "));
  5407. //lw.Add(string.Format("isDianziOrder = 0 "));
  5408. lw.Add(string.Format("SupplierId > 0 "));
  5409. //lw.Add(string.Format("IsRefund<={0}", 1));
  5410. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5411. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5412. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5413. foreach (DataRow dr in dt.Rows)
  5414. {
  5415. 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();
  5416. }
  5417. writeGridDataTableJson(dStruct.TotalCount, dt);
  5418. }
  5419. public void get_erp_financeallplacelist()
  5420. {
  5421. DataStruct dStruct = GetPostStruct();
  5422. List<string> lw = new List<string>();
  5423. string tid = GetPostString("ctid");
  5424. string shopname = GetPostString("shopname");
  5425. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5426. string buyernick = GetPostString("buyer_nick");
  5427. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5428. string customer = GetPostString("customer");
  5429. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5430. string design = GetPostString("design");
  5431. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5432. string sellermemo = GetPostString("seller_memo");
  5433. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5434. string supplier = GetPostString("supplier");
  5435. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5436. string date1 = GetPostString("date1");
  5437. string date2 = GetPostString("date2");
  5438. string pldate1 = GetPostString("placedate1");
  5439. string pldate2 = GetPostString("placedate2");
  5440. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5441. {
  5442. if (tid.Length > 0)
  5443. {
  5444. string select_tid = getTidByCtid(tid);
  5445. lw.Add(string.Format("tid='{0}'", select_tid));
  5446. }
  5447. if (buyernick.Length > 0)
  5448. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5449. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5450. if (dw.Length > 0) lw.Add(dw);
  5451. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5452. if (dw_place.Length > 0) lw.Add(dw_place);
  5453. }
  5454. else
  5455. {
  5456. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5457. {
  5458. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5459. }
  5460. }
  5461. string price1 = GetPostString("price1");
  5462. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5463. string price2 = GetPostString("price2");
  5464. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5465. string posTag = CurrentUser.UserPost.Post.Code;
  5466. if (posTag == "Supplier")
  5467. {
  5468. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5469. }
  5470. //lw.Add(string.Format("OrderState >= 6"));
  5471. lw.Add(string.Format("IsSample != 2 "));
  5472. lw.Add(string.Format("isDianziOrder = 0 "));
  5473. //lw.Add(string.Format("IsRefund<={0}", 1));
  5474. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5475. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5476. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5477. foreach (DataRow dr in dt.Rows)
  5478. {
  5479. 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();
  5480. }
  5481. writeGridDataTableJson(dStruct.TotalCount, dt);
  5482. }
  5483. public void get_erp_expresslist()
  5484. {
  5485. int listtype = GetInt("ltype");
  5486. DataStruct dStruct = GetPostStruct();
  5487. List<string> lw = new List<string>();
  5488. string tid = GetPostString("tid");
  5489. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5490. string outsid = GetPostString("out_sid");
  5491. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5492. string importer = GetPostString("ImportUserName");
  5493. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5494. string file = GetPostString("import_file");
  5495. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5496. string printman = GetPostString("printman");
  5497. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5498. string date1 = GetPostString("date1");
  5499. string date2 = GetPostString("date2");
  5500. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5501. if (dw.Length > 0) lw.Add(dw);
  5502. string fdate1 = GetPostString("finishdate1");
  5503. string fdate2 = GetPostString("finishdate2");
  5504. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5505. if (fdw.Length > 0) lw.Add(fdw);
  5506. string supplierId = GetPostString("supplierId");
  5507. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5508. if (listtype == 1)
  5509. {
  5510. lw.Add(string.Format("importUserId !=0"));
  5511. }
  5512. string posTag = CurrentUser.UserPost.Post.Code;
  5513. if (posTag == "Supplier")
  5514. {
  5515. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5516. }
  5517. if (dStruct.PageSize != 100000)
  5518. {
  5519. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5520. }
  5521. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5522. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5523. writeGridDataTableJson(dStruct.TotalCount, dt);
  5524. }
  5525. public void set_erp_buchaorderdelivery()
  5526. {
  5527. if (UrlPostParmsCheck("ctid"))
  5528. {
  5529. string eid = GetPostString("ctid");
  5530. CeErpTradeCell entity = null;
  5531. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5532. if (entity != null)
  5533. {
  5534. if (entity.IsSample != 2)
  5535. {
  5536. returnErrorMsg("补差价单才能标记为已发货");
  5537. return;
  5538. }
  5539. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5540. entity.OrderState = 7;
  5541. entity.Update();
  5542. returnSuccessMsg("操作成功!");
  5543. return;
  5544. }
  5545. returnErrorMsg("找不到记录");
  5546. }
  5547. }
  5548. public void get_stdtemplates()
  5549. {
  5550. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5551. //string res = taobaoHelper.test();
  5552. string res = apiHelper.API_PrintTemplate();
  5553. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5554. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5555. {
  5556. int sidx = res.IndexOf("error_code");
  5557. int eidx = res.IndexOf("success");
  5558. string msg = res.Substring(sidx, eidx - sidx);
  5559. returnErrorMsg(msg);
  5560. return;
  5561. }
  5562. if (res.Length <= 0)
  5563. {
  5564. returnErrorMsg("模板数据为空!");
  5565. return;
  5566. }
  5567. ReturnSuccess(res);
  5568. }
  5569. public void cancel_print_order()
  5570. {
  5571. if (UrlPostParmsCheck("ctid"))
  5572. {
  5573. string ctid = GetPostString("ctid");
  5574. CeErpTradeCell entity = null;
  5575. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5576. if (entity != null)
  5577. {
  5578. string res = "";
  5579. string code = entity.LastBillWaybillCode;
  5580. if (code == "")
  5581. {
  5582. code = entity.OutSid;
  5583. }
  5584. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5585. XLog.SaveLog(0, "取消面单" + res);
  5586. }
  5587. }
  5588. }
  5589. public void set_erp_printwaybill()
  5590. {
  5591. if (UrlPostParmsCheck("ctid"))
  5592. {
  5593. string ctid = GetPostString("ctid");
  5594. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5595. string cpName = GetPostString("cpname");
  5596. string isTogether = GetPostString("together");
  5597. string printType = GetPostString("printType");
  5598. //var res_obj = new
  5599. //{
  5600. // restype = 1,
  5601. // 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\"}"
  5602. //};
  5603. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5604. //ReturnSuccess(ro_json);
  5605. //return;
  5606. bool isUseLastWayBillCode = false;
  5607. CeErpTradeCell entity = null;
  5608. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5609. if (entity != null)
  5610. {
  5611. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5612. {
  5613. isUseLastWayBillCode = true;
  5614. }
  5615. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5616. {
  5617. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5618. return;
  5619. }
  5620. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5621. {
  5622. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5623. return;
  5624. }
  5625. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5626. {
  5627. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5628. return;
  5629. }
  5630. }
  5631. string res = "";
  5632. Api_waybill_code_response_Obj fullObj = null;
  5633. string pData_str = "";
  5634. string curUseWayBillCode = "";
  5635. if (isUseLastWayBillCode == false)
  5636. {
  5637. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5638. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5639. if (res.IndexOf("failure") != -1)
  5640. {
  5641. //int idx = res.IndexOf("sub_message");
  5642. //int idx2 = res.IndexOf("flag");
  5643. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5644. string errMsgNeed = commonHelper.KeepChinese(res);
  5645. var res_objd = new
  5646. {
  5647. restype = 0,
  5648. data = "获取面单失败" + errMsgNeed
  5649. };
  5650. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5651. returnSuccess(ro_jsond);
  5652. if (res.IndexOf("停发") != -1)
  5653. {
  5654. entity.UnusualCon = "物流停发";
  5655. entity.Update();
  5656. }
  5657. //returnErrorMsg("获取面单失败,"+emsg);
  5658. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5659. return;
  5660. }
  5661. else if (res.IndexOf("errorMsg") != -1)
  5662. {
  5663. //int idx = res.IndexOf("errorMsg");
  5664. //int idx2 = res.IndexOf("}]}");
  5665. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5666. string errMsgNeed = commonHelper.KeepChinese(res);
  5667. var res_objf = new
  5668. {
  5669. restype = 0,
  5670. data = "获取面单失败2" + errMsgNeed
  5671. };
  5672. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5673. if (res.IndexOf("停发") != -1)
  5674. {
  5675. entity.UnusualCon = "物流停发";
  5676. entity.Update();
  5677. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5678. if (trade != null)
  5679. {
  5680. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5681. }
  5682. }
  5683. returnSuccess(ro_jsonf);
  5684. //returnErrorMsg("获取面单失败," + emsg);
  5685. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5686. return;
  5687. }
  5688. try
  5689. {
  5690. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5691. //res = res.Replace(" ", "");
  5692. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5693. }
  5694. catch (Exception ex)
  5695. {
  5696. XLog.SaveLog(0, "生成fullObj" + res);
  5697. var res_objf = new
  5698. {
  5699. restype = 0,
  5700. data = "生成fullObj发生错误" + ex.Message
  5701. };
  5702. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5703. returnSuccess(ro_jsonf);
  5704. return;
  5705. }
  5706. if (fullObj.response.data.content.Count > 0)
  5707. {
  5708. ContentItem codeObj = fullObj.response.data.content[0];
  5709. if (cpCode.IndexOf("SFFQ-") != -1)
  5710. {
  5711. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5712. }
  5713. else
  5714. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5715. curUseWayBillCode = codeObj.waybillCode;
  5716. }
  5717. else
  5718. {
  5719. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5720. var res_objf = new
  5721. {
  5722. restype = 0,
  5723. data = "生成fullObj找不到快递单号waybillCode"
  5724. };
  5725. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5726. returnSuccess(ro_jsonf);
  5727. return;
  5728. }
  5729. }
  5730. else
  5731. {
  5732. //使用上次打印的快递单号
  5733. if (cpCode == "SFFQ-LY")
  5734. {
  5735. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5736. }
  5737. else
  5738. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5739. curUseWayBillCode = entity.LastBillWaybillCode;
  5740. }
  5741. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5742. {
  5743. var res_obje = new
  5744. {
  5745. restype = 0,
  5746. data = "获取加密打印数据失败"
  5747. };
  5748. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5749. returnSuccess(ro_jsone);
  5750. entity.LastBillCpCode = cpCode;
  5751. entity.LastBillWaybillCode = curUseWayBillCode;
  5752. entity.Update();
  5753. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5754. //returnErrorMsg("获取加密打印数据失败");
  5755. return;
  5756. }
  5757. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5758. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5759. string btnType = "";
  5760. string errorMsg = "";
  5761. if (entity != null)
  5762. {
  5763. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5764. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5765. //cpcode是 YTO-CAINIAO
  5766. //string comCode = cpCode.Split('-')[0].ToString();
  5767. string apires = "";
  5768. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5769. //isTogether=2是新的合包弹窗
  5770. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5771. {
  5772. if (ctid.IndexOf("N") != -1)
  5773. {
  5774. apires = "发货成功";
  5775. }
  5776. else
  5777. {
  5778. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode, entity.ctid);
  5779. }
  5780. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5781. //打单后发货
  5782. StringBuilder sql = new StringBuilder();
  5783. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5784. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5785. {
  5786. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5787. }
  5788. else
  5789. {
  5790. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5791. }
  5792. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5793. foreach (DataRow row in dt.Rows)
  5794. {
  5795. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5796. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5797. {
  5798. try
  5799. {
  5800. btnType = "待发货";
  5801. entity.OutSid = curUseWayBillCode;
  5802. entity.OrderState = 7;
  5803. entity.IsUrgency = false;
  5804. entity.LastBillCpCode = "";
  5805. entity.LastBillWaybillCode = "";
  5806. entity.FinishDeliveryTime = DateTime.Now;
  5807. entity.IsReturn = 0;
  5808. entity.MemoOpt = 0;
  5809. entity.UpdateTime = DateTime.Now;
  5810. entity.Update();
  5811. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5812. //还要插入快递信息到 快递信息表
  5813. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5814. exinfo.tid = entity.ctid;
  5815. exinfo.out_sid = curUseWayBillCode;
  5816. exinfo.company_code = cpCode;
  5817. exinfo.company_name = cpName;
  5818. exinfo.supplierUserName = supplierName;
  5819. exinfo.deliveryType = "发货成功";
  5820. exinfo.print_time = DateTime.Now;
  5821. exinfo.printUser = CurrentUser.UserName;
  5822. exinfo.postData = pData_str;
  5823. exinfo.Create();
  5824. commonHelper.UpdateRelationOrder(entity.ctid);
  5825. CeErpSukuraData.createInfo(ctid, 4);
  5826. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5827. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  5828. {
  5829. commonHelper.sendCytExpress(exinfo);
  5830. }
  5831. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5832. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5833. }
  5834. catch (Exception ex)
  5835. {
  5836. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5837. }
  5838. }
  5839. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5840. {
  5841. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5842. if (entity.OrderState == 6)
  5843. {
  5844. entity.OrderState = 7;
  5845. }
  5846. entity.UpdateTime = DateTime.Now;
  5847. entity.FinishDeliveryTime = DateTime.Now;
  5848. btnType = "已发货";
  5849. entity.Update();
  5850. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5851. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5852. exinfo.tid = entity.ctid;
  5853. exinfo.out_sid = curUseWayBillCode;
  5854. exinfo.company_code = cpCode;
  5855. exinfo.company_name = cpName;
  5856. exinfo.supplierUserName = supplierName;
  5857. exinfo.deliveryType = "发货成功";
  5858. exinfo.print_time = DateTime.Now;
  5859. exinfo.printUser = CurrentUser.UserName;
  5860. exinfo.postData = pData_str;
  5861. exinfo.Create();
  5862. commonHelper.UpdateRelationOrder(entity.ctid);
  5863. CeErpSukuraData.createInfo(entity.ctid, 4);
  5864. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  5865. {
  5866. commonHelper.sendCytExpress(exinfo);
  5867. }
  5868. //不处理
  5869. }
  5870. else
  5871. {
  5872. entity.UpdateTime = DateTime.Now;
  5873. entity.LastBillCpCode = cpCode;
  5874. entity.LastBillWaybillCode = curUseWayBillCode;
  5875. entity.Update();
  5876. string errmsg = commonHelper.KeepChinese(apires);
  5877. var res_objz = new
  5878. {
  5879. restype = 0,
  5880. data = "打单后发货失败"
  5881. };
  5882. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5883. returnSuccess(ro_jsonz);
  5884. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5885. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5886. return;
  5887. }
  5888. }
  5889. }
  5890. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5891. {
  5892. string ctids = GetPostString("ctids");
  5893. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5894. List<string> list = new List<string>();
  5895. List<string> send_list = new List<string>();
  5896. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5897. CeErpTrade ceErpTrade = new CeErpTrade();
  5898. //可合包的合并一起发货
  5899. if (dt == null && string.IsNullOrEmpty(ctids))
  5900. {
  5901. var res_objz = new
  5902. {
  5903. restype = 0,
  5904. data = "打单后发货失败"
  5905. };
  5906. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5907. returnSuccess(ro_jsonz);
  5908. return;
  5909. }
  5910. if (!string.IsNullOrEmpty(ctids))
  5911. {
  5912. StringBuilder sql = new StringBuilder();
  5913. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5914. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5915. }
  5916. foreach (DataRow row in dt.Rows)
  5917. {
  5918. list.Add("'" + row["ctid"] + "'");
  5919. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5920. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5921. if (ctid.IndexOf("N") != -1)
  5922. {
  5923. apires = "发货成功";
  5924. }
  5925. else
  5926. {
  5927. if (!send_list.Contains(ceErpTrade.tid))
  5928. {
  5929. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode, ctid);
  5930. }
  5931. else
  5932. {
  5933. apires = "发货成功";
  5934. }
  5935. }
  5936. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5937. {
  5938. send_list.Add(ceErpTrade.tid);
  5939. try
  5940. {
  5941. btnType = "待发货";
  5942. ceErpTradeCell.OutSid = curUseWayBillCode;
  5943. ceErpTradeCell.OrderState = 7;
  5944. ceErpTradeCell.IsUrgency = false;
  5945. ceErpTradeCell.LastBillCpCode = "";
  5946. ceErpTradeCell.LastBillWaybillCode = "";
  5947. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5948. ceErpTradeCell.IsReturn = 0;
  5949. ceErpTradeCell.MemoOpt = 0;
  5950. ceErpTradeCell.UpdateTime = DateTime.Now;
  5951. ceErpTradeCell.Update();
  5952. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5953. //还要插入快递信息到 快递信息表
  5954. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5955. exinfo.tid = ceErpTradeCell.ctid;
  5956. exinfo.out_sid = curUseWayBillCode;
  5957. exinfo.company_code = cpCode;
  5958. exinfo.company_name = cpName;
  5959. exinfo.supplierUserName = supplierName;
  5960. exinfo.deliveryType = "发货成功";
  5961. exinfo.print_time = DateTime.Now;
  5962. exinfo.printUser = CurrentUser.UserName;
  5963. exinfo.postData = pData_str;
  5964. exinfo.Create();
  5965. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5966. CeErpSukuraData.createInfo(ctid, 4);
  5967. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5968. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80 || entity.SupplierId == 126)
  5969. {
  5970. commonHelper.sendCytExpress(exinfo);
  5971. }
  5972. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5973. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5974. }
  5975. catch (Exception ex)
  5976. {
  5977. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5978. }
  5979. }
  5980. else
  5981. {
  5982. ceErpTradeCell.UpdateTime = DateTime.Now;
  5983. ceErpTradeCell.LastBillCpCode = cpCode;
  5984. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5985. ceErpTradeCell.Update();
  5986. string errmsg = commonHelper.KeepChinese(apires);
  5987. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5988. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5989. }
  5990. }
  5991. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5992. }
  5993. }
  5994. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5995. var res_obj = new
  5996. {
  5997. restype = 1,
  5998. data = pData_str,
  5999. errorMsg
  6000. };
  6001. string ro_json = JsonConvert.SerializeObject(res_obj);
  6002. ReturnSuccess(ro_json);
  6003. return;
  6004. }
  6005. }
  6006. private string GetUTF8String(byte[] vs)
  6007. {
  6008. throw new NotImplementedException();
  6009. }
  6010. public void set_erp_printwaybill_cn()
  6011. {
  6012. if (UrlPostParmsCheck("ctid"))
  6013. {
  6014. string ctid = GetPostString("ctid");
  6015. string cpCode = GetPostString("cpcode");
  6016. string cpName = GetPostString("cpname");
  6017. string tempUrl = GetPostString("tempurl");
  6018. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6019. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  6020. //string res = taobaoHelper.test();
  6021. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6022. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  6023. {
  6024. int sidx = res.IndexOf("errorMsg");
  6025. int eidx = res.IndexOf("}");
  6026. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  6027. var res_objzxx = new
  6028. {
  6029. restype = 0,
  6030. data = msg
  6031. };
  6032. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  6033. returnSuccess(ro_jsonzxx);
  6034. //returnErrorMsg(msg);
  6035. return;
  6036. }
  6037. int idx = res.IndexOf("waybillCode");
  6038. int idx2 = res.IndexOf("printData");
  6039. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  6040. string eid = GetPostString("ctid");
  6041. CeErpTradeCell entity = null;
  6042. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6043. if (entity != null)
  6044. {
  6045. string osid = entity.OutSid;
  6046. entity.OutSid = osid + "," + outsid;
  6047. entity.FinishDeliveryTime = DateTime.Now;
  6048. entity.OrderState = 7;
  6049. entity.UpdateTime = DateTime.Now;
  6050. entity.IsReturn = 0;
  6051. entity.Update();
  6052. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  6053. exinfo.tid = entity.ctid;
  6054. exinfo.out_sid = outsid;
  6055. exinfo.company_code = cpCode;
  6056. exinfo.company_name = cpName;
  6057. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  6058. exinfo.deliveryType = "发货成功";
  6059. exinfo.print_time = DateTime.Now;
  6060. exinfo.printUser = CurrentUser.UserName;
  6061. exinfo.Create();
  6062. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  6063. {
  6064. commonHelper.sendCytExpress(exinfo);
  6065. }
  6066. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  6067. }
  6068. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  6069. var res_objz = new
  6070. {
  6071. restype = 1,
  6072. data = res
  6073. };
  6074. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  6075. returnSuccess(ro_jsonz);
  6076. //ReturnSuccess(res);
  6077. }
  6078. }
  6079. ////打单,打印面单 获取面单号
  6080. //public void set_erp_printwaybill()
  6081. //{
  6082. // if (UrlPostParmsCheck("ctid"))
  6083. // {
  6084. // string ctid = GetPostString("ctid");
  6085. // string cpCode = GetPostString("cpcode");
  6086. // string tempUrl = GetPostString("tempurl");
  6087. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6088. // //string res = taobaoHelper.test();
  6089. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6090. // if (res.IndexOf("error_response") != -1)
  6091. // {
  6092. // int sidx = res.IndexOf("sub_msg");
  6093. // int eidx = res.IndexOf("request_id");
  6094. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  6095. // returnErrorMsg(msg);
  6096. // return;
  6097. // }
  6098. // int idx = res.IndexOf("waybill_code");
  6099. // int idx2 = res.IndexOf("}]}");
  6100. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  6101. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  6102. // ReturnSuccess(res);
  6103. // }
  6104. //}
  6105. public void cancel_erp_aftersale()
  6106. {
  6107. if (UrlPostParmsCheck("ctid"))
  6108. {
  6109. string eid = GetPostString("ctid");
  6110. CeErpTradeCell entity = null;
  6111. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6112. if (entity != null)
  6113. {
  6114. //有过处理的售后,取消也不能删除 售 字,保留
  6115. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  6116. {
  6117. entity.AfterSaleState = 4;
  6118. }
  6119. else
  6120. entity.AfterSaleState = 0;
  6121. entity.UpdateTime = DateTime.Now;
  6122. entity.Update();
  6123. returnSuccessMsg("操作成功!");
  6124. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  6125. return;
  6126. }
  6127. returnErrorMsg("找不到订单记录");
  6128. }
  6129. }
  6130. public void get_erp_aftersalelist()
  6131. {
  6132. DataStruct dStruct = GetPostStruct();
  6133. List<string> lw = new List<string>();
  6134. int st = GetInt("st");
  6135. string tid = GetPostString("ctid");
  6136. if (st == 3)
  6137. {
  6138. if (tid.Length > 0)
  6139. {
  6140. string select_tid = getTidByCtid(tid);
  6141. lw.Add(string.Format("tid='{0}'", select_tid));
  6142. }
  6143. }
  6144. else
  6145. {
  6146. if (tid.Length > 0)
  6147. {
  6148. string select_tid = getTidByCtid(tid);
  6149. lw.Add(string.Format("tid='{0}'", select_tid));
  6150. }
  6151. }
  6152. string shopname = GetPostString("shopname");
  6153. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6154. string buyernick = GetPostString("buyer_nick");
  6155. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  6156. string sellermemo = GetPostString("seller_memo");
  6157. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6158. string orderState = GetPostString("orderState");
  6159. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  6160. string afterState = GetPostString("afterstate");
  6161. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6162. string date1 = GetPostString("date1");
  6163. string date2 = GetPostString("date2");
  6164. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6165. if (dw.Length > 0) lw.Add(dw);
  6166. string price1 = GetPostString("price1");
  6167. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6168. string price2 = GetPostString("price2");
  6169. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6170. //lw.Add(string.Format("IsRefund!={0}", 1));
  6171. string reason = GetPostString("reason");
  6172. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6173. string method = GetPostString("method");
  6174. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6175. string handler = GetPostString("handler");
  6176. if (handler.Length > 0)
  6177. {
  6178. lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6179. }
  6180. string handledate1 = GetPostString("handledate1");
  6181. string handledate2 = GetPostString("handledate2");
  6182. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6183. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6184. string finish1 = GetPostString("finishdate1");
  6185. string finish2 = GetPostString("finishdate2");
  6186. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6187. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6188. string afterdate1 = GetPostString("afterdate1");
  6189. string afterdate2 = GetPostString("afterdate2");
  6190. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6191. if (afterDate.Length > 0) lw.Add(afterDate);
  6192. string supplier = GetPostString("supplier");
  6193. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6194. string responsible = GetPostString("responsibleman");
  6195. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6196. string customer = GetPostString("customer");
  6197. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6198. string design = GetPostString("design");
  6199. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6200. string afterMemoType = GetPostString("aftermemotype");
  6201. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6202. string posCode = CurrentUser.UserPost.Post.Code;
  6203. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6204. //{
  6205. // string vstate = GetPostString("vstate");
  6206. // if (vstate.Length > 0)
  6207. // {
  6208. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6209. // }
  6210. // if (posCode == "Supplier")
  6211. // {
  6212. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6213. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6214. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6215. // }
  6216. // else
  6217. // {
  6218. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6219. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6220. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6221. // {
  6222. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6223. // }
  6224. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6225. // {
  6226. // int orgid = CurrentUser.UserPost.OrgID;
  6227. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6228. // }
  6229. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6230. // {
  6231. // string shopid = CurrentUser.User.pemShop;
  6232. // lw.Add(string.Format("shopId in ({0})", shopid));
  6233. // }
  6234. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6235. // //{
  6236. // // int org_id = CurrentUser.UserPost.OrgID;
  6237. // // lw.Add(string.Format("OrgID={0}", org_id));
  6238. // //}
  6239. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6240. // }
  6241. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6242. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6243. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6244. //}
  6245. if (st == 5)
  6246. {
  6247. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6248. {
  6249. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6250. {
  6251. string shopid = CurrentUser.User.pemShop;
  6252. lw.Add(string.Format("shopId in ({0})", shopid));
  6253. }
  6254. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6255. {
  6256. int mrOrgid = CurrentUser.UserPost.OrgID;
  6257. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6258. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6259. }
  6260. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6261. //{
  6262. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6263. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6264. //}
  6265. else
  6266. {
  6267. string userIdStr = "";
  6268. if (posCode == "CustomerService")
  6269. {
  6270. userIdStr = CurrentUser.UserID + "_k";
  6271. }
  6272. else if (posCode == "Designer" || posCode == "wxDesigner")
  6273. {
  6274. userIdStr = CurrentUser.UserID + "_s";
  6275. }
  6276. else if (posCode == "Place")
  6277. {
  6278. userIdStr = CurrentUser.UserID + "_x";
  6279. }
  6280. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6281. }
  6282. }
  6283. string placedate1 = GetPostString("placedate1");
  6284. string placedate2 = GetPostString("placedate2");
  6285. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6286. if (dwplace.Length > 0) lw.Add(dwplace);
  6287. string supState = GetPostString("supState");
  6288. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6289. string searchType = GetPostString("searchType");
  6290. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6291. {
  6292. lw.Add(string.Format("BackNum>1"));
  6293. }
  6294. lw.Add(string.Format("AfterSaleState>0"));
  6295. if (ex_psize > 0)
  6296. {
  6297. if (CurrentUser.UserPost.Post.Code == "Finance")
  6298. dStruct.Order = "pay_time desc";
  6299. else
  6300. dStruct.Order = "HandleTime desc";
  6301. }
  6302. else
  6303. dStruct.Order = "HandleTime desc";
  6304. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6305. DataTable dt = WebCache.GetData("view_test", dStruct);
  6306. writeGridDataTableJson(dStruct.TotalCount, dt);
  6307. }
  6308. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6309. //{
  6310. // lw.Add(string.Format("AfterSaleState=4"));
  6311. // string code = CurrentUser.UserPost.Post.Code;
  6312. // if (code == "CustomerService")
  6313. // {
  6314. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6315. // }
  6316. // else if (code == "Designer" || code == "DesignerMr")
  6317. // {
  6318. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6319. // }
  6320. // else if (code == "Place" || code == "PlaceMr")
  6321. // {
  6322. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6323. // }
  6324. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6325. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6326. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6327. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6328. //}
  6329. //else //处理中的售后,待处理和处理中合并
  6330. //{
  6331. // if (afterState.Length <= 0)
  6332. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6333. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6334. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6335. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6336. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6337. //}
  6338. }
  6339. public void get_erp_disagreeftersalelist()
  6340. {
  6341. DataStruct dStruct = GetPostStruct();
  6342. List<string> lw = new List<string>();
  6343. int st = 2;
  6344. string tid = GetPostString("ctid");
  6345. if (tid.Length > 0)
  6346. {
  6347. string select_tid = getTidByCtid(tid);
  6348. lw.Add(string.Format("tid='{0}'", select_tid));
  6349. }
  6350. string shopname = GetPostString("shopname");
  6351. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6352. string buyernick = GetPostString("buyer_nick");
  6353. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6354. string sellermemo = GetPostString("seller_memo");
  6355. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6356. string orderState = GetPostString("orderState");
  6357. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6358. string afterState = GetPostString("afterstate");
  6359. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6360. string date1 = GetPostString("date1");
  6361. string date2 = GetPostString("date2");
  6362. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6363. if (dw.Length > 0) lw.Add(dw);
  6364. string price1 = GetPostString("price1");
  6365. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6366. string price2 = GetPostString("price2");
  6367. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6368. //lw.Add(string.Format("IsRefund!={0}", 1));
  6369. string reason = GetPostString("reason");
  6370. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6371. string method = GetPostString("method");
  6372. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6373. string handler = GetPostString("handler");
  6374. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6375. string handledate1 = GetPostString("handledate1");
  6376. string handledate2 = GetPostString("handledate2");
  6377. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6378. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6379. string afterdate1 = GetPostString("afterdate1");
  6380. string afterdate2 = GetPostString("afterdate2");
  6381. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6382. if (afterDate.Length > 0) lw.Add(afterDate);
  6383. string backdate1 = GetPostString("backdate1");
  6384. string backdate2 = GetPostString("backdate2");
  6385. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6386. if (backDate.Length > 0) lw.Add(backDate);
  6387. string supplier = GetPostString("supplier");
  6388. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6389. string responsible = GetPostString("responsibleman");
  6390. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6391. string customer = GetPostString("customer");
  6392. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6393. string design = GetPostString("design");
  6394. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6395. string afterSaleMemo = GetPostString("afterSaleMemo");
  6396. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6397. string afterMemoType = GetPostString("aftermemotype");
  6398. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6399. string aftersakereason = GetPostString("aftersakereason");
  6400. if (aftersakereason.Length > 0)
  6401. {
  6402. if (aftersakereason == "1")
  6403. {
  6404. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6405. }
  6406. if (aftersakereason == "2")
  6407. {
  6408. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6409. }
  6410. }
  6411. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6412. string poscode = CurrentUser.UserPost.Post.Code;
  6413. if (poscode != "SysAdmin")
  6414. {
  6415. string shopid = CurrentUser.User.pemShop;
  6416. lw.Add(string.Format("shopId in ({0})", shopid));
  6417. }
  6418. string searchType = GetPostString("searchType");
  6419. if (searchType == "wait")
  6420. {
  6421. lw.Add(string.Format("HandleTime is null"));
  6422. }
  6423. if (searchType == "handling")
  6424. {
  6425. lw.Add(string.Format("HandleTime is not null "));
  6426. }
  6427. if (searchType == "back" || searchType == "puBack")
  6428. {
  6429. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6430. }
  6431. if (searchType == "reBack")
  6432. {
  6433. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6434. }
  6435. if (searchType == "moreBack")
  6436. {
  6437. lw.Add(string.Format("backNum > 1"));
  6438. }
  6439. lw.Add(string.Format("(AfterSaleState=5)"));
  6440. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6441. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6442. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6443. writeGridDataTableJson(dStruct.TotalCount, dt);
  6444. }
  6445. public void get_erp_handlingaftersalelist()
  6446. {
  6447. DataStruct dStruct = GetPostStruct();
  6448. List<string> lw = new List<string>();
  6449. int st = 2;
  6450. string tid = GetPostString("ctid");
  6451. if (tid.Length > 0)
  6452. {
  6453. string select_tid = getTidByCtid(tid);
  6454. lw.Add(string.Format("tid='{0}'", select_tid));
  6455. }
  6456. string shopname = GetPostString("shopname");
  6457. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6458. string buyernick = GetPostString("buyer_nick");
  6459. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6460. string sellermemo = GetPostString("seller_memo");
  6461. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6462. string orderState = GetPostString("orderState");
  6463. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6464. string afterState = GetPostString("afterstate");
  6465. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6466. string date1 = GetPostString("date1");
  6467. string date2 = GetPostString("date2");
  6468. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6469. if (dw.Length > 0) lw.Add(dw);
  6470. string price1 = GetPostString("price1");
  6471. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6472. string price2 = GetPostString("price2");
  6473. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6474. //lw.Add(string.Format("IsRefund!={0}", 1));
  6475. string reason = GetPostString("reason");
  6476. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6477. string method = GetPostString("method");
  6478. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6479. string handler = GetPostString("handler");
  6480. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6481. string handledate1 = GetPostString("handledate1");
  6482. string handledate2 = GetPostString("handledate2");
  6483. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6484. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6485. string afterdate1 = GetPostString("afterdate1");
  6486. string afterdate2 = GetPostString("afterdate2");
  6487. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6488. if (afterDate.Length > 0) lw.Add(afterDate);
  6489. string supplier = GetPostString("supplier");
  6490. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6491. string responsible = GetPostString("responsibleman");
  6492. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6493. string customer = GetPostString("customer");
  6494. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6495. string design = GetPostString("design");
  6496. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6497. string afterSaleMemo = GetPostString("afterSaleMemo");
  6498. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6499. string afterMemoType = GetPostString("aftermemotype");
  6500. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6501. string afterresult = GetPostString("afterresult");
  6502. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6503. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6504. string poscode = CurrentUser.UserPost.Post.Code;
  6505. if (poscode != "SysAdmin")
  6506. {
  6507. string shopid = CurrentUser.User.pemShop;
  6508. lw.Add(string.Format("shopId in ({0})", shopid));
  6509. }
  6510. string searchType = GetPostString("searchType");
  6511. if (searchType == "wait")
  6512. {
  6513. lw.Add(string.Format("HandleTime is null"));
  6514. }
  6515. if (searchType == "documentary")
  6516. {
  6517. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6518. }
  6519. if (searchType == "handling")
  6520. {
  6521. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6522. }
  6523. if (searchType == "back" || searchType == "puBack")
  6524. {
  6525. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6526. }
  6527. if (searchType == "reBack")
  6528. {
  6529. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6530. }
  6531. if (afterState.Length <= 0)
  6532. {
  6533. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6534. }
  6535. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6536. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6537. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6538. writeGridDataTableJson(dStruct.TotalCount, dt);
  6539. }
  6540. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6541. //public void get_erp_back_handlingaftersalelist()
  6542. //{
  6543. // DataStruct dStruct = GetPostStruct();
  6544. // List<string> lw = new List<string>();
  6545. // string tid = GetPostString("ctid");
  6546. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6547. // string shopname = GetPostString("shopname");
  6548. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6549. // string buyernick = GetPostString("buyer_nick");
  6550. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6551. // string sellermemo = GetPostString("seller_memo");
  6552. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6553. // string orderState = GetPostString("orderState");
  6554. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6555. // string afterState = GetPostString("afterstate");
  6556. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6557. // string date1 = GetPostString("date1");
  6558. // string date2 = GetPostString("date2");
  6559. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6560. // if (dw.Length > 0) lw.Add(dw);
  6561. // string price1 = GetPostString("price1");
  6562. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6563. // string price2 = GetPostString("price2");
  6564. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6565. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6566. // string reason = GetPostString("reason");
  6567. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6568. // string method = GetPostString("method");
  6569. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6570. // string handler = GetPostString("handler");
  6571. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6572. // string handledate1 = GetPostString("handledate1");
  6573. // string handledate2 = GetPostString("handledate2");
  6574. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6575. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6576. // string afterdate1 = GetPostString("afterdate1");
  6577. // string afterdate2 = GetPostString("afterdate2");
  6578. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6579. // if (afterDate.Length > 0) lw.Add(afterDate);
  6580. // string supplier = GetPostString("supplier");
  6581. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6582. // string responsible = GetPostString("responsibleman");
  6583. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6584. // string customer = GetPostString("customer");
  6585. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6586. // string design = GetPostString("design");
  6587. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6588. // string afterMemoType = GetPostString("aftermemotype");
  6589. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6590. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6591. // if (afterState.Length <= 0)
  6592. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6593. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6594. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6595. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6596. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6597. //}
  6598. public void get_erp_aftersaleverifylist()
  6599. {
  6600. DataStruct dStruct = GetPostStruct();
  6601. List<string> lw = new List<string>();
  6602. string tid = GetPostString("ctid");
  6603. if (tid.Length > 0)
  6604. {
  6605. string select_tid = getTidByCtid(tid);
  6606. lw.Add(string.Format("otid='{0}'", select_tid));
  6607. }
  6608. string shopname = GetPostString("shopname");
  6609. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6610. string buyernick = GetPostString("buyer_nick");
  6611. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6612. string sellermemo = GetPostString("seller_memo");
  6613. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6614. string orderState = GetPostString("orderState");
  6615. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6616. //lw.Add(string.Format("IsRefund!={0}", 1));
  6617. string reason = GetPostString("reason");
  6618. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6619. string method = GetPostString("method");
  6620. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6621. string handler = GetPostString("handler");
  6622. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6623. string handledate1 = GetPostString("handledate1");
  6624. string handledate2 = GetPostString("handledate2");
  6625. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6626. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6627. string finish1 = GetPostString("finishdate1");
  6628. string finish2 = GetPostString("finishdate2");
  6629. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6630. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6631. string supplier = GetPostString("supplier");
  6632. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6633. string responsible = GetPostString("responsibleman");
  6634. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6635. string posCode = CurrentUser.UserPost.Post.Code;
  6636. string vstate = GetPostString("vstate");
  6637. if (vstate.Length > 0)
  6638. {
  6639. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6640. }
  6641. if (posCode == "Supplier")
  6642. {
  6643. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6644. lw.Add(string.Format("VerifyState = 0"));
  6645. lw.Add("type = 1");
  6646. lw.Add(string.Format("AfterSaleState={0}", 3));
  6647. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6648. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6649. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6650. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6651. writeGridDataTableJson(dStruct.TotalCount, dt);
  6652. }
  6653. else if (posCode == "logistics")
  6654. {
  6655. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6656. lw.Add(string.Format("VerifyState = 0"));
  6657. lw.Add("type = 2");
  6658. lw.Add(string.Format("AfterSaleState={0}", 3));
  6659. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6660. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6661. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6662. writeGridDataTableJson(dStruct.TotalCount, dt);
  6663. }
  6664. else
  6665. {
  6666. lw.Add(string.Format("(AfterSaleState = 3)"));
  6667. lw.Add("type = 0");
  6668. string reasonState = GetPostString("reasonState");
  6669. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "Summarize" || posCode == "Finance")
  6670. {
  6671. if (reasonState == "2")
  6672. {
  6673. lw.Add("VerifyState = 3");
  6674. }
  6675. else if (reasonState == "1")
  6676. {
  6677. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6678. }
  6679. else
  6680. {
  6681. lw.Add("VerifyState in (0,3)");
  6682. }
  6683. //不加条件,可以看全部
  6684. }
  6685. 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")
  6686. {
  6687. int orgid = CurrentUser.UserPost.OrgID;
  6688. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6689. if (string.IsNullOrEmpty(manageOrgId))
  6690. {
  6691. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6692. }
  6693. else
  6694. {
  6695. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6696. }
  6697. if (reasonState == "1")
  6698. {
  6699. lw.Add("VerifyState = 3");
  6700. }
  6701. else if (reasonState == "2")
  6702. {
  6703. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6704. }
  6705. else
  6706. {
  6707. }
  6708. }
  6709. else
  6710. {
  6711. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6712. }
  6713. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6714. //{
  6715. // int org_id = CurrentUser.UserPost.OrgID;
  6716. // lw.Add(string.Format("OrgID={0}", org_id));
  6717. //}
  6718. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6719. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6720. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6721. writeGridDataTableJson(dStruct.TotalCount, dt);
  6722. }
  6723. }
  6724. public void get_erp_finishaftersalelist()
  6725. {
  6726. DataStruct dStruct = GetPostStruct();
  6727. List<string> lw = new List<string>();
  6728. int st = 4;
  6729. string tid = GetPostString("ctid");
  6730. if (tid.Length > 0)
  6731. {
  6732. string select_tid = getTidByCtid(tid);
  6733. lw.Add(string.Format("otid='{0}'", select_tid));
  6734. }
  6735. string shopname = GetPostString("shopname");
  6736. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6737. //lw.Add(string.Format("IsRefund!={0}", 1));
  6738. string reason = GetPostString("reason");
  6739. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6740. string method = GetPostString("method");
  6741. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6742. string buyernick = GetPostString("buyer_nick");
  6743. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6744. string handler = GetPostString("handler");
  6745. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6746. string handledate1 = GetPostString("handledate1");
  6747. string handledate2 = GetPostString("handledate2");
  6748. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6749. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6750. string finish1 = GetPostString("finishdate1");
  6751. string finish2 = GetPostString("finishdate2");
  6752. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6753. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6754. string supplier = GetPostString("supplier");
  6755. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6756. string responsible = GetPostString("responsibleman");
  6757. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6758. string vstate = GetPostString("vstate");
  6759. if (vstate.Length > 0)
  6760. {
  6761. if ("3".Equals(vstate))
  6762. {
  6763. lw.Add(string.Format("IsTem=1"));
  6764. }
  6765. else
  6766. {
  6767. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6768. }
  6769. }
  6770. lw.Add(string.Format("AfterSaleState=4"));
  6771. string code = CurrentUser.UserPost.Post.Code;
  6772. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6773. {
  6774. //不加条件,可以看全部
  6775. }
  6776. else if (code == "Supplier")
  6777. {
  6778. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6779. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6780. lw.Add("type = 1");
  6781. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6782. }
  6783. else if (code == "logistics")
  6784. {
  6785. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6786. lw.Add("type = 2");
  6787. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6788. }
  6789. 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")
  6790. {
  6791. lw.Add("type = 0");
  6792. int orgid = CurrentUser.UserPost.OrgID;
  6793. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6794. if (string.IsNullOrEmpty(manageOrgIds))
  6795. {
  6796. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6797. }
  6798. else
  6799. {
  6800. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6801. }
  6802. }
  6803. else
  6804. {
  6805. lw.Add("type = 0");
  6806. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6807. }
  6808. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6809. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6810. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6811. writeGridDataTableJson(dStruct.TotalCount, dt);
  6812. }
  6813. public void handle_erp_aftersale()
  6814. {
  6815. if (UrlPostParmsCheck("ctid"))
  6816. {
  6817. string eid = GetPostString("ctid");
  6818. string responStr = GetPostString("AfterSaleResponsible");
  6819. if (responStr.Length <= 0)
  6820. {
  6821. returnErrorMsg("售后责任人不能为空");
  6822. return;
  6823. }
  6824. bool isDesign = false;
  6825. double designFree = 0.00;
  6826. int responsibleId = 0;
  6827. CeErpTradeCell entity = null;
  6828. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6829. if (entity != null)
  6830. {
  6831. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6832. string afterMethod = GetPostString("AfterSaleMethod");
  6833. if (isNeedNewOrder == 1)
  6834. {
  6835. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6836. bool ishav = true;
  6837. if (newentity == null)
  6838. {
  6839. newentity = entity.Clone() as CeErpTradeCell;
  6840. ishav = false;
  6841. newentity.ctid = "S_" + entity.ctid;
  6842. newentity.OrderState = 0;
  6843. //唯一标识
  6844. newentity.OrderSn = newentity.ctid;
  6845. string orderSn = dataHelper.getSaleOrderSn();
  6846. if (orderSn != "")
  6847. {
  6848. newentity.OrderSn = orderSn;
  6849. }
  6850. }
  6851. newentity.UpdateTime = DateTime.Now;
  6852. newentity.AfterSaleState = 0;
  6853. newentity.AfterSaleMethod = afterMethod;
  6854. if (!ishav)
  6855. {
  6856. string memo_str = newentity.seller_memo;
  6857. memo_str = memo_str.Replace("(", "(");
  6858. memo_str = memo_str.Replace(")", ")");
  6859. int sIndex = memo_str.IndexOf("(");
  6860. int eIndex = memo_str.IndexOf(")");
  6861. if (sIndex == -1 || eIndex == -1)
  6862. {
  6863. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6864. return;
  6865. }
  6866. string first = memo_str.Substring(0, sIndex + 1);
  6867. string memoCtid = newentity.OrderSn;
  6868. //if (memoCtid.IndexOf("C") != -1)
  6869. //{
  6870. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6871. //if (CIdx.IndexOf("+") != -1)
  6872. //{
  6873. //CIdx = "C" + CIdx.Split('+')[1];
  6874. //}
  6875. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6876. //}
  6877. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6878. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6879. string newMemo = first + memoCtid + last;
  6880. newentity.seller_memo = newMemo;
  6881. newentity.FinishPlaceTime = null;
  6882. newentity.UnusualTag = 0;
  6883. newentity.UnusualCon = "";
  6884. newentity.UnusualTime = null;
  6885. newentity.AfterSaleMemo = "";
  6886. newentity.AfterSaleMethod = afterMethod;
  6887. newentity.AfterSalePreTime = null;
  6888. newentity.AfterSaleReason = "";
  6889. newentity.AfterSaleResponsible = "";
  6890. newentity.AfterSaleState = 0;
  6891. newentity.AfterSaleTime = null;
  6892. newentity.AfterSaleUserId = 0;
  6893. newentity.AfterSaleSupplierState = 0;
  6894. newentity.LastBillWaybillCode = "";
  6895. newentity.LastBillCpCode = "";
  6896. newentity.FinishAfterSaleTime = null;
  6897. newentity.HandleTime = null;
  6898. newentity.IsSF = 0;
  6899. newentity.IsOldCustomer = 0;
  6900. newentity.UrgencyTime = null;
  6901. newentity.ResponsibleUserId = "";
  6902. newentity.IsVerifyToSupplier = false;
  6903. newentity.payment = 0;
  6904. newentity.CheckMemo = "";
  6905. newentity.OutSid = "";
  6906. newentity.CheckOrderTime = null;
  6907. newentity.MemoOpt = 0;
  6908. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6909. }
  6910. newentity.isAfterSaleOrder = 1;
  6911. newentity.IsRefund = 0;
  6912. string receiveMobile = GetPostString("receiver_mobile");
  6913. if (receiveMobile.Length > 0)
  6914. {
  6915. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6916. if (trade != null)
  6917. {
  6918. trade.receiver_name = GetPostString("receiver_name");
  6919. trade.receiver_mobile = receiveMobile;
  6920. trade.receiver_state = GetPostString("receiver_state");
  6921. trade.receiver_city = GetPostString("receiver_city");
  6922. trade.receiver_district = GetPostString("receiver_district");
  6923. trade.receiver_address = GetPostString("receiver_address");
  6924. newentity.IsOffLineOrder = 1;
  6925. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6926. }
  6927. }
  6928. string st = GetPostString("ToState");
  6929. if (st.Length > 0)
  6930. {
  6931. if (newentity.OrderState <= 3)
  6932. {
  6933. newentity.WaitDesignTime = DateTime.Now;
  6934. newentity.StartDesignTime = null;
  6935. newentity.FinishDesignTime = null;
  6936. newentity.OrderState = 3;
  6937. if (st == "下单员")
  6938. {
  6939. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6940. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6941. {
  6942. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6943. }
  6944. }
  6945. else
  6946. {
  6947. newentity.WaitDesignTime = DateTime.Now;
  6948. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6949. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6950. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6951. {
  6952. DataRow user = dt1.Rows[0];
  6953. //找主管
  6954. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6955. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6956. if (dt != null && dt.Rows.Count > 0)
  6957. {
  6958. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6959. newentity.DesignUserId = designMr;
  6960. string key = "aftersale_order_" + designMr;
  6961. if (RedisHelper.HasKey(key))
  6962. {
  6963. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6964. list.Add(newentity.ctid);
  6965. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6966. }
  6967. }
  6968. //账号正常
  6969. if (user["State"].ToString() == "0")
  6970. {
  6971. newentity.DesignUserId = entity.DesignUserId;
  6972. string key = "aftersale_order_" + entity.DesignUserId;
  6973. if (RedisHelper.HasKey(key))
  6974. {
  6975. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6976. list.Add(newentity.ctid);
  6977. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6978. }
  6979. }
  6980. }
  6981. }
  6982. }
  6983. if (entity.IsXianHuo == 1)
  6984. {
  6985. newentity.OrderState = 6;
  6986. entity.FinishPlaceTime = DateTime.Now;
  6987. }
  6988. }
  6989. if (ishav)
  6990. {
  6991. newentity.Update();
  6992. }
  6993. else
  6994. {
  6995. newentity.Create();
  6996. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6997. newCellExtend.ctid = newentity.ctid;
  6998. newCellExtend.orderFrom = 20;
  6999. newCellExtend.orderType = 30;
  7000. if (st == "下单员")
  7001. {
  7002. }
  7003. else
  7004. {
  7005. newCellExtend.ReprintTime = DateTime.Now;
  7006. }
  7007. newCellExtend.Create();
  7008. }
  7009. if (st != "下单员")
  7010. {
  7011. if (entity.DispatchSort == 2)
  7012. {
  7013. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  7014. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  7015. }
  7016. }
  7017. }
  7018. //处理售后扩展
  7019. string resIdStr = GetPostString("ResponsibleUserId");
  7020. string refundFees = GetPostString("refundFrees");
  7021. int IsComplain = GetPostInt("isComplain");
  7022. int IsBad = GetPostInt("isBad");
  7023. string IsOriginal = GetPostString("isOriginal");
  7024. double diffResultPrice = GetPostDouble("diffResultPrice");
  7025. string textResult = GetPostString("textResult");
  7026. string supplierResponsible = GetPostString("supplierResponsible");
  7027. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  7028. if (ceErpTradeAfterSaleExtend == null)
  7029. {
  7030. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7031. ceErpTradeAfterSaleExtend.tid = eid;
  7032. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  7033. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  7034. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7035. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  7036. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  7037. ceErpTradeAfterSaleExtend.TextResult = textResult;
  7038. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  7039. ceErpTradeAfterSaleExtend.Create();
  7040. }
  7041. else
  7042. {
  7043. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  7044. {
  7045. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  7046. }
  7047. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  7048. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  7049. ceErpTradeAfterSaleExtend.TextResult = textResult;
  7050. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  7051. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  7052. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  7053. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7054. ceErpTradeAfterSaleExtend.Update();
  7055. }
  7056. int gysid = GetPostInt("ResponsibleSupId");
  7057. if (entity.AfterSaleUserId == 0)
  7058. {
  7059. entity.AfterSaleUserId = CurrentUser.UserID;
  7060. }
  7061. entity.ResponsibleUserId = resIdStr;
  7062. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  7063. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  7064. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  7065. {
  7066. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7067. int backNum = 0;
  7068. if (number != null)
  7069. {
  7070. backNum = number.BackNum;
  7071. }
  7072. char[] separator = { ',' };
  7073. string[] sArray = resIdStr.Split(separator);
  7074. string[] refundFreeList = { };
  7075. if (refundFees.Length > 0)
  7076. {
  7077. refundFreeList = refundFees.Split(separator);
  7078. }
  7079. int index = -1;
  7080. List<int> responsibleIds = new List<int>();
  7081. foreach (string i in sArray)
  7082. {
  7083. index++;
  7084. if (i.Length <= 0) continue;
  7085. char[] separator2 = { '_' };
  7086. string idstr = i.Split(separator2)[0];
  7087. string idtype = i.Split(separator2)[1];
  7088. double refudFree = 0;
  7089. if (refundFreeList.Length > 0)
  7090. {
  7091. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  7092. }
  7093. if (idtype == "s")
  7094. {
  7095. isDesign = true;
  7096. designFree = refudFree;
  7097. }
  7098. int userId = Convert.ToInt32(idstr);
  7099. int type = 0;
  7100. if (idtype == "g")
  7101. {
  7102. type = 1;
  7103. }
  7104. if (idtype == "w")
  7105. {
  7106. type = 2;
  7107. }
  7108. if (idtype == "t")
  7109. {
  7110. type = 3;
  7111. }
  7112. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  7113. if (ceErpTradeResponsible == null)
  7114. {
  7115. ceErpTradeResponsible = new CeErpTradeResponsible();
  7116. ceErpTradeResponsible.tid = eid;
  7117. ceErpTradeResponsible.UserId = userId;
  7118. ceErpTradeResponsible.createdTime = DateTime.Now;
  7119. ceErpTradeResponsible.type = type;
  7120. if (type == 1)
  7121. {
  7122. ceErpTradeResponsible.IsSup = 1;
  7123. }
  7124. if (type == 2)
  7125. {
  7126. ceErpTradeResponsible.IsFlow = 1;
  7127. }
  7128. }
  7129. int state = 0;
  7130. //已认可的不需要再次认可
  7131. if (sArray.Length > 1 && ceErpTradeResponsible.VerifyState == 1)
  7132. {
  7133. state = 1;
  7134. }
  7135. ceErpTradeResponsible.RefundFee = refudFree;
  7136. ceErpTradeResponsible.VerifyState = state;
  7137. if (userId == 2125 || idtype == "w")
  7138. {
  7139. ceErpTradeResponsible.VerifyState = 1;
  7140. }
  7141. if (idtype == "w" && userId == 101)
  7142. {
  7143. ceErpTradeResponsible.VerifyState = state;
  7144. }
  7145. if (ceErpTradeResponsible.ID > 0)
  7146. {
  7147. ceErpTradeResponsible.Update();
  7148. }
  7149. else
  7150. {
  7151. ceErpTradeResponsible.Create();
  7152. }
  7153. if (isDesign)
  7154. {
  7155. responsibleId = ceErpTradeResponsible.ID;
  7156. }
  7157. responsibleIds.Add(ceErpTradeResponsible.ID);
  7158. }
  7159. CeErpTradeResponsible.ExecuteNonQuery(string.Format("update CE_ErpTradeResponsible set VerifyState =-1 where tid='" + eid + "' and ID NOT IN (" + string.Join(",", responsibleIds) + ")"));
  7160. CeErpTradeResponsible.NumByTid(backNum, eid);
  7161. }
  7162. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  7163. if (ceErpTradeCellExtend != null)
  7164. {
  7165. ceErpTradeCellExtend.returnVisit = 0;
  7166. ceErpTradeCellExtend.Update();
  7167. }
  7168. if (entity.HandleTime != null)
  7169. {
  7170. if (entity.AfterSaleState == 1)
  7171. {
  7172. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  7173. }
  7174. else
  7175. {
  7176. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  7177. }
  7178. }
  7179. else
  7180. {
  7181. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  7182. entity.HandleTime = DateTime.Now;
  7183. }
  7184. bool isCompale = false;
  7185. if (entity.AfterSaleState == 5)
  7186. {
  7187. isCompale = true;
  7188. entity.AfterSaleState = 3;
  7189. }
  7190. entity.AfterSaleSupplierState = 0;
  7191. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7192. {
  7193. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7194. }
  7195. string sImgs = GetPostString("img");
  7196. entity.AfterSaleSupplierImg = sImgs;
  7197. entity.supRefundType = GetPostString("supRefundType");
  7198. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7199. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7200. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7201. entity.AfterSaleMemoType = GetPostString("MemoType");
  7202. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7203. {
  7204. //entity.AfterSaleSupplierState = 2;
  7205. }
  7206. string df = GetPostString("DeductFee");
  7207. if (df == "")
  7208. {
  7209. df = "0";
  7210. }
  7211. string rf = GetPostString("RefundFee");
  7212. if (rf == "")
  7213. {
  7214. rf = "0";
  7215. }
  7216. string pm = GetPostString("AfterSalePayment");
  7217. if (pm == "")
  7218. {
  7219. pm = "0";
  7220. }
  7221. entity.AfterSalePayment = Convert.ToDouble(pm);
  7222. entity.DeductFee = Convert.ToDouble(df);
  7223. entity.RefundFee = Convert.ToDouble(rf);
  7224. entity.UpdateTime = DateTime.Now;
  7225. entity.Update();
  7226. string toState = GetPostString("ToState");
  7227. string original = GetPostString("isOriginal");
  7228. ApiVo apiVo = new ApiVo();
  7229. apiVo.orderNumber = entity.ctid;
  7230. apiVo.actionName = "afterDesign";
  7231. apiVo.orderRemarks = entity.AfterSaleMethod;
  7232. apiVo.reasonRemarks = entity.AfterSaleReason;
  7233. apiVo.isDesign = isDesign;
  7234. apiVo.designFree = designFree;
  7235. apiVo.responsibleId = responsibleId;
  7236. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7237. if (toState == "设计师")
  7238. {
  7239. apiVo.isOriginal = Convert.ToBoolean(original);
  7240. }
  7241. designHelper.API_WorkCore(apiVo);//afterDesign
  7242. CeErpMethod methodSql = new CeErpMethod();
  7243. methodSql.con = entity.AfterSaleMethod;
  7244. methodSql.addTime = DateTime.Now;
  7245. methodSql.Create();
  7246. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7247. CeErpMethod.ExecuteNonQuery(delsql);
  7248. if (isCompale)
  7249. {
  7250. aftersale_data_change(entity.ctid);
  7251. }
  7252. returnSuccessMsg("操作成功!");
  7253. return;
  7254. }
  7255. returnErrorMsg("找不到订单记录");
  7256. }
  7257. }
  7258. public void ins_erp_toresponsible()
  7259. {
  7260. if (UrlPostParmsCheck("ctid"))
  7261. {
  7262. string eid = GetPostString("ctid");
  7263. CeErpTradeCell entity = null;
  7264. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7265. if (entity != null)
  7266. {
  7267. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7268. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7269. {
  7270. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7271. return;
  7272. }
  7273. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7274. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7275. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7276. if (entity.AfterSalePreTime == null)
  7277. {
  7278. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7279. {
  7280. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7281. }
  7282. }
  7283. entity.AfterSalePreTime = DateTime.Now;
  7284. //预完成给售后主管审核客户问题直接完成
  7285. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7286. {
  7287. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7288. {
  7289. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7290. }
  7291. }
  7292. ceErpTradeAfterSaleExtend.DisagreeTime = null;
  7293. ceErpTradeAfterSaleExtend.Update();
  7294. entity.AfterSaleState = 2;
  7295. entity.UpdateTime = DateTime.Now;
  7296. entity.Update();
  7297. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7298. aftersale_data_change(entity.ctid);
  7299. returnSuccessMsg("操作成功!");
  7300. return;
  7301. }
  7302. returnErrorMsg("找不到订单记录");
  7303. }
  7304. }
  7305. public void cancel_erp_aftersaleanddelnew()
  7306. {
  7307. if (UrlPostParmsCheck("ctid"))
  7308. {
  7309. string eid = GetPostString("ctid");
  7310. CeErpTradeCell entity = null;
  7311. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7312. if (entity != null)
  7313. {
  7314. entity.AfterSaleState = 0;
  7315. entity.AfterSaleReason = "";
  7316. entity.AfterSaleMethod = "";
  7317. entity.AfterSaleMemo = "";
  7318. entity.AfterSaleResponsible = "";
  7319. entity.ResponsibleUserId = "";
  7320. entity.DeductFee = 0;
  7321. entity.RefundFee = 0;
  7322. entity.IsArbitrate = 0;
  7323. CeErpTradeResponsible.DelByTid(eid, -1);
  7324. entity.Update();
  7325. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7326. if (after != null)
  7327. {
  7328. if (after.OrderState < 5)
  7329. CeErpTradeCell.DelByCtid("S_" + eid);
  7330. }
  7331. returnSuccessMsg("操作成功!");
  7332. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7333. return;
  7334. }
  7335. returnErrorMsg("找不到订单记录");
  7336. }
  7337. }
  7338. public void get_erp_aftersale_pregather()
  7339. {
  7340. List<string> lw = new List<string>();
  7341. int st = GetInt("st");
  7342. string tid = GetPostString("ctid");
  7343. if (tid.Length > 0)
  7344. {
  7345. string select_tid = getTidByCtid(tid);
  7346. lw.Add(string.Format("tid='{0}'", select_tid));
  7347. }
  7348. string shopname = GetPostString("shopname");
  7349. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7350. string buyernick = GetPostString("buyer_nick");
  7351. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7352. string sellermemo = GetPostString("seller_memo");
  7353. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7354. string orderState = GetPostString("orderState");
  7355. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7356. string reason = GetPostString("reason");
  7357. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7358. string method = GetPostString("method");
  7359. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7360. string handler = GetPostString("handler");
  7361. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7362. string handledate1 = GetPostString("handledate1");
  7363. string handledate2 = GetPostString("handledate2");
  7364. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7365. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7366. string supplier = GetPostString("supplier");
  7367. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7368. string responsible = GetPostString("responsibleman");
  7369. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7370. string customer = GetPostString("customer");
  7371. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7372. string design = GetPostString("design");
  7373. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7374. string afterMemoType = GetPostString("aftermemotype");
  7375. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7376. string afterSaleMemo = GetPostString("afterSaleMemo");
  7377. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7378. string afterresult = GetPostString("afterresult");
  7379. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7380. string poscode = CurrentUser.UserPost.Post.Code;
  7381. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7382. {
  7383. string shopid = CurrentUser.User.pemShop;
  7384. lw.Add(string.Format("shopId in ({0})", shopid));
  7385. }
  7386. var mainwhere = string.Join(" and ", lw.ToArray());
  7387. string ro_json = "";
  7388. string type = GetPostString("gather_type");
  7389. int number = 0;
  7390. if (poscode == "AfterSale")
  7391. {
  7392. //处理中
  7393. if (type == "Handling")
  7394. {
  7395. 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) : ""));
  7396. DataTable dt = null;
  7397. try
  7398. {
  7399. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7400. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7401. }
  7402. catch (Exception e)
  7403. {
  7404. dt = new DataTable();
  7405. }
  7406. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7407. return;
  7408. }
  7409. if (type == "Wait")
  7410. {
  7411. //待处理
  7412. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7413. DataTable dt1 = null;
  7414. try
  7415. {
  7416. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7417. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7418. }
  7419. catch (Exception e)
  7420. {
  7421. dt1 = new DataTable();
  7422. }
  7423. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7424. return;
  7425. }
  7426. if (type == "back")
  7427. {
  7428. //打回
  7429. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7430. DataTable dt2 = null;
  7431. try
  7432. {
  7433. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7434. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7435. }
  7436. catch (Exception e)
  7437. {
  7438. dt2 = new DataTable();
  7439. }
  7440. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7441. return;
  7442. }
  7443. if (type == "preCompletion")
  7444. {
  7445. //预完成
  7446. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7447. DataTable dt3 = null;
  7448. try
  7449. {
  7450. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7451. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7452. }
  7453. catch (Exception e)
  7454. {
  7455. dt3 = new DataTable();
  7456. }
  7457. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7458. return;
  7459. }
  7460. if (type == "documentary")
  7461. {
  7462. //跟单中
  7463. 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) : ""));
  7464. DataTable dt4 = null;
  7465. try
  7466. {
  7467. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7468. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7469. }
  7470. catch (Exception e)
  7471. {
  7472. dt4 = new DataTable();
  7473. }
  7474. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7475. return;
  7476. }
  7477. if (type == "reBack")
  7478. {
  7479. //被打回
  7480. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7481. DataTable dt1 = null;
  7482. try
  7483. {
  7484. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7485. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7486. }
  7487. catch (Exception e)
  7488. {
  7489. dt1 = new DataTable();
  7490. }
  7491. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7492. return;
  7493. }
  7494. }
  7495. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7496. {
  7497. if (type == "puBack")
  7498. {
  7499. //退回
  7500. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7501. DataTable dt = null;
  7502. try
  7503. {
  7504. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7505. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7506. }
  7507. catch (Exception e)
  7508. {
  7509. dt = new DataTable();
  7510. }
  7511. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7512. return;
  7513. }
  7514. if (type == "reBack")
  7515. {
  7516. //打回
  7517. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7518. DataTable dt1 = null;
  7519. try
  7520. {
  7521. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7522. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7523. }
  7524. catch (Exception e)
  7525. {
  7526. dt1 = new DataTable();
  7527. }
  7528. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7529. return;
  7530. }
  7531. if (type == "examEd")
  7532. {
  7533. //已审核
  7534. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7535. DataTable dt2 = null;
  7536. try
  7537. {
  7538. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7539. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7540. }
  7541. catch (Exception e)
  7542. {
  7543. dt2 = new DataTable();
  7544. }
  7545. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7546. return;
  7547. }
  7548. if (type == "waitExam")
  7549. {
  7550. //待审核
  7551. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7552. DataTable dt3 = null;
  7553. try
  7554. {
  7555. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7556. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7557. }
  7558. catch (Exception e)
  7559. {
  7560. dt3 = new DataTable();
  7561. }
  7562. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7563. return;
  7564. }
  7565. if (type == "Handling")
  7566. {
  7567. //处理中
  7568. 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) : ""));
  7569. DataTable dt4 = null;
  7570. try
  7571. {
  7572. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7573. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7574. }
  7575. catch (Exception e)
  7576. {
  7577. dt4 = new DataTable();
  7578. }
  7579. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7580. return;
  7581. }
  7582. if (type == "Wait")
  7583. {
  7584. //待处理
  7585. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7586. DataTable dt5 = null;
  7587. try
  7588. {
  7589. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7590. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7591. }
  7592. catch (Exception e)
  7593. {
  7594. dt5 = new DataTable();
  7595. }
  7596. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7597. return;
  7598. }
  7599. if (type == "documentary")
  7600. {
  7601. //跟单中
  7602. 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) : ""));
  7603. DataTable dt6 = null;
  7604. try
  7605. {
  7606. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7607. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7608. }
  7609. catch (Exception e)
  7610. {
  7611. dt6 = new DataTable();
  7612. }
  7613. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7614. return;
  7615. }
  7616. }
  7617. returnSuccess(ro_json);
  7618. }
  7619. public void end_erp_aftersale()
  7620. {
  7621. if (UrlPostParmsCheck("ctid"))
  7622. {
  7623. string eid = GetPostString("ctid");
  7624. CeErpTradeCell entity = null;
  7625. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7626. if (entity != null)
  7627. {
  7628. string stype = GetPostString("stype");
  7629. string typeStr = stype;
  7630. entity.AfterSaleState = 4;
  7631. entity.FinishAfterSaleTime = DateTime.Now;
  7632. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7633. entity.Update();
  7634. ApiVo apiVo = new ApiVo();
  7635. apiVo.orderNumber = entity.ctid;
  7636. apiVo.actionName = "afterOver";
  7637. designHelper.API_WorkCore(apiVo); //afterOver
  7638. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7639. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7640. CeErpSukuraData.createInfo(entity.ctid, 8);
  7641. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7642. returnSuccessMsg("操作成功!");
  7643. return;
  7644. }
  7645. returnErrorMsg("找不到订单记录");
  7646. }
  7647. }
  7648. public void ins_erp_finishaftersale()
  7649. {
  7650. if (UrlPostParmsCheck("id"))
  7651. {
  7652. string eid = GetPostString("id");
  7653. CeErpTradeResponsible entity = null;
  7654. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7655. if (entity != null)
  7656. {
  7657. entity.VerifyState = 1;
  7658. entity.VerifyTime = DateTime.Now;
  7659. entity.Update();
  7660. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7661. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7662. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7663. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7664. if (dt.Rows.Count <= 0)
  7665. {
  7666. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7667. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7668. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7669. CeErpSukuraData.createInfo(entity.tid, 8);
  7670. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7671. {
  7672. CeErpDesignerBill.Del(entity.tid);
  7673. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7674. }
  7675. }
  7676. returnSuccessMsg("操作成功!");
  7677. return;
  7678. }
  7679. returnErrorMsg("找不到订单记录");
  7680. }
  7681. }
  7682. public void upd_erp_arbitrateaftersale()
  7683. {
  7684. if (UrlPostParmsCheck("id"))
  7685. {
  7686. string eid = GetPostString("id");
  7687. CeErpTradeResponsible entity = null;
  7688. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7689. if (entity != null)
  7690. {
  7691. entity.IsArbitrate = 1;
  7692. entity.ArbitradeMemo = GetPostString("reason");
  7693. entity.VerifyState = 2;
  7694. entity.Update();
  7695. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7696. if (tradecell != null)
  7697. {
  7698. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7699. tradecell.IsArbitrate = 1;
  7700. tradecell.Update();
  7701. }
  7702. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7703. returnSuccessMsg("操作成功!");
  7704. return;
  7705. }
  7706. returnErrorMsg("找不到订单记录");
  7707. }
  7708. }
  7709. public void upd_erp_backaftersale()
  7710. {
  7711. if (UrlPostParmsCheck("tid"))
  7712. {
  7713. string eid = GetPostString("tid");
  7714. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7715. int backNum = 0;
  7716. if (number != null)
  7717. {
  7718. backNum = number.BackNum;
  7719. }
  7720. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7721. CeErpTradeCell entity = null;
  7722. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7723. if (entity != null)
  7724. {
  7725. entity.AfterSaleBackReason = GetPostString("backreason");
  7726. entity.AfterSaleState = 1;
  7727. entity.AfterSaleSupplierState = 0;
  7728. entity.UpdateTime = DateTime.Now;
  7729. entity.Update();
  7730. returnSuccessMsg("操作成功!");
  7731. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7732. return;
  7733. }
  7734. returnErrorMsg("找不到订单记录");
  7735. }
  7736. }
  7737. public void get_erp_supplieraftersalelist()
  7738. {
  7739. DataStruct dStruct = GetPostStruct();
  7740. List<string> lw = new List<string>();
  7741. string tid = GetPostString("ctid");
  7742. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7743. string shopname = GetPostString("shopname");
  7744. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7745. string buyernick = GetPostString("buyer_nick");
  7746. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7747. string sellermemo = GetPostString("seller_memo");
  7748. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7749. string orderState = GetPostString("orderState");
  7750. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7751. string afterState = GetPostString("afterstate");
  7752. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7753. string date1 = GetPostString("date1");
  7754. string date2 = GetPostString("date2");
  7755. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7756. if (dw.Length > 0) lw.Add(dw);
  7757. string price1 = GetPostString("price1");
  7758. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7759. string price2 = GetPostString("price2");
  7760. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7761. string reason = GetPostString("reason");
  7762. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7763. string method = GetPostString("method");
  7764. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7765. string handledate1 = GetPostString("handledate1");
  7766. string handledate2 = GetPostString("handledate2");
  7767. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7768. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7769. string handler = GetPostString("handler");
  7770. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7771. string afterdate1 = GetPostString("afterdate1");
  7772. string afterdate2 = GetPostString("afterdate2");
  7773. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7774. if (afterDate.Length > 0) lw.Add(afterDate);
  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 afterMemoType = GetPostString("aftermemotype");
  7780. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7781. string vstate = GetPostString("vstate");
  7782. if (vstate.Length > 0)
  7783. {
  7784. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7785. }
  7786. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7787. string supplier = GetPostString("supplier");
  7788. int supid = commonHelper.getSupplierIDByName(supplier);
  7789. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7790. string posCode = CurrentUser.UserPost.Post.Code;
  7791. if (posCode == "Supplier")
  7792. {
  7793. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7794. }
  7795. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7796. {
  7797. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7798. }
  7799. else
  7800. {
  7801. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7802. }
  7803. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7804. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7805. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7806. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7807. writeGridDataTableJson(dStruct.TotalCount, dt);
  7808. }
  7809. public void upd_erp_supverifyaftersale()
  7810. {
  7811. if (UrlPostParmsCheck("id"))
  7812. {
  7813. string id = GetPostString("id");
  7814. int st = GetPostInt("afterstate");
  7815. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7816. CeErpTradeCell entity = null;
  7817. if (ceErpTradeResponsible != null)
  7818. {
  7819. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7820. }
  7821. string afmemo = GetPostString("supmemo");
  7822. string image = GetPostString("image");
  7823. if (entity != null)
  7824. {
  7825. entity.AfterSaleSupplierState = st;
  7826. entity.AfterSaleSupplierMemo = afmemo;
  7827. if (st == 1)
  7828. {
  7829. ceErpTradeResponsible.VerifyState = 1;
  7830. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7831. ceErpTradeResponsible.Update();
  7832. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7833. if (isAll)
  7834. {
  7835. entity.AfterSaleState = 4;
  7836. entity.FinishAfterSaleTime = DateTime.Now;
  7837. }
  7838. }
  7839. else
  7840. {
  7841. CeErpTradeResponsible.dateByTid(entity.ctid);
  7842. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7843. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7844. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7845. if (num <= 1)
  7846. {
  7847. entity.AfterSaleState = 1;
  7848. }
  7849. else
  7850. {
  7851. entity.AfterSaleState = 5;
  7852. }
  7853. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7854. if (ceErpTradeAfterSaleExtend != null)
  7855. {
  7856. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7857. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7858. ceErpTradeAfterSaleExtend.Update();
  7859. }
  7860. else
  7861. {
  7862. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7863. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7864. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7865. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7866. ceErpTradeAfterSaleExtend.Create();
  7867. }
  7868. }
  7869. if (entity.AfterSaleState == 4)
  7870. {
  7871. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7872. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7873. {
  7874. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7875. }
  7876. ApiVo apiVo = new ApiVo();
  7877. apiVo.orderNumber = entity.ctid;
  7878. apiVo.actionName = "afterOver";
  7879. designHelper.API_WorkCore(apiVo); //afterOver
  7880. }
  7881. entity.UpdateTime = DateTime.Now;
  7882. entity.Update();
  7883. returnSuccessMsg("操作成功!");
  7884. CeErpSukuraData.createInfo(entity.ctid, 8);
  7885. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7886. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7887. return;
  7888. }
  7889. returnErrorMsg("找不到订单记录");
  7890. }
  7891. }
  7892. public void upd_erp_masteraftersale()
  7893. {
  7894. if (UrlPostParmsCheck("id"))
  7895. {
  7896. string id = GetPostString("id");
  7897. int st = GetPostInt("afterstate");
  7898. string afmemo = GetPostString("supmemo");
  7899. string image = GetPostString("image");
  7900. string textResult = GetPostString("textResult");
  7901. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7902. if (ceErpTradeResponsible != null)
  7903. {
  7904. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7905. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7906. ceErpTradeResponsible.Update();
  7907. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7908. if (entity != null)
  7909. {
  7910. entity.AfterSaleSupplierState = st;
  7911. entity.AfterSaleSupplierMemo = afmemo;
  7912. if (st == 1)
  7913. {
  7914. }
  7915. else
  7916. {
  7917. CeErpTradeResponsible.dateByTid(entity.ctid);
  7918. //退回到售后
  7919. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7920. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7921. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7922. if (num <= 1)
  7923. {
  7924. entity.AfterSaleState = 1;
  7925. }
  7926. else
  7927. {
  7928. entity.AfterSaleState = 5;
  7929. }
  7930. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7931. if (ceErpTradeAfterSaleExtend != null)
  7932. {
  7933. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7934. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7935. ceErpTradeAfterSaleExtend.Update();
  7936. }
  7937. else
  7938. {
  7939. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7940. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7941. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7942. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7943. ceErpTradeAfterSaleExtend.Create();
  7944. }
  7945. }
  7946. entity.UpdateTime = DateTime.Now;
  7947. entity.Update();
  7948. returnSuccessMsg("操作成功!");
  7949. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7950. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7951. return;
  7952. }
  7953. }
  7954. returnErrorMsg("找不到订单记录");
  7955. }
  7956. }
  7957. public void upd_erp_personaftersale()
  7958. {
  7959. if (UrlPostParmsCheck("id"))
  7960. {
  7961. //林小连
  7962. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7963. {
  7964. upd_erp_masteraftersale();
  7965. return;
  7966. }
  7967. string id = GetPostString("id");
  7968. int st = GetPostInt("afterstate");
  7969. string afmemo = GetPostString("supmemo");
  7970. string image = GetPostString("image");
  7971. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7972. if (ceErpTradeResponsible != null)
  7973. {
  7974. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7975. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7976. ceErpTradeResponsible.Update();
  7977. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7978. if (entity != null)
  7979. {
  7980. entity.AfterSaleSupplierMemo = afmemo;
  7981. entity.AfterSaleSupplierState = st;
  7982. if (st == 1)
  7983. {
  7984. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7985. if (isAll)
  7986. {
  7987. entity.AfterSaleState = 4;
  7988. entity.FinishAfterSaleTime = DateTime.Now;
  7989. }
  7990. }
  7991. else
  7992. {
  7993. CeErpTradeResponsible.dateByTid(entity.ctid);
  7994. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7995. if (ceErpTradeAfterSaleExtend != null)
  7996. {
  7997. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7998. ceErpTradeAfterSaleExtend.Update();
  7999. }
  8000. else
  8001. {
  8002. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  8003. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  8004. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  8005. ceErpTradeAfterSaleExtend.Create();
  8006. }
  8007. //退回到主管
  8008. //entity.AfterSaleState = 2;
  8009. }
  8010. if (entity.AfterSaleState == 4)
  8011. {
  8012. ApiVo apiVo = new ApiVo();
  8013. apiVo.orderNumber = entity.ctid;
  8014. apiVo.actionName = "afterOver";
  8015. designHelper.API_WorkCore(apiVo); //afterOver
  8016. }
  8017. entity.UpdateTime = DateTime.Now;
  8018. entity.Update();
  8019. returnSuccessMsg("操作成功!");
  8020. CeErpSukuraData.createInfo(entity.ctid, 8);
  8021. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  8022. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  8023. return;
  8024. }
  8025. }
  8026. returnErrorMsg("找不到订单记录");
  8027. }
  8028. }
  8029. public void set_erp_supplierrefundtag()
  8030. {
  8031. if (UrlPostParmsCheck("ctid"))
  8032. {
  8033. string eid = GetPostString("ctid");
  8034. CeErpTradeCell entity = null;
  8035. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8036. if (entity != null)
  8037. {
  8038. entity.IsSupplierRefund = GetPostInt("tag");
  8039. entity.Update();
  8040. returnSuccessMsg("操作成功!");
  8041. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  8042. return;
  8043. }
  8044. returnErrorMsg("找不到订单记录");
  8045. }
  8046. }
  8047. public void get_erp_refundlist()
  8048. {
  8049. DataStruct dStruct = GetPostStruct();
  8050. List<string> lw = new List<string>();
  8051. string tid = GetPostString("tid");
  8052. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8053. //string rid = GetPostString("refund_id");
  8054. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  8055. string shopname = GetPostString("shopname");
  8056. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8057. string buyernick = GetPostString("buyer_nick");
  8058. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8059. string customer = GetPostString("customer");
  8060. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8061. string design = GetPostString("design");
  8062. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8063. string sellermemo = GetPostString("seller_memo");
  8064. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8065. //string date1 = GetPostString("date1");
  8066. //string date2 = GetPostString("date2");
  8067. //string dateType = GetPostString("dateType");
  8068. //if (dateType.Length > 0)
  8069. //{
  8070. // if (dateType == "1001") dateType = "0";
  8071. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  8072. // if (searchDT.Count == 2)
  8073. // {
  8074. // date1 = searchDT[0].ToString();
  8075. // date2 = searchDT[1].ToString();
  8076. // }
  8077. //}
  8078. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8079. //if (dw.Length > 0) lw.Add(dw);
  8080. string redate1 = GetPostString("refunddate1");
  8081. string redate2 = GetPostString("refunddate2");
  8082. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8083. if (dwdate.Length > 0) lw.Add(dwdate);
  8084. string price1 = GetPostString("price1");
  8085. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8086. string price2 = GetPostString("price2");
  8087. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8088. string ispartrefund = GetPostString("ispartrefund");
  8089. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8090. string refundState = GetPostString("refundvstate");
  8091. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  8092. int st = GetInt("st");
  8093. if (st == 2) //待确认列表中,把state=3已确认的也显示
  8094. {
  8095. string responsible = GetPostString("responsibleman");
  8096. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8097. lw.Add(string.Format("RefundState>={0}", st));
  8098. string code = CurrentUser.UserPost.Post.Code;
  8099. if (code == "CustomerService")
  8100. {
  8101. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  8102. }
  8103. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  8104. {
  8105. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  8106. }
  8107. else if (code == "Place" || code == "PlaceMr")
  8108. {
  8109. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  8110. }
  8111. dStruct.Order = "RefundState asc,created desc";
  8112. }
  8113. else if (st == 10)
  8114. {
  8115. string responsible = GetPostString("responsibleman");
  8116. if (responsible == "空白")
  8117. {
  8118. lw.Add(string.Format("ResponsibleUserName = ''"));
  8119. }
  8120. else if (responsible.Length > 0)
  8121. {
  8122. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8123. }
  8124. lw.Add(string.Format("RefundState>=0"));
  8125. dStruct.Order = "created desc";
  8126. }
  8127. else
  8128. {
  8129. string responsible = GetPostString("responsibleman");
  8130. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8131. lw.Add(string.Format("RefundState={0}", st));
  8132. dStruct.Order = "created desc";
  8133. }
  8134. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8135. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  8136. dt.Columns.Add("refund_fees");
  8137. foreach (DataRow dr in dt.Rows)
  8138. {
  8139. String status = dr["status"].ToString();
  8140. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8141. {
  8142. dr["refund_fees"] = dr["refund_fee"];
  8143. }
  8144. else
  8145. {
  8146. dr["refund_fees"] = "0.0";
  8147. }
  8148. }
  8149. writeGridDataTableJson(dStruct.TotalCount, dt);
  8150. }
  8151. public void get_erp_refunddesignlist()
  8152. {
  8153. DataStruct dStruct = GetPostStruct();
  8154. List<string> lw = new List<string>();
  8155. string tid = GetPostString("tid");
  8156. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8157. string shopname = GetPostString("shopname");
  8158. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8159. string buyernick = GetPostString("buyer_nick");
  8160. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8161. string customer = GetPostString("customer");
  8162. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8163. string design = GetPostString("design");
  8164. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8165. string sellermemo = GetPostString("seller_memo");
  8166. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8167. string redate1 = GetPostString("refunddate1");
  8168. string redate2 = GetPostString("refunddate2");
  8169. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8170. if (dwdate.Length > 0) lw.Add(dwdate);
  8171. string price1 = GetPostString("price1");
  8172. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8173. string price2 = GetPostString("price2");
  8174. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8175. string ispartrefund = GetPostString("ispartrefund");
  8176. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8177. string designerorg = GetPostString("designerorg");
  8178. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  8179. string refundState = GetPostString("refundState");
  8180. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  8181. int myOrgid = CurrentUser.UserPost.OrgID;
  8182. string myOrgCode = CurrentUser.UserPost.Post.Code;
  8183. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8184. {
  8185. if (CurrentUser.User.TeamIds.Length > 0)
  8186. {
  8187. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8188. }
  8189. else
  8190. {
  8191. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8192. }
  8193. }
  8194. else if ("SysAdmin".Equals(myOrgCode))
  8195. {
  8196. }
  8197. else
  8198. {
  8199. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8200. {
  8201. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8202. }
  8203. else
  8204. {
  8205. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8206. }
  8207. }
  8208. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8209. dStruct.Order = "created desc";
  8210. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8211. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8212. dt.Columns.Add("refund_fees");
  8213. foreach (DataRow dr in dt.Rows)
  8214. {
  8215. String status = dr["status"].ToString();
  8216. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8217. {
  8218. dr["refund_fees"] = dr["refund_fee"];
  8219. }
  8220. else
  8221. {
  8222. dr["refund_fees"] = "0.0";
  8223. }
  8224. }
  8225. writeGridDataTableJson(dStruct.TotalCount, dt);
  8226. }
  8227. public void handle_erp_refundtag()
  8228. {
  8229. if (UrlPostParmsCheck("refund_id"))
  8230. {
  8231. string eid = GetPostString("refund_id");
  8232. string respMan = GetPostString("ResponsibleName");
  8233. if (respMan.Length <= 0)
  8234. {
  8235. returnErrorMsg("责任人不能为空");
  8236. return;
  8237. }
  8238. CeErpTradeRefund entity = null;
  8239. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8240. if (entity != null)
  8241. {
  8242. entity.ResponsibleUserName = respMan;
  8243. string userid = GetPostString("ResponsibleUserId");
  8244. if (userid.Length > 0)
  8245. {
  8246. entity.ResponsibleUserId = userid;
  8247. }
  8248. entity.Memo = GetPostString("Memo");
  8249. if (respMan.IndexOf("客服") != -1 ||
  8250. respMan.IndexOf("设计师") != -1 ||
  8251. respMan.IndexOf("下单员") != -1)
  8252. {
  8253. entity.RefundState = 2;
  8254. }
  8255. else
  8256. {
  8257. entity.RefundState = 3;
  8258. }
  8259. entity.modified = DateTime.Now;
  8260. entity.Update();
  8261. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8262. returnSuccessMsg("操作成功!");
  8263. return;
  8264. }
  8265. returnErrorMsg("找不到订单记录");
  8266. }
  8267. }
  8268. public void handle_erp_designrefundtag()
  8269. {
  8270. if (UrlPostParmsCheck("refund_id"))
  8271. {
  8272. string eid = GetPostString("refund_id");
  8273. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8274. if (ceErpTradeCellExtend == null)
  8275. {
  8276. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8277. ceErpTradeCellExtend.ctid = eid;
  8278. }
  8279. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8280. if (ceErpTradeCellExtend.ID > 0)
  8281. {
  8282. ceErpTradeCellExtend.Update();
  8283. }
  8284. else
  8285. {
  8286. ceErpTradeCellExtend.Create();
  8287. }
  8288. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8289. returnSuccessMsg("操作成功!");
  8290. return;
  8291. }
  8292. returnErrorMsg("找不到订单记录");
  8293. }
  8294. public void upd_erp_refundverify()
  8295. {
  8296. if (UrlPostParmsCheck("refund_id"))
  8297. {
  8298. string eid = GetPostString("refund_id");
  8299. CeErpTradeRefund entity = null;
  8300. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8301. if (entity != null)
  8302. {
  8303. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8304. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8305. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8306. {
  8307. entity.RefundState = 2;
  8308. }
  8309. else
  8310. {
  8311. entity.RefundState = 3;
  8312. }
  8313. entity.Update();
  8314. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8315. returnSuccessMsg("操作成功!");
  8316. return;
  8317. }
  8318. returnErrorMsg("找不到订单记录");
  8319. }
  8320. }
  8321. public void upd_erp_refundapprove()
  8322. {
  8323. if (UrlPostParmsCheck("refund_id"))
  8324. {
  8325. string eid = GetPostString("refund_id");
  8326. CeErpTradeRefund entity = null;
  8327. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8328. if (entity != null)
  8329. {
  8330. int apr = GetPostInt("approve");
  8331. if (apr == 0)
  8332. {
  8333. entity.RefundState = 1;
  8334. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8335. }
  8336. else if (apr == 1)
  8337. {
  8338. entity.RefundState = 3;
  8339. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8340. }
  8341. entity.modified = DateTime.Now;
  8342. entity.Update();
  8343. returnSuccessMsg("操作成功!");
  8344. return;
  8345. }
  8346. returnErrorMsg("找不到订单记录");
  8347. }
  8348. }
  8349. public void get_erp_billlist()
  8350. {
  8351. DataStruct dStruct = GetPostStruct();
  8352. List<string> lw = new List<string>();
  8353. string title = GetPostString("title");
  8354. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8355. string tid = GetPostString("tid");
  8356. string tids = GetPostString("tids");
  8357. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8358. if (tids.Length > 0)
  8359. {
  8360. tids = "'" + tids + "'";
  8361. tids = tids.Replace(",", "','");
  8362. lw.Add(string.Format("tid in ({0})", tids));
  8363. }
  8364. string shopname = GetPostString("shopname");
  8365. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8366. string buyernick = GetPostString("buyer_nick");
  8367. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8368. string customer = GetPostString("customer");
  8369. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8370. string date1 = GetPostString("date1");
  8371. string date2 = GetPostString("date2");
  8372. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8373. if (dw.Length > 0) lw.Add(dw);
  8374. string price1 = GetPostString("price1");
  8375. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8376. string price2 = GetPostString("price2");
  8377. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8378. string returndate1 = GetPostString("returndate1");
  8379. string returndate2 = GetPostString("returndate2");
  8380. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8381. if (dw1.Length > 0) lw.Add(dw1);
  8382. string billtype = GetPostString("billtype");
  8383. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8384. string billstate = GetPostString("billstate");
  8385. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8386. string usershop = CurrentUser.User.pemShop;
  8387. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8388. dStruct.Order = "createTime desc";
  8389. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8390. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8391. //foreach (DataRow dr in dt.Rows)
  8392. //{
  8393. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8394. //}
  8395. writeGridDataTableJson(dStruct.TotalCount, dt);
  8396. }
  8397. public void modify_erp_billinfo()
  8398. {
  8399. if (UrlPostParmsCheck("ID"))
  8400. {
  8401. string eid = GetPostString("ID");
  8402. CeErpBill bill_entity = null;
  8403. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8404. if (bill_entity != null)
  8405. {
  8406. bill_entity.tid = GetPostString("tid");
  8407. bill_entity.title = GetPostString("title");
  8408. bill_entity.tax = GetPostString("tax");
  8409. bill_entity.bank = GetPostString("bank");
  8410. bill_entity.bankac = GetPostString("bankac");
  8411. bill_entity.address = GetPostString("address");
  8412. bill_entity.phone = GetPostString("phone");
  8413. bill_entity.price = GetPostString("price");
  8414. bill_entity.productId = GetPostInt("ProductName");
  8415. bill_entity.num = GetPostInt("num");
  8416. bill_entity.unit = GetPostString("unit");
  8417. bill_entity.type = GetPostString("type");
  8418. bill_entity.sendType = GetPostString("SendType");
  8419. bill_entity.email = GetPostString("email");
  8420. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8421. bill_entity.shopName = GetPostString("ShopName");
  8422. bill_entity.applymemo = GetPostString("applymemo");
  8423. bill_entity.modifyTime = DateTime.Now;
  8424. bill_entity.createTime = DateTime.Now;
  8425. bill_entity.state = 0;
  8426. bill_entity.Update();
  8427. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8428. returnSuccessMsg("发票修改成功!");
  8429. return;
  8430. }
  8431. returnErrorMsg("找不到对应记录");
  8432. }
  8433. }
  8434. public void set_erp_invoicing()
  8435. {
  8436. if (UrlPostParmsCheck("id"))
  8437. {
  8438. try
  8439. {
  8440. string eid = GetPostString("id");
  8441. CeErpBill bill_entity = null;
  8442. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8443. if (bill_entity != null)
  8444. {
  8445. int ComId = GetPostInt("ComId");
  8446. //string memo = GetPostString("Memo");
  8447. int allInfo = GetPostInt("allinfo");
  8448. string clert = CurrentUser.User.Name;
  8449. //string detailValue = GetPostString("detailvalue");
  8450. string billId = bill_entity.billOrderId;
  8451. string[] billIdList = billId.Split(',');
  8452. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8453. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8454. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8455. {
  8456. billCount += 1;
  8457. }
  8458. if (billId.Length <= 0 || billIdList.Length != billCount)
  8459. {
  8460. bill_entity.billOrderId = "";
  8461. string prebill = "ltb";
  8462. for (int idx = 1; idx <= billCount; idx++)
  8463. {
  8464. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8465. string billoid = prebill + idx + dtstr;
  8466. bill_entity.billOrderId += billoid;
  8467. if (idx < billCount)
  8468. {
  8469. bill_entity.billOrderId += ",";
  8470. }
  8471. }
  8472. }
  8473. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8474. if (bill_entity.state == 5)
  8475. {
  8476. string errMsg = bill_entity.failerror;
  8477. string[] errlist = errMsg.Split('|');
  8478. string[] errTags = new string[errlist.Length];
  8479. for (int itag = 0; itag < errlist.Length; itag++)
  8480. {
  8481. if (errlist[itag].Length <= 0) continue;
  8482. errTags[itag] = errlist[itag].Split('&')[0];
  8483. }
  8484. for (int iii = 0; iii < errTags.Length; iii++)
  8485. {
  8486. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8487. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8488. if (billOrderList.Length >= erroBillOrderTag)
  8489. {
  8490. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8491. if (needModifyBillId.Length <= 19)
  8492. {
  8493. needModifyBillId = needModifyBillId + "1";
  8494. }
  8495. else
  8496. {
  8497. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8498. last = last + 1;
  8499. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8500. }
  8501. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8502. }
  8503. }
  8504. }
  8505. bool isHaveBillSucces = false;
  8506. string totalRes = "";
  8507. bill_entity.failerror = "";
  8508. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8509. {
  8510. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8511. totalRes += res;
  8512. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8513. {
  8514. isHaveBillSucces = true;
  8515. bill_entity.comId = ComId;
  8516. bill_entity.state = 1;
  8517. bill_entity.executeTime = DateTime.Now;
  8518. bill_entity.executeUser = clert;
  8519. }
  8520. else
  8521. {
  8522. bill_entity.state = 5;
  8523. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8524. }
  8525. }
  8526. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8527. bill_entity.Update();
  8528. if (isHaveBillSucces)
  8529. {
  8530. StringBuilder sql = new StringBuilder();
  8531. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8532. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8533. }
  8534. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8535. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8536. {
  8537. returnErrorMsg("开票失败");
  8538. }
  8539. else
  8540. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8541. return;
  8542. }
  8543. returnErrorMsg("找不到对应记录");
  8544. }
  8545. catch (Exception ex)
  8546. {
  8547. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8548. returnErrorMsg("操作失败");
  8549. }
  8550. }
  8551. }
  8552. public void get_erp_invoicing_back()
  8553. {
  8554. if (UrlPostParmsCheck("id"))
  8555. {
  8556. try
  8557. {
  8558. string id = GetPostString("id");
  8559. CeErpBill entiy = CeErpBill.Get(id);
  8560. if (entiy != null)
  8561. {
  8562. if (entiy.state == 0)
  8563. {
  8564. returnErrorMsg("发票还未开具");
  8565. return;
  8566. }
  8567. string[] billOrderList = entiy.billOrderId.Split(',');
  8568. int iTag = 0;
  8569. entiy.fplsh = "";
  8570. entiy.fpdm = "";
  8571. entiy.fphm = "";
  8572. foreach (string billOrderId in billOrderList)
  8573. {
  8574. iTag++;
  8575. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8576. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8577. {
  8578. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8579. try
  8580. {
  8581. Invoicing_get_response_Obj iObj = null;
  8582. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8583. if (iObj != null)
  8584. {
  8585. entiy.state = 2;
  8586. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8587. entiy.fpdm += iObj.list[0].c_fpdm;
  8588. entiy.fphm += iObj.list[0].c_fphm;
  8589. if (iTag < billOrderList.Length)
  8590. {
  8591. entiy.fplsh += ",";
  8592. entiy.fpdm += ",";
  8593. entiy.fphm += ",";
  8594. }
  8595. entiy.Update();
  8596. }
  8597. StringBuilder sql = new StringBuilder();
  8598. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8599. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8600. returnSuccessMsg("开票成功");
  8601. }
  8602. catch (Exception ex)
  8603. {
  8604. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8605. }
  8606. return;
  8607. }
  8608. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8609. {
  8610. var res_obj = new
  8611. {
  8612. data = "开票中"
  8613. };
  8614. string ro_json = JsonConvert.SerializeObject(res_obj);
  8615. returnSuccess(ro_json);
  8616. return;
  8617. }
  8618. else
  8619. {
  8620. int eidx = res.IndexOf("c_resultmsg");
  8621. int lidx = res.IndexOf("c_status");
  8622. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8623. entiy.state = 5;
  8624. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8625. entiy.Update();
  8626. returnErrorMsg("开票失败");
  8627. return;
  8628. }
  8629. }
  8630. }
  8631. }
  8632. catch (Exception ex)
  8633. {
  8634. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8635. }
  8636. return;
  8637. }
  8638. }
  8639. public void get_erp_invoicing()
  8640. {
  8641. if (UrlPostParmsCheck("id"))
  8642. {
  8643. try
  8644. {
  8645. string id = GetPostString("id");
  8646. CeErpBill entiy = CeErpBill.Get(id);
  8647. if (entiy != null)
  8648. {
  8649. if (entiy.state == 0)
  8650. {
  8651. returnErrorMsg("发票还未开具");
  8652. return;
  8653. }
  8654. if (entiy.sendType == "纸质发票")
  8655. {
  8656. if (entiy.img.Length <= 0)
  8657. {
  8658. returnErrorMsg("查无纸质发票");
  8659. return;
  8660. }
  8661. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8662. returnSuccess(returnres);
  8663. return;
  8664. }
  8665. string[] billOrderList = entiy.billOrderId.Split(',');
  8666. int iTag = 0;
  8667. string fpUrl = "";
  8668. entiy.fplsh = "";
  8669. entiy.fpdm = "";
  8670. entiy.fphm = "";
  8671. foreach (string billOrderId in billOrderList)
  8672. {
  8673. iTag++;
  8674. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8675. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8676. {
  8677. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8678. Invoicing_get_response_Obj iObj = null;
  8679. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8680. if (iObj != null)
  8681. {
  8682. //entiy.state = 2;
  8683. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8684. entiy.fpdm += iObj.list[0].c_fpdm;
  8685. entiy.fphm += iObj.list[0].c_fphm;
  8686. if (iTag < billOrderList.Length)
  8687. {
  8688. entiy.fplsh += ",";
  8689. entiy.fpdm += ",";
  8690. entiy.fphm += ",";
  8691. }
  8692. entiy.Update();
  8693. fpUrl += iObj.list[0].c_url + ",";
  8694. }
  8695. //returnSuccess(res);
  8696. StringBuilder sql = new StringBuilder();
  8697. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8698. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8699. }
  8700. else
  8701. {
  8702. int eidx = res.IndexOf("c_resultmsg");
  8703. //int lidx = res.IndexOf("c_status");
  8704. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8705. //开票失败
  8706. entiy.state = 5;
  8707. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8708. entiy.Update();
  8709. returnErrorMsg("开票失败");
  8710. return;
  8711. }
  8712. }
  8713. var returnObj = new
  8714. {
  8715. data = fpUrl
  8716. };
  8717. string ro_json = JsonConvert.SerializeObject(returnObj);
  8718. returnSuccess(ro_json);
  8719. }
  8720. }
  8721. catch (Exception ex)
  8722. {
  8723. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8724. }
  8725. return;
  8726. }
  8727. }
  8728. public void save_erp_billimg()
  8729. {
  8730. if (UrlPostParmsCheck("id"))
  8731. {
  8732. string eid = GetPostString("id");
  8733. CeErpBill bill_entity = null;
  8734. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8735. if (bill_entity != null)
  8736. {
  8737. bill_entity.img = GetPostString("img");
  8738. bill_entity.executeTime = DateTime.Now;
  8739. bill_entity.state = 2;
  8740. bill_entity.Update();
  8741. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8742. returnSuccessMsg("保存成功");
  8743. }
  8744. return;
  8745. }
  8746. }
  8747. public void upd_erp_billreturnback()
  8748. {
  8749. if (UrlPostParmsCheck("id"))
  8750. {
  8751. int eid = GetPostInt("id");
  8752. CeErpBill bill_entity = null;
  8753. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8754. if (bill_entity != null)
  8755. {
  8756. bill_entity.state = 3;
  8757. bill_entity.returnReason = GetPostString("reason");
  8758. bill_entity.Update();
  8759. returnSuccessMsg("驳回成功!");
  8760. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8761. }
  8762. return;
  8763. }
  8764. }
  8765. public void cancel_erp_bill()
  8766. {
  8767. if (UrlPostParmsCheck("id"))
  8768. {
  8769. int eid = GetPostInt("id");
  8770. int detailValue = GetPostInt("detailvalue");
  8771. CeErpBill bill_entity = null;
  8772. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8773. string cres = "";
  8774. string gres = "";
  8775. if (bill_entity != null)
  8776. {
  8777. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8778. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8779. {
  8780. int iTag = 0;
  8781. bill_entity.fplsh = "";
  8782. bill_entity.fpdm = "";
  8783. bill_entity.fphm = "";
  8784. foreach (string billOrderId in billOrderList)
  8785. {
  8786. iTag++;
  8787. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8788. if (gres.IndexOf("success") != -1)
  8789. {
  8790. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8791. Invoicing_get_response_Obj iObj = null;
  8792. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8793. if (iObj != null)
  8794. {
  8795. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8796. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8797. bill_entity.fphm += iObj.list[0].c_fphm;
  8798. if (iTag < billOrderList.Length)
  8799. {
  8800. bill_entity.fplsh += ",";
  8801. bill_entity.fpdm += ",";
  8802. bill_entity.fphm += ",";
  8803. }
  8804. bill_entity.Update();
  8805. }
  8806. }
  8807. else
  8808. {
  8809. returnErrorMsg(gres);
  8810. return;
  8811. }
  8812. }
  8813. }
  8814. if (bill_entity.sendType == "纸质发票")
  8815. {
  8816. //作废
  8817. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8818. //if (DateTime.Now.Month == extime.Month)
  8819. //{
  8820. //cres = taobaoHelper.cancel_invoicing(eid);
  8821. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8822. //{
  8823. bill_entity.state = 4;//已作废
  8824. bill_entity.Update();
  8825. returnSuccessMsg("发票已作废");
  8826. return;
  8827. //}
  8828. //else
  8829. //{
  8830. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8831. // bill_entity.Update();
  8832. // returnErrorMsg(cres);
  8833. // return;
  8834. //}
  8835. //}
  8836. //else
  8837. //{
  8838. // returnErrorMsg("纸质发票只能作废本月的发票");
  8839. // return;
  8840. //}
  8841. }
  8842. //红冲
  8843. int redTag = 0;
  8844. string[] fpdmList = bill_entity.fpdm.Split(',');
  8845. string[] fphmList = bill_entity.fphm.Split(',');
  8846. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8847. {
  8848. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8849. return;
  8850. }
  8851. foreach (string billOrderId in billOrderList)
  8852. {
  8853. redTag++;
  8854. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8855. cres += onecres;
  8856. cres += ",";
  8857. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8858. {
  8859. bill_entity.state = 4;//已作废
  8860. //bill_entity.Update();
  8861. //returnSuccessMsg("发票已红冲");
  8862. }
  8863. else if (onecres.IndexOf("重复冲红") != -1)
  8864. {
  8865. bill_entity.state = 4;//已作废
  8866. //bill_entity.Update();
  8867. //returnSuccessMsg("发票已红冲");
  8868. }
  8869. else
  8870. {
  8871. string errmsg = commonHelper.KeepChinese(onecres);
  8872. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8873. }
  8874. }
  8875. bill_entity.Update();
  8876. if (cres.IndexOf("失败") != -1)
  8877. returnErrorMsg("红冲失败");
  8878. else
  8879. returnSuccessMsg("发票已红冲");
  8880. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8881. return;
  8882. }
  8883. return;
  8884. }
  8885. }
  8886. public void del_erp_billorder()
  8887. {
  8888. if (UrlPostParmsCheck("id"))
  8889. {
  8890. string eid = GetPostString("id");
  8891. CeErpBill.Del(eid);
  8892. CeErpBill bill = CeErpBill.Get(eid);
  8893. if (bill != null)
  8894. {
  8895. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8896. }
  8897. returnSuccessMsg("删除成功");
  8898. }
  8899. }
  8900. public void finish_erp_bill()
  8901. {
  8902. if (UrlPostParmsCheck("ids"))
  8903. {
  8904. string eids = GetPostString("ids");
  8905. string[] list = eids.Split(',');
  8906. foreach (string eid in list)
  8907. {
  8908. CeErpBill bill = CeErpBill.Get(eid);
  8909. if (bill != null)
  8910. {
  8911. bill.state = 2;
  8912. bill.Update();
  8913. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8914. }
  8915. }
  8916. returnSuccessMsg("操作成功");
  8917. }
  8918. }
  8919. public void get_erp_returncash()
  8920. {
  8921. DataStruct dStruct = GetPostStruct();
  8922. List<string> lw = new List<string>();
  8923. string tid = GetPostString("tid");
  8924. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8925. string shopname = GetPostString("shopname");
  8926. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8927. string buyernick = GetPostString("buyer_nick");
  8928. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8929. string customer = GetPostString("customer");
  8930. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8931. string returndate1 = GetPostString("returndate1");
  8932. string returndate2 = GetPostString("returndate2");
  8933. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8934. if (dw.Length > 0) lw.Add(dw);
  8935. string finishDate1 = GetPostString("finishdate1");
  8936. string finishDate2 = GetPostString("finishdate2");
  8937. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8938. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8939. string returntype = GetPostString("returntype");
  8940. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8941. string returnvstate = GetPostString("returnvstate");
  8942. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8943. dStruct.Order = "created desc";
  8944. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8945. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8946. writeGridDataTableJson(dStruct.TotalCount, dt);
  8947. }
  8948. public void get_erp_staygoods()
  8949. {
  8950. DataStruct dStruct = GetPostStruct();
  8951. List<string> lw = new List<string>();
  8952. string tid = GetPostString("tid");
  8953. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8954. string shopname = GetPostString("shopname");
  8955. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8956. string wangwang = GetPostString("wangwang");
  8957. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8958. string customer = GetPostString("customer");
  8959. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8960. string returndate1 = GetPostString("returndate1");
  8961. string returndate2 = GetPostString("returndate2");
  8962. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8963. if (dw.Length > 0) lw.Add(dw);
  8964. string finishDate1 = GetPostString("finishdate1");
  8965. string finishDate2 = GetPostString("finishdate2");
  8966. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8967. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8968. string returnvstate = GetPostString("returnvstate");
  8969. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8970. string persuadetype = GetPostString("persuadetype");
  8971. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8972. string customerOrg = GetPostString("customerOrg");
  8973. if (customerOrg.Length > 0)
  8974. {
  8975. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8976. }
  8977. string designerorg = GetPostString("designerorg");
  8978. if (designerorg.Length > 0)
  8979. {
  8980. lw.Add(string.Format("OrgID = {0}", designerorg));
  8981. }
  8982. dStruct.Order = "creata_time desc";
  8983. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8984. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8985. writeGridDataTableJson(dStruct.TotalCount, dt);
  8986. }
  8987. public void upd_erp_staygoods()
  8988. {
  8989. if (UrlPostParmsCheck("id"))
  8990. {
  8991. int eid = GetPostInt("id");
  8992. CeErpStayGoods entity = null;
  8993. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8994. if (entity != null)
  8995. {
  8996. entity.audit_type = 1;
  8997. entity.audit_time = DateTime.Now;
  8998. entity.audit_u_id = CurrentUser.UserID;
  8999. entity.audit_u_name = CurrentUser.UserName;
  9000. entity.Update();
  9001. returnSuccessMsg("审核成功!");
  9002. return;
  9003. }
  9004. returnErrorMsg("找不到订单记录");
  9005. }
  9006. }
  9007. public void upd_erp_stayGoodsback()
  9008. {
  9009. if (UrlPostParmsCheck("id"))
  9010. {
  9011. int eid = GetPostInt("id");
  9012. CeErpStayGoods entity = null;
  9013. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  9014. if (entity != null)
  9015. {
  9016. entity.audit_text = GetPostString("reason");
  9017. entity.audit_type = 2;
  9018. entity.audit_time = DateTime.Now;
  9019. entity.audit_u_id = CurrentUser.UserID;
  9020. entity.audit_u_name = CurrentUser.UserName;
  9021. entity.Update();
  9022. returnSuccessMsg("退回成功!");
  9023. return;
  9024. }
  9025. returnErrorMsg("找不到订单记录");
  9026. }
  9027. }
  9028. public void upd_erp_returncashverify()
  9029. {
  9030. if (UrlPostParmsCheck("ID"))
  9031. {
  9032. int eid = GetPostInt("ID");
  9033. CeErpReturnCash entity = null;
  9034. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9035. if (entity != null)
  9036. {
  9037. entity.cashstate = 1;
  9038. entity.verifytime = DateTime.Now;
  9039. entity.verifyuserid = CurrentUser.UserID;
  9040. entity.Update();
  9041. returnSuccessMsg("审核成功!");
  9042. return;
  9043. }
  9044. returnErrorMsg("找不到订单记录");
  9045. }
  9046. }
  9047. public void upd_all_erp_returncashverify()
  9048. {
  9049. if (UrlPostParmsCheck("ID"))
  9050. {
  9051. String[] list = GetPostString("ID").Split(',');
  9052. CeErpReturnCash entity = null;
  9053. for (int i = 0; i < list.Length; i++)
  9054. {
  9055. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  9056. if (entity != null)
  9057. {
  9058. if (entity.cashstate == 1)
  9059. {
  9060. returnErrorMsg("已审核过的订单不需要在审核!");
  9061. return;
  9062. }
  9063. entity.cashstate = 1;
  9064. entity.verifytime = DateTime.Now;
  9065. entity.verifyuserid = CurrentUser.UserID;
  9066. entity.Update();
  9067. }
  9068. }
  9069. returnSuccessMsg("审核成功!");
  9070. return;
  9071. }
  9072. }
  9073. public void upd_erp_returncashback()
  9074. {
  9075. if (UrlPostParmsCheck("ID"))
  9076. {
  9077. int eid = GetPostInt("ID");
  9078. CeErpReturnCash entity = null;
  9079. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9080. if (entity != null)
  9081. {
  9082. entity.backreason = GetPostString("reason");
  9083. entity.cashstate = 2;
  9084. entity.verifytime = DateTime.Now;
  9085. entity.verifyuserid = CurrentUser.UserID;
  9086. entity.Update();
  9087. returnSuccessMsg("退回成功!");
  9088. return;
  9089. }
  9090. returnErrorMsg("找不到订单记录");
  9091. }
  9092. }
  9093. public void upd_erp_returnprice()
  9094. {
  9095. if (UrlPostParmsCheck("ID"))
  9096. {
  9097. int eid = GetPostInt("ID");
  9098. CeErpReturnCash entity = null;
  9099. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9100. if (entity != null)
  9101. {
  9102. if (entity.cashstate == 1)
  9103. {
  9104. returnErrorMsg("审核通过了不能改");
  9105. return;
  9106. }
  9107. entity.returnprice = GetPostDouble("returnprice");
  9108. entity.Update();
  9109. returnSuccessMsg("修改成功!");
  9110. return;
  9111. }
  9112. returnErrorMsg("找不到订单记录");
  9113. }
  9114. }
  9115. public void del_erp_returncash()
  9116. {
  9117. if (UrlPostParmsCheck("ID"))
  9118. {
  9119. int eid = GetPostInt("ID");
  9120. CeErpReturnCash.Del(eid);
  9121. returnSuccessMsg("操作成功");
  9122. return;
  9123. }
  9124. }
  9125. public void test_for_do_sql()
  9126. {
  9127. string sql = GetPostString("sqlstr");
  9128. if (sql.Length > 0)
  9129. {
  9130. try
  9131. {
  9132. DbHelper.DbConn.ExecuteNonQuery(sql);
  9133. var res_obj = new
  9134. {
  9135. data = "成功",
  9136. };
  9137. string ro_json = JsonConvert.SerializeObject(res_obj);
  9138. returnSuccess(ro_json);
  9139. }
  9140. catch (Exception ex)
  9141. {
  9142. var res_obj = new
  9143. {
  9144. data = ex.Message,
  9145. };
  9146. string ro_json = JsonConvert.SerializeObject(res_obj);
  9147. returnSuccess(ro_json);
  9148. }
  9149. }
  9150. }
  9151. public void get_user_info()
  9152. {
  9153. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  9154. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  9155. }
  9156. public void get_total_data()
  9157. {
  9158. int userId = CurrentUser.UserID;
  9159. string sql = "";
  9160. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9161. {
  9162. 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);
  9163. }
  9164. else
  9165. {
  9166. 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 " +
  9167. "(select ID from CE_ErpUser where ID = {0}) d " +
  9168. "left join " +
  9169. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  9170. ") a on d.ID = a.id left join " +
  9171. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  9172. ") b on a.id = b.id1 left join" +
  9173. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  9174. ") c on a.id = c.id2;", userId);
  9175. }
  9176. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9177. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9178. }
  9179. public void get_date_area_total_data2()
  9180. {
  9181. int userId = CurrentUser.UserID;
  9182. string date_type = GetPostString("timetype");
  9183. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9184. string sql = "";
  9185. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9186. {
  9187. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  9188. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9189. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9190. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9191. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9192. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9193. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9194. ") a on e.ID = a.id left join " +
  9195. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9196. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9197. ") b on a.id = b.id1 " +
  9198. "left join " +
  9199. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9200. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9201. ") c on a.id = c.id2 " +
  9202. "left join " +
  9203. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9204. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9205. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9206. }
  9207. else
  9208. {
  9209. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9210. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9211. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9212. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9213. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9214. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9215. ") a on e.ID = a.id left join " +
  9216. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9217. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9218. ") c on a.id = c.id2 " +
  9219. "left join " +
  9220. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9221. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9222. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9223. }
  9224. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9225. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9226. }
  9227. public void get_date_area_total_data()
  9228. {
  9229. int userId = CurrentUser.UserID;
  9230. string date_type = GetPostString("timetype");
  9231. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9232. string date1 = searchDT[0].ToString();
  9233. string date2 = searchDT[1].ToString();
  9234. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9235. {
  9236. SqlParameter[] sqlParameter ={
  9237. new SqlParameter("@userId", SqlDbType.Int,4),
  9238. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9239. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9240. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9241. };
  9242. sqlParameter[0].Value = userId;
  9243. sqlParameter[1].Value = date1;
  9244. sqlParameter[2].Value = date2;
  9245. sqlParameter[3].Direction = ParameterDirection.Output;
  9246. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9247. string res = sqlParameter[3].Value.ToString();
  9248. var res_obj = new
  9249. {
  9250. data = res
  9251. };
  9252. string ro_json = JsonConvert.SerializeObject(res_obj);
  9253. returnSuccess(ro_json);
  9254. }
  9255. else
  9256. {
  9257. SqlParameter[] sqlParameter ={
  9258. new SqlParameter("@userId", SqlDbType.Int,4),
  9259. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9260. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9261. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9262. };
  9263. sqlParameter[0].Value = userId;
  9264. sqlParameter[1].Value = date1;
  9265. sqlParameter[2].Value = date2;
  9266. sqlParameter[3].Direction = ParameterDirection.Output;
  9267. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9268. string res = sqlParameter[3].Value.ToString();
  9269. var res_obj = new
  9270. {
  9271. data = res
  9272. };
  9273. string ro_json = JsonConvert.SerializeObject(res_obj);
  9274. returnSuccess(ro_json);
  9275. }
  9276. //writeGridDataViewJson(dt.Rows.Count, dv);
  9277. }
  9278. public void get_order_list()
  9279. {
  9280. string strFields = GetPostString("paraFields");
  9281. string strOrder = GetPostString("paraOrder");
  9282. string strWhere = GetPostString("paraWhere");
  9283. string strPageSize = GetPostString("paraPageSize");
  9284. DataStruct dStruct = GetPostStruct();
  9285. dStruct.PageSize = int.Parse(strPageSize);
  9286. dStruct.Fileds = strFields;
  9287. dStruct.Order = strOrder;
  9288. dStruct.MainWhere = strWhere;
  9289. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9290. writeGridDataTableJson(dStruct.TotalCount, dt);
  9291. }
  9292. ////获取待开始订单列表
  9293. //public void get_wait_design_order_list()
  9294. //{
  9295. // string date_type = GetPostString("date_type");
  9296. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9297. // DataStruct dStruct = GetPostStruct();
  9298. // dStruct.PageSize = 1000;
  9299. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9300. // List<string> lw = new List<string>();
  9301. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9302. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9303. // dStruct.Order = "WaitDesignTime asc";
  9304. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9305. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9306. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9307. //}
  9308. //获取完成单量排名
  9309. public void get_finish_order_count_ranking()
  9310. {
  9311. /* string date_type = GetPostString("date_type");
  9312. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9313. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9314. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9315. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9316. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9317. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9318. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9319. writeGridDataTableJson(0, new DataTable());
  9320. }
  9321. public void get_finish_order_amount_ranking()
  9322. {
  9323. /*string date_type = GetPostString("date_type");
  9324. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9325. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9326. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9327. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9328. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9329. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9330. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9331. writeGridDataTableJson(0, new DataTable());
  9332. }
  9333. public void get_finish_refund_count_ranking()
  9334. {
  9335. string date_type = GetPostString("date_type");
  9336. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9337. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9338. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9339. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9340. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9341. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9342. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9343. writeGridDataTableJson(dt.Rows.Count, dt);
  9344. }
  9345. public void get_finish_refund_amount_ranking()
  9346. {
  9347. string date_type = GetPostString("date_type");
  9348. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9349. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9350. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9351. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9352. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9353. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9354. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9355. writeGridDataTableJson(dt.Rows.Count, dt);
  9356. }
  9357. public void set_erp_finishorder_director()
  9358. {
  9359. if (UrlPostParmsCheck("ctid"))
  9360. {
  9361. string eid = GetPostString("ctid");
  9362. CeErpTradeCell entity = null;
  9363. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9364. if (entity != null)
  9365. {
  9366. entity.OrderState = 8;
  9367. entity.Update();
  9368. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9369. returnSuccessMsg("操作成功!");
  9370. return;
  9371. }
  9372. returnErrorMsg("找不到记录");
  9373. }
  9374. }
  9375. public void get_erp_placeregistlist()
  9376. {
  9377. DataStruct dStruct = GetPostStruct();
  9378. List<string> lw = new List<string>();
  9379. string outsid = GetPostString("outsid");
  9380. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9381. string memo = GetPostString("memo");
  9382. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9383. string filename = GetPostString("filename");
  9384. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9385. string islate = GetPostString("islate");
  9386. if (islate.Length > 0)
  9387. {
  9388. if (islate == "1")
  9389. lw.Add(string.Format("OutLate>0"));
  9390. else
  9391. lw.Add(string.Format("OutLate=0"));
  9392. }
  9393. string placedate1 = GetPostString("placedate1");
  9394. string placedate2 = GetPostString("placedate2");
  9395. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9396. if (dw.Length > 0) lw.Add(dw);
  9397. string deliveryDate1 = GetPostString("deliverydate1");
  9398. string deliveryDate2 = GetPostString("deliverydate2");
  9399. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9400. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9401. dStruct.Order = "ID desc";
  9402. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9403. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9404. writeGridDataTableJson(dStruct.TotalCount, dt);
  9405. }
  9406. public void ins_erp_placeregist()
  9407. {
  9408. if (UrlPostParmsCheck("id"))
  9409. {
  9410. string eid = GetPostString("id");
  9411. CeErpPlaceRegister entity = null;
  9412. if (eid == "0")//新增
  9413. {
  9414. entity = new CeErpPlaceRegister();
  9415. string xdTime = GetPostString("placeTime");
  9416. if (xdTime.Length > 0)
  9417. {
  9418. entity.PlactTime = Convert.ToDateTime(xdTime);
  9419. }
  9420. string fhTime = GetPostString("deliveryTime");
  9421. if (fhTime.Length > 0)
  9422. {
  9423. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9424. }
  9425. string preTime = GetPostString("preOutTime");
  9426. if (preTime.Length > 0)
  9427. {
  9428. entity.PreOutTime = Convert.ToDateTime(preTime);
  9429. }
  9430. entity.DeliveryCount = GetPostInt("deliveryCount");
  9431. entity.ReceiveCount = GetPostInt("receiveCount");
  9432. entity.OutSid = GetPostString("outSid");
  9433. entity.FileName = GetPostString("fileName");
  9434. entity.Memo = GetPostString("memo");
  9435. entity.AddUserId = CurrentUser.UserID;
  9436. entity.CreateTime = DateTime.Now;
  9437. entity.Img = GetPostString("img");
  9438. entity.Supplier = GetPostInt("supplier");
  9439. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9440. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9441. {
  9442. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9443. DateTime dt2 = (DateTime)entity.PreOutTime;
  9444. TimeSpan span = dt1.Subtract(dt2);
  9445. if (span.Days > 0)
  9446. {
  9447. entity.OutLate = span.Days;
  9448. }
  9449. }
  9450. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9451. entity.Create();
  9452. returnSuccessMsg("添加成功!");
  9453. return;
  9454. }
  9455. else //修改
  9456. {
  9457. entity = CeErpPlaceRegister.Get(eid);
  9458. if (entity != null)
  9459. {
  9460. string xdTime = GetPostString("placeTime");
  9461. if (xdTime.Length > 0)
  9462. {
  9463. entity.PlactTime = Convert.ToDateTime(xdTime);
  9464. }
  9465. string fhTime = GetPostString("deliveryTime");
  9466. if (fhTime.Length > 0)
  9467. {
  9468. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9469. }
  9470. string preTime = GetPostString("preOutTime");
  9471. if (preTime.Length > 0)
  9472. {
  9473. entity.PreOutTime = Convert.ToDateTime(preTime);
  9474. }
  9475. entity.DeliveryCount = GetPostInt("deliveryCount");
  9476. entity.ReceiveCount = GetPostInt("receiveCount");
  9477. if (entity.DeliveryCount == entity.ReceiveCount)
  9478. {
  9479. entity.CurState = "已完成";
  9480. }
  9481. else
  9482. {
  9483. entity.CurState = "未完成";
  9484. }
  9485. entity.OutSid = GetPostString("outSid");
  9486. entity.FileName = GetPostString("fileName");
  9487. entity.Memo = GetPostString("memo");
  9488. entity.Img = GetPostString("img");
  9489. entity.Supplier = GetPostInt("supplier");
  9490. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9491. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9492. {
  9493. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9494. DateTime dt2 = (DateTime)entity.PreOutTime;
  9495. TimeSpan span = dt1.Subtract(dt2);
  9496. if (span.Days > 0)
  9497. {
  9498. entity.OutLate = span.Days;
  9499. }
  9500. }
  9501. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9502. entity.Update();
  9503. returnSuccessMsg("修改成功");
  9504. return;
  9505. }
  9506. returnErrorMsg("找不到对应的记录");
  9507. return;
  9508. }
  9509. }
  9510. returnErrorMsg("缺少必要参数");
  9511. }
  9512. public void del_erp_placeregist()
  9513. {
  9514. string eid = GetPostString("id");
  9515. CeErpPlaceRegister.Del(eid);
  9516. returnSuccessMsg("删除成功!");
  9517. return;
  9518. }
  9519. public void ins_erp_placeregistbyorder()
  9520. {
  9521. string ctid = GetPostString("ctid");
  9522. if (ctid.Length > 0)
  9523. {
  9524. StringBuilder sql = new StringBuilder();
  9525. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9526. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9527. if (dt.Rows.Count > 0)
  9528. {
  9529. foreach (DataRow dr in dt.Rows)
  9530. {
  9531. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9532. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9533. entity.AddUserId = CurrentUser.UserID;
  9534. entity.tid = dr["tid"].ToString();
  9535. entity.Did = Convert.ToString(dr["ctid"]);
  9536. entity.splitTag = dr["SplitTag"].ToString();
  9537. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9538. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9539. if (pre_ctid.Length > 0)
  9540. {
  9541. sellmemo = sellmemo.Replace(pre_ctid, "");
  9542. }
  9543. sellmemo = sellmemo.Replace("[", "");
  9544. sellmemo = sellmemo.Replace("]", "");
  9545. entity.FileName = sellmemo;
  9546. string count = dr["ProductCount"].ToString();
  9547. int usecount = commonHelper.getIntCountFromString(count);
  9548. entity.DeliveryCount = usecount;
  9549. entity.CurState = "未完成";
  9550. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9551. {
  9552. entity.Supplier = 24;//dl手提袋定制
  9553. }
  9554. else
  9555. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9556. entity.CreateTime = DateTime.Now;
  9557. entity.Create();
  9558. }
  9559. returnSuccessMsg("操作成功");
  9560. return;
  9561. }
  9562. returnErrorMsg("没有找到对应订单");
  9563. return;
  9564. }
  9565. returnErrorMsg("缺少订单编号");
  9566. return;
  9567. }
  9568. public void get_erp_persuadelist()
  9569. {
  9570. DataStruct dStruct = GetPostStruct();
  9571. List<string> lw = new List<string>();
  9572. string ctid = GetPostString("ctid");
  9573. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9574. string shopname = GetPostString("shopname");
  9575. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9576. string buyernick = GetPostString("buyer_nick");
  9577. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9578. string customer = GetPostString("customer");
  9579. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9580. string returndate1 = GetPostString("returndate1");
  9581. string returndate2 = GetPostString("returndate2");
  9582. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9583. if (dw.Length > 0) lw.Add(dw);
  9584. string finishDate1 = GetPostString("finishdate1");
  9585. string finishDate2 = GetPostString("finishdate2");
  9586. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9587. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9588. string persuadetype = GetPostString("persuadetype");
  9589. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9590. string returnvstate = GetPostString("returnvstate");
  9591. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9592. dStruct.Order = "created desc";
  9593. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9594. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9595. writeGridDataTableJson(dStruct.TotalCount, dt);
  9596. }
  9597. public void upd_erp_returnpersuadeback()
  9598. {
  9599. if (UrlPostParmsCheck("ID"))
  9600. {
  9601. int eid = GetPostInt("ID");
  9602. CeErpPersuade entity = null;
  9603. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9604. if (entity != null)
  9605. {
  9606. entity.backreason = GetPostString("reason");
  9607. entity.pstate = 2;
  9608. entity.verifytime = DateTime.Now;
  9609. entity.verifyuserid = CurrentUser.UserID;
  9610. entity.Update();
  9611. returnSuccessMsg("退回成功!");
  9612. return;
  9613. }
  9614. returnErrorMsg("找不到订单记录");
  9615. }
  9616. }
  9617. public void upd_erp_returnpersuadeverify()
  9618. {
  9619. if (UrlPostParmsCheck("ID"))
  9620. {
  9621. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9622. {
  9623. returnErrorMsg("暂无权限审核");
  9624. return;
  9625. }
  9626. int eid = GetPostInt("ID");
  9627. CeErpPersuade entity = null;
  9628. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9629. if (entity != null)
  9630. {
  9631. entity.pstate = 1;
  9632. entity.verifytime = DateTime.Now;
  9633. entity.verifyuserid = CurrentUser.UserID;
  9634. entity.Update();
  9635. returnSuccessMsg("审核成功!");
  9636. return;
  9637. }
  9638. returnErrorMsg("找不到订单记录");
  9639. }
  9640. }
  9641. public void del_erp_persuade()
  9642. {
  9643. if (UrlPostParmsCheck("ID"))
  9644. {
  9645. int eid = GetPostInt("ID");
  9646. CeErpPersuade.Del(eid);
  9647. returnSuccessMsg("操作成功");
  9648. return;
  9649. }
  9650. }
  9651. public void get_erp_oldcustoupload()
  9652. {
  9653. DataStruct dStruct = GetPostStruct();
  9654. List<string> lw = new List<string>();
  9655. string buyernick = GetPostString("buyer_nick");
  9656. if (buyernick.Length > 0)
  9657. {
  9658. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9659. }
  9660. else
  9661. return;
  9662. dStruct.Order = "pay_time desc";
  9663. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9664. DataTable dt = null;
  9665. dt = WebCache.GetData("view_erptradecell", dStruct);
  9666. writeGridDataTableJson(dStruct.TotalCount, dt);
  9667. }
  9668. public void get_erp_checkorderlist()
  9669. {
  9670. DataStruct dStruct = GetPostStruct();
  9671. List<string> lw = new List<string>();
  9672. string tid = GetPostString("ctid");
  9673. if (tid.Length > 0)
  9674. {
  9675. string select_tid = getTidByCtid(tid);
  9676. lw.Add(string.Format("tid='{0}'", select_tid));
  9677. }
  9678. string shopname = GetPostString("shopname");
  9679. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9680. string buyernick = GetPostString("buyer_nick");
  9681. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9682. string customer = GetPostString("customer");
  9683. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9684. string design = GetPostString("design");
  9685. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9686. string orderState = GetPostString("orderState");
  9687. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9688. string address = GetPostString("address");
  9689. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9690. string sellermemo = GetPostString("seller_memo");
  9691. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9692. string supplier = GetPostString("supplier");
  9693. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9694. {
  9695. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9696. }
  9697. else
  9698. {
  9699. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9700. }
  9701. string date1 = GetPostString("date1");
  9702. string date2 = GetPostString("date2");
  9703. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9704. if (dw.Length > 0) lw.Add(dw);
  9705. string placedate1 = GetPostString("placedate1");
  9706. string placedate2 = GetPostString("placedate2");
  9707. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9708. if (fdw.Length > 0) lw.Add(fdw);
  9709. string price1 = GetPostString("price1");
  9710. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9711. string price2 = GetPostString("price2");
  9712. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9713. string checkst = GetPostString("checkstate");
  9714. if (checkst.Length > 0 && "10".Equals(checkst))
  9715. {
  9716. lw.Add(string.Format("CheckOut>0"));
  9717. }
  9718. else
  9719. {
  9720. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9721. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9722. }
  9723. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9724. {
  9725. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9726. }
  9727. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9728. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9729. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9730. writeGridDataTableJson(dStruct.TotalCount, dt);
  9731. }
  9732. public void ins_erp_startCheck()
  9733. {
  9734. if (UrlPostParmsCheck("ctid"))
  9735. {
  9736. string eid = GetPostString("ctid");
  9737. CeErpTradeCell entity = null;
  9738. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9739. if (entity != null)
  9740. {
  9741. entity.MemoOpt = 4;
  9742. entity.UpdateTime = DateTime.Now;
  9743. entity.Update();
  9744. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9745. CeErpSukuraData.createInfo(entity.ctid, 6);
  9746. returnSuccessMsg("操作成功!");
  9747. return;
  9748. }
  9749. returnErrorMsg("找不到记录");
  9750. }
  9751. }
  9752. public void upd_erp_sendXlw()
  9753. {
  9754. if (UrlPostParmsCheck("ctid"))
  9755. {
  9756. string eid = GetPostString("ctid");
  9757. CeErpTradeCell entity = null;
  9758. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9759. if (entity != null)
  9760. {
  9761. if (entity.IsSendGift == 1)
  9762. {
  9763. returnErrorMsg("请勿重复标记");
  9764. return;
  9765. }
  9766. entity.IsSendGift = 1;
  9767. entity.Update();
  9768. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9769. returnSuccessMsg("操作成功!");
  9770. return;
  9771. }
  9772. returnErrorMsg("找不到记录");
  9773. }
  9774. }
  9775. public void cancel_sendXlw()
  9776. {
  9777. if (UrlPostParmsCheck("ctid"))
  9778. {
  9779. string eid = GetPostString("ctid");
  9780. CeErpTradeCell entity = null;
  9781. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9782. if (entity != null)
  9783. {
  9784. if (entity.IsSendGift == 0)
  9785. {
  9786. returnErrorMsg("未标记小礼物");
  9787. return;
  9788. }
  9789. entity.IsSendGift = 0;
  9790. entity.Update();
  9791. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9792. returnSuccessMsg("操作成功!");
  9793. return;
  9794. }
  9795. returnErrorMsg("找不到记录");
  9796. }
  9797. }
  9798. public void get_erp_designbill()
  9799. {
  9800. DataStruct dStruct = GetPostStruct();
  9801. List<string> lw = new List<string>();
  9802. int isMy = GetInt("my");
  9803. if (isMy == 1)
  9804. {
  9805. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9806. }
  9807. string tid = GetPostString("tid");
  9808. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9809. string userName = GetPostString("design");
  9810. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9811. string price1 = GetPostString("price1");
  9812. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9813. string price2 = GetPostString("price2");
  9814. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9815. string rePrice1 = GetPostString("rePrice1");
  9816. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9817. string rePrice2 = GetPostString("rePrice2");
  9818. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9819. string designerType = GetPostString("designerType");
  9820. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9821. string orderState = GetPostString("orderState");
  9822. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9823. string endTime1 = GetPostString("endTime1");
  9824. string endTime2 = GetPostString("endTime2");
  9825. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9826. if (dw.Length > 0) lw.Add(dw);
  9827. string isDk = GetPostString("isDk");
  9828. if (isDk == "1")
  9829. {
  9830. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9831. }
  9832. else if (isDk == "0")
  9833. {
  9834. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9835. }
  9836. dStruct.Order = "oid, create_time desc";
  9837. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9838. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9839. writeGridDataTableJson(dStruct.TotalCount, dt);
  9840. }
  9841. public void upd_erp_designerbill()
  9842. {
  9843. if (UrlPostParmsCheck("ID"))
  9844. {
  9845. string eid = GetPostString("ID");
  9846. CeErpDesignerBill entity = null;
  9847. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9848. if (entity != null)
  9849. {
  9850. if (GetPostDouble("designerpirce") > 0)
  9851. {
  9852. entity.realPrice = GetPostDouble("designerpirce");
  9853. entity.update_time = DateTime.Now;
  9854. entity.update_u_id = CurrentUser.UserID;
  9855. entity.update_u_name = CurrentUser.UserName;
  9856. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9857. entity.Update();
  9858. returnSuccessMsg("操作成功!");
  9859. return;
  9860. }
  9861. else
  9862. {
  9863. entity.price = GetPostDouble("price");
  9864. entity.update_time = DateTime.Now;
  9865. entity.update_u_id = CurrentUser.UserID;
  9866. entity.update_u_name = CurrentUser.UserName;
  9867. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9868. entity.Update();
  9869. returnSuccessMsg("操作成功!");
  9870. return;
  9871. }
  9872. }
  9873. returnErrorMsg("找不到记录");
  9874. }
  9875. }
  9876. public void audit_erp_designerbill()
  9877. {
  9878. if (UrlPostParmsCheck("ID"))
  9879. {
  9880. string eid = GetPostString("ID");
  9881. CeErpDesignerBill entity = null;
  9882. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9883. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9884. if (entity != null)
  9885. {
  9886. entity.realPrice = GetPostDouble("designerpirce");
  9887. entity.update_time = DateTime.Now;
  9888. entity.update_u_id = CurrentUser.UserID;
  9889. entity.update_u_name = CurrentUser.UserName;
  9890. entity.isAudit = 1;
  9891. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9892. entity.Update();
  9893. if (orderEntity != null)
  9894. {
  9895. orderEntity.IsReadTag = 3;
  9896. orderEntity.Update();
  9897. }
  9898. returnSuccessMsg("操作成功!");
  9899. return;
  9900. }
  9901. returnErrorMsg("找不到记录");
  9902. }
  9903. }
  9904. public void all_audit_erp_designerbill()
  9905. {
  9906. if (UrlPostParmsCheck("idList"))
  9907. {
  9908. string[] list = GetPostString("idList").Split(',');
  9909. CeErpDesignerBill entity = null;
  9910. for (int i = 0; i < list.Length; i++)
  9911. {
  9912. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9913. if (entity == null) return;
  9914. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9915. if (orderEntity == null) return;
  9916. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9917. entity.update_time = DateTime.Now;
  9918. entity.update_u_id = CurrentUser.UserID;
  9919. entity.update_u_name = CurrentUser.UserName;
  9920. entity.isAudit = 1;
  9921. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9922. entity.Update();
  9923. orderEntity.IsReadTag = 3;
  9924. orderEntity.Update();
  9925. }
  9926. returnSuccessMsg("操作成功!");
  9927. return;
  9928. }
  9929. }
  9930. public void get_erp_sameorders()
  9931. {
  9932. if (UrlPostParmsCheck("ctid"))
  9933. {
  9934. string eid = GetPostString("ctid");
  9935. CeErpTradeCell entity = null;
  9936. entity = CeErpTradeCell.GetByCtid(eid);
  9937. if (entity != null)
  9938. {
  9939. StringBuilder sql = new StringBuilder();
  9940. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9941. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9942. var res = new
  9943. {
  9944. data = dt.Rows.Count
  9945. };
  9946. string ro_jsond = JsonConvert.SerializeObject(res);
  9947. returnSuccess(ro_jsond);
  9948. return;
  9949. }
  9950. returnErrorMsg("未找到订单");
  9951. return;
  9952. }
  9953. returnErrorMsg("缺少必要的参数");
  9954. }
  9955. public void get_erp_islasthavesameorder()
  9956. {
  9957. if (UrlPostParmsCheck("ctid"))
  9958. {
  9959. string eid = GetPostString("ctid");
  9960. string[] ctidList = eid.Split(',');
  9961. StringBuilder sql = new StringBuilder();
  9962. string tisCtid = "";
  9963. foreach (string ctid in ctidList)
  9964. {
  9965. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9966. if (entity != null)
  9967. {
  9968. sql = new StringBuilder();
  9969. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9970. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9971. if (dth.Rows.Count > 0)
  9972. {
  9973. tisCtid += entity.ctid;
  9974. tisCtid += ",";
  9975. }
  9976. }
  9977. }
  9978. if (tisCtid.Length > 0)
  9979. {
  9980. var res = new
  9981. {
  9982. data = tisCtid
  9983. };
  9984. string ro_jsond = JsonConvert.SerializeObject(res);
  9985. returnSuccess(ro_jsond);
  9986. }
  9987. else
  9988. {
  9989. var res = new
  9990. {
  9991. data = ""
  9992. };
  9993. string ro_jsond = JsonConvert.SerializeObject(res);
  9994. returnSuccess(ro_jsond);
  9995. }
  9996. return;
  9997. }
  9998. returnErrorMsg("缺少必要的参数");
  9999. }
  10000. public void file_client_down_url()
  10001. {
  10002. if (!UrlPostParmsCheck("userId"))
  10003. {
  10004. returnErrorMsg("缺少必要的参数");
  10005. }
  10006. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  10007. }
  10008. public void checkout_form_data()
  10009. {
  10010. if (!UrlPostParmsCheck("tid"))
  10011. {
  10012. returnErrorMsg("缺少必要的参数");
  10013. }
  10014. string tid = GetPostString("tid");
  10015. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  10016. if (ceErpOrderFormData != null)
  10017. {
  10018. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  10019. returnSuccess(ro_jsond);
  10020. return;
  10021. }
  10022. returnErrorMsg("尚未有文件!");
  10023. }
  10024. public void back_supplier_audit()
  10025. {
  10026. int userId = CurrentUser.UserID;
  10027. StringBuilder sql = new StringBuilder();
  10028. 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);
  10029. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10030. if (dt.Rows.Count > 0)
  10031. {
  10032. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10033. }
  10034. else
  10035. {
  10036. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10037. }
  10038. }
  10039. public void back_supplier_query()
  10040. {
  10041. string eid = GetPostString("ctid");
  10042. if (eid != "")
  10043. {
  10044. StringBuilder sql = new StringBuilder();
  10045. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  10046. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10047. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10048. }
  10049. else
  10050. {
  10051. returnErrorMsg("找不到订单记录");
  10052. return;
  10053. }
  10054. }
  10055. public void verified_to_order()
  10056. {
  10057. int userId = CurrentUser.UserID;
  10058. StringBuilder sql = new StringBuilder();
  10059. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  10060. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10061. if (dt.Rows.Count > 0)
  10062. {
  10063. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10064. }
  10065. else
  10066. {
  10067. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10068. }
  10069. }
  10070. public void upd_supplier_audit()
  10071. {
  10072. if (UrlPostParmsCheck("ctid"))
  10073. {
  10074. string eid = GetPostString("ctid");
  10075. string reason = GetPostString("returnreason");
  10076. CeErpTradeCell entity = null;
  10077. CeWithdraw withdraw = null;
  10078. withdraw = CeWithdraw.GetByTid(eid);
  10079. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  10080. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  10081. {
  10082. if (withdraw != null)
  10083. {
  10084. if (!withdraw.userid.Equals(CurrentUser.UserID))
  10085. {
  10086. returnSuccessMsg("您没有权限操作!");
  10087. return;
  10088. }
  10089. else
  10090. {
  10091. if (reason.Equals("1"))
  10092. {
  10093. if (entity.OrderState == -1)
  10094. {
  10095. if (entity.FinishPlaceTime == null)
  10096. {
  10097. entity.OrderState = 2;
  10098. }
  10099. else
  10100. {
  10101. entity.OrderState = 6;
  10102. }
  10103. }
  10104. entity.Update();
  10105. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10106. if (withdraw != null)
  10107. {
  10108. withdraw.status = int.Parse(reason);
  10109. withdraw.Update();
  10110. }
  10111. returnSuccessMsg("操作成功!");
  10112. return;
  10113. }
  10114. else
  10115. {
  10116. withdraw.status = int.Parse(reason);
  10117. withdraw.acknowledgingtime = DateTime.Now;
  10118. withdraw.Update();
  10119. returnSuccessMsg("查看详细请点击线下订单查询");
  10120. return;
  10121. }
  10122. }
  10123. }
  10124. // 第一个字符是 'N'
  10125. }
  10126. if (eid[0] != 'N')
  10127. {
  10128. }
  10129. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  10130. {
  10131. entity.IsVerifyToSupplier = false;
  10132. entity.IsReturn = 1;
  10133. entity.ReturnTime = DateTime.Now;
  10134. entity.ReturnReason = reason;
  10135. if (entity.OrderState == 6)
  10136. {
  10137. entity.OrderState = 5;
  10138. }
  10139. entity.Update();
  10140. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  10141. if (withdraw != null)
  10142. {
  10143. withdraw.status = int.Parse(reason);
  10144. withdraw.Update();
  10145. }
  10146. returnSuccessMsg("操作成功!");
  10147. return;
  10148. }
  10149. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  10150. {
  10151. ;
  10152. if (withdraw != null)
  10153. {
  10154. withdraw.status = int.Parse(reason);
  10155. withdraw.acknowledgingtime = DateTime.Now;
  10156. withdraw.Update();
  10157. returnSuccessMsg("供应商取消撤回!");
  10158. return;
  10159. }
  10160. }
  10161. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  10162. {
  10163. if (entity.OrderState == -1)
  10164. {
  10165. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  10166. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10167. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  10168. {
  10169. returnErrorMsg("台湾客户需填写身份证!");
  10170. return;
  10171. }
  10172. if (commonHelper.isFarAddress(ceErpTrade.receiver_state) && ceErpTrade.delivery_paymant == 0 && entity.IsSF != 2)
  10173. {
  10174. returnErrorMsg("偏远地区需要填写物流费!");
  10175. return;
  10176. }
  10177. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  10178. {
  10179. returnErrorMsg("订单spu没有确认无法通过审核!");
  10180. return;
  10181. }
  10182. if (entity.FinishPlaceTime == null)
  10183. {
  10184. entity.OrderState = 2;
  10185. }
  10186. else
  10187. {
  10188. entity.OrderState = 3;
  10189. }
  10190. commonHelper.getCytPrice(entity);
  10191. if ((entity.OtherMemo.Contains("老客户") || entity.OtherMemo.Contains("老顾客")) && entity.OtherMemo.Contains("改稿"))
  10192. {
  10193. tmcHelper.dealOldCustomerEntityTag(ref entity, ceErpTrade);
  10194. }
  10195. if (entity.IsSample > 1 || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物"))
  10196. {
  10197. entity.OrderState = 6;
  10198. }
  10199. }
  10200. entity.Update();
  10201. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10202. if (withdraw != null)
  10203. {
  10204. withdraw.status = int.Parse(reason);
  10205. withdraw.Update();
  10206. }
  10207. returnSuccessMsg("操作成功!");
  10208. return;
  10209. }
  10210. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10211. {
  10212. if (withdraw == null)
  10213. {
  10214. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10215. return;
  10216. }
  10217. }
  10218. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10219. {
  10220. if (withdraw != null)
  10221. {
  10222. withdraw.status = int.Parse(reason);
  10223. withdraw.acknowledgingtime = DateTime.Now;
  10224. withdraw.Update();
  10225. returnSuccessMsg("查看详细请点击线下订单查询");
  10226. return;
  10227. }
  10228. }
  10229. return;
  10230. }
  10231. }
  10232. //校验报价
  10233. public void refund_order_tip()
  10234. {
  10235. int userid = CurrentUser.UserID;
  10236. int sectionId = CurrentUser.UserPost.OrgID;
  10237. StringBuilder sql = new StringBuilder();
  10238. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10239. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10240. List<string> ids = new List<string>();
  10241. if (dth.Rows.Count > 0)
  10242. {
  10243. foreach (DataRow dr in dth.Rows)
  10244. {
  10245. ids.Add(dr["ID"].ToString());
  10246. }
  10247. try
  10248. {
  10249. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10250. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10251. }
  10252. catch (Exception ex)
  10253. {
  10254. }
  10255. }
  10256. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10257. }
  10258. public void refund_order_Design()
  10259. {
  10260. int userid = CurrentUser.UserID;
  10261. int sectionId = CurrentUser.UserPost.OrgID;
  10262. StringBuilder sql = new StringBuilder();
  10263. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10264. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10265. List<string> ids = new List<string>();
  10266. if (dth.Rows.Count > 0)
  10267. {
  10268. foreach (DataRow dr in dth.Rows)
  10269. {
  10270. ids.Add(dr["ID"].ToString());
  10271. }
  10272. try
  10273. {
  10274. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10275. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10276. }
  10277. catch (Exception ex)
  10278. {
  10279. }
  10280. }
  10281. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10282. }
  10283. public void change_order_info()
  10284. {
  10285. int userid = CurrentUser.UserID;
  10286. StringBuilder sql = new StringBuilder();
  10287. 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);
  10288. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10289. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10290. }
  10291. public void change_win_mome()
  10292. {
  10293. if (UrlPostParmsCheck("id,ctid"))
  10294. {
  10295. string id = GetPostString("id");
  10296. string ctid = GetPostString("ctid");
  10297. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10298. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10299. if (ce == null || ceErpMessageTip == null)
  10300. {
  10301. returnSuccessMsg("未找到对应的订单!");
  10302. return;
  10303. }
  10304. if (ce.OrderState >= 5)
  10305. {
  10306. ceErpMessageTip.isVisit = true;
  10307. ceErpMessageTip.Update();
  10308. returnSuccessMsg("已上传文件无法修改!");
  10309. return;
  10310. }
  10311. int type = GetPostInt("type");
  10312. string content = GetPostString("content");
  10313. if (type == 0)
  10314. {
  10315. content = content.Replace("(", "(");
  10316. content = content.Replace(")", ")");
  10317. string check = MidStrEx(content, "(", ")").Trim();
  10318. if (string.IsNullOrEmpty(check))
  10319. {
  10320. returnSuccessMsg("文件名格式不正确");
  10321. return;
  10322. }
  10323. }
  10324. ce.seller_memo = content;
  10325. ce.Update();
  10326. ceErpMessageTip.isVisit = true;
  10327. ceErpMessageTip.Update();
  10328. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10329. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10330. ApiVo apiVo = new ApiVo();
  10331. apiVo.orderNumber = ce.ctid;
  10332. apiVo.actionName = "demandDesign";
  10333. apiVo.orderRemarks = content;
  10334. apiVo.demandExamine = type + 1;
  10335. designHelper.API_WorkCore(apiVo);//demandDesign
  10336. returnSuccessMsg("修改成功!");
  10337. }
  10338. }
  10339. public static string MidStrEx(string sourse, string startstr, string endstr)
  10340. {
  10341. string result = string.Empty;
  10342. int startindex, endindex;
  10343. try
  10344. {
  10345. startindex = sourse.IndexOf(startstr);
  10346. if (startindex == -1)
  10347. return result;
  10348. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10349. endindex = tmpstr.IndexOf(endstr);
  10350. if (endindex == -1)
  10351. return result;
  10352. result = tmpstr.Remove(endindex);
  10353. }
  10354. catch (Exception ex)
  10355. {
  10356. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10357. }
  10358. return result;
  10359. }
  10360. public void refund_order_list()
  10361. {
  10362. int userid = CurrentUser.UserID;
  10363. int sectionId = CurrentUser.UserPost.OrgID;
  10364. StringBuilder sql = new StringBuilder();
  10365. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10366. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10367. DataStruct dStruct = GetPostStruct();
  10368. DataTable dt = null;
  10369. List<string> ids = new List<string>();
  10370. List<string> tids = new List<string>();
  10371. if (dth.Rows.Count > 0)
  10372. {
  10373. foreach (DataRow dr in dth.Rows)
  10374. {
  10375. tids.Add("'" + dr["tid"].ToString() + "'");
  10376. ids.Add(dr["id"].ToString());
  10377. }
  10378. try
  10379. {
  10380. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10381. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10382. List<string> lw = new List<string>();
  10383. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10384. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10385. dt = WebCache.GetData("view_orderlist", dStruct);
  10386. }
  10387. catch (Exception ex)
  10388. {
  10389. }
  10390. }
  10391. writeGridDataTableJson(dStruct.TotalCount, dt);
  10392. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10393. }
  10394. //新增
  10395. public void order_batch_downloads()
  10396. {
  10397. string ceid = GetPostString("tid");
  10398. String[] tid = ceid.Split(',');
  10399. order_batch_caiyingtong(tid);
  10400. /* (string success, string errors) = UploadFiles(tid);
  10401. returnSuccessMsg(success + errors);*/
  10402. return;
  10403. }
  10404. //报价接口
  10405. public void Get_To_Quote()
  10406. {
  10407. string ceid = GetPostString("ctid");
  10408. if (ceid != null)
  10409. {
  10410. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10411. if (entity != null)
  10412. {
  10413. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10414. {
  10415. return;
  10416. }
  10417. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10418. double price = 0;
  10419. if (cp == null)
  10420. {
  10421. JObject jsonObject12 = new JObject
  10422. {
  10423. { "UserId", "77886" },
  10424. { "Pwd", "lt666888" },
  10425. { "Filename", entity.seller_memo }
  10426. };
  10427. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10428. JObject jsonObjects1 = JObject.Parse(response1);
  10429. string ms1g = (string)jsonObjects1["msg"];
  10430. if (ms1g == "报价成功")
  10431. {
  10432. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10433. string data = (string)jsonObject1["price"];
  10434. 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 + "');";
  10435. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10436. returnSuccessMsg("获取报价成功:" + data);
  10437. price = Convert.ToDouble(data);
  10438. }
  10439. else
  10440. {
  10441. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10442. return;
  10443. }
  10444. }
  10445. String[] beizhu = entity.seller_memo.Split('-');
  10446. String chanp = "";
  10447. if (beizhu.Length > 0)
  10448. {
  10449. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10450. }
  10451. else
  10452. {
  10453. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10454. }
  10455. JObject jsonObject = new JObject
  10456. {
  10457. { "UserId", "77886" },
  10458. { "Pwd", "lt666888" },
  10459. { "Filename", chanp }
  10460. };
  10461. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10462. JObject jsonObjects = JObject.Parse(response);
  10463. string msg = (string)jsonObjects["msg"];
  10464. if (msg == "报价成功")
  10465. {
  10466. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10467. string data = (string)jsonObject1["price"];
  10468. 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 + "');";
  10469. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10470. returnSuccessMsg("获取报价成功:" + data);
  10471. price = Convert.ToDouble(data);
  10472. }
  10473. else
  10474. {
  10475. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10476. return;
  10477. }
  10478. if (price > 0)
  10479. {
  10480. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10481. if (ceErpTradeCellExtend == null)
  10482. {
  10483. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10484. ceErpTradeCellExtend.ctid = entity.ctid;
  10485. ceErpTradeCellExtend.payment_cyt = price;
  10486. ceErpTradeCellExtend.Create();
  10487. }
  10488. else
  10489. {
  10490. ceErpTradeCellExtend.payment_cyt = price;
  10491. ceErpTradeCellExtend.Update();
  10492. }
  10493. }
  10494. return;
  10495. }
  10496. }
  10497. else
  10498. {
  10499. returnErrorMsg("请至少选择一条数据");
  10500. return;
  10501. }
  10502. }
  10503. //新增
  10504. public void order_To_Supplier()
  10505. {
  10506. string ceid = GetPostString("tid");
  10507. String[] tid = ceid.Split(',');
  10508. if (tid.Length > 0)
  10509. {
  10510. try
  10511. {
  10512. for (int i = 0; i < tid.Length; i++)
  10513. {
  10514. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10515. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10516. entity.SupplierId = suid;
  10517. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10518. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10519. entity.Update();
  10520. }
  10521. }
  10522. catch (Exception ex)
  10523. {
  10524. returnErrorMsg("自动匹配供应商失败");
  10525. return;
  10526. }
  10527. }
  10528. else
  10529. {
  10530. returnErrorMsg("请至少选择一条数据");
  10531. return;
  10532. }
  10533. returnSuccessMsg("自动匹配供应商成功");
  10534. return;
  10535. }
  10536. public (string, string) UploadFiles(string[] urls)
  10537. {
  10538. string success = "";
  10539. string errors = "";
  10540. int userid = CurrentUser.UserID;
  10541. foreach (string url in urls)
  10542. {
  10543. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10544. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10545. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10546. {
  10547. JObject jsonObject = new JObject
  10548. {
  10549. { "Userid", "77886" },
  10550. { "pwd", "cyt86435015" },
  10551. { "content", base64FileContent },
  10552. { "ext", Path.GetExtension(fileName) }
  10553. };
  10554. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10555. JObject jsonObjects = JObject.Parse(response);
  10556. string msg = (string)jsonObjects["msg"];
  10557. if (msg.Equals("上传成功"))
  10558. {
  10559. success += url + " 上传成功";
  10560. }
  10561. else
  10562. {
  10563. errors += url + " 上传失败";
  10564. }
  10565. }
  10566. else
  10567. {
  10568. errors += url + " 格式出现问题";
  10569. }
  10570. }
  10571. if (urls.Length == 0)
  10572. {
  10573. return (success, errors);
  10574. }
  10575. return (success, errors);
  10576. }
  10577. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10578. {
  10579. return true; //总是接受
  10580. }
  10581. public static string HttpPost(string url, string param = null)
  10582. {
  10583. HttpWebRequest request;
  10584. //如果是发送HTTPS请求
  10585. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10586. {
  10587. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10588. request = WebRequest.Create(url) as HttpWebRequest;
  10589. request.ProtocolVersion = HttpVersion.Version10;
  10590. }
  10591. else
  10592. {
  10593. request = WebRequest.Create(url) as HttpWebRequest;
  10594. }
  10595. request.Method = "POST";
  10596. request.ContentType = "application/json";
  10597. request.Accept = "*/*";
  10598. request.Timeout = 120000;
  10599. request.AllowAutoRedirect = false;
  10600. StreamWriter requestStream = null;
  10601. WebResponse response = null;
  10602. string responseStr = null;
  10603. try
  10604. {
  10605. requestStream = new StreamWriter(request.GetRequestStream());
  10606. requestStream.Write(param);
  10607. requestStream.Close();
  10608. response = request.GetResponse();
  10609. if (response != null)
  10610. {
  10611. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10612. responseStr = reader.ReadToEnd();
  10613. reader.Close();
  10614. }
  10615. }
  10616. catch (Exception ex)
  10617. {
  10618. return ex.Message;
  10619. }
  10620. finally
  10621. {
  10622. request = null;
  10623. requestStream = null;
  10624. response = null;
  10625. }
  10626. return responseStr;
  10627. }
  10628. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10629. {
  10630. string base64FileContent;
  10631. string fileName;
  10632. using (WebClient webClient = new WebClient())
  10633. {
  10634. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10635. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10636. {
  10637. using (Stream stream = response.GetResponseStream())
  10638. {
  10639. using (MemoryStream memoryStream = new MemoryStream())
  10640. {
  10641. stream.CopyTo(memoryStream);
  10642. byte[] fileBytes = memoryStream.ToArray();
  10643. base64FileContent = Convert.ToBase64String(fileBytes);
  10644. fileName = response.Headers["Content-Disposition"];
  10645. if (!string.IsNullOrEmpty(fileName))
  10646. {
  10647. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10648. if (index >= 0)
  10649. {
  10650. fileName = fileName.Substring(index + 9).Trim('\"');
  10651. }
  10652. }
  10653. else
  10654. {
  10655. fileName = Path.GetFileName(downloadUrl);
  10656. }
  10657. }
  10658. }
  10659. }
  10660. }
  10661. return (fileName, base64FileContent);
  10662. }
  10663. //新增
  10664. public void order_batch_caiyingtong(string[] downloadUrls)
  10665. {
  10666. try
  10667. {
  10668. //遍历文件
  10669. DataStruct dStruct = GetPostStruct();
  10670. DataTable dt = null;
  10671. int userid = CurrentUser.UserID;
  10672. List<string> ids = new List<string>();//失败组
  10673. List<string> tids = new List<string>();
  10674. using (WebClient webClient = new WebClient())
  10675. {
  10676. foreach (var url in downloadUrls)
  10677. {
  10678. try
  10679. {
  10680. tids.Add("'" + url + "'");
  10681. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10682. if (entity != null)
  10683. {
  10684. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10685. if (cp == null)
  10686. {
  10687. JObject jsonObject = new JObject
  10688. {
  10689. { "Userid", "77886" },
  10690. { "pwd", "lt666888" },
  10691. { "Filename",entity.seller_memo }
  10692. };
  10693. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10694. JObject jsonObjects = JObject.Parse(response);
  10695. string msg = (string)jsonObjects["msg"];
  10696. if (msg == "报价成功")
  10697. {
  10698. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10699. DownloadAndConvertToBase64(url1);
  10700. }
  10701. else
  10702. {
  10703. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10704. }
  10705. }
  10706. else
  10707. {
  10708. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10709. JObject jsonObject = new JObject
  10710. {
  10711. { "Userid", "77886" },
  10712. { "pwd", "lt666888" },
  10713. { "Filename",chanp }
  10714. };
  10715. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10716. JObject jsonObjects = JObject.Parse(response);
  10717. string msg = (string)jsonObjects["msg"];
  10718. if (msg == "报价成功")
  10719. {
  10720. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10721. DownloadAndConvertToBase64(url1);
  10722. }
  10723. else
  10724. {
  10725. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10726. }
  10727. }
  10728. }
  10729. // 上传文件到FTP
  10730. }
  10731. catch (Exception ex)
  10732. {
  10733. Console.WriteLine($"An error occurred: {ex.Message}");
  10734. }
  10735. }
  10736. List<string> lw = new List<string>();
  10737. lw.Add(string.Format("( OrderState < 6 )"));
  10738. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10739. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10740. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10741. if (dt.Rows.Count > 0)
  10742. {
  10743. foreach (DataRow dr in dt.Rows)
  10744. {
  10745. ids.Add(dr["ctid"].ToString());
  10746. }
  10747. }
  10748. String ErrorMsgs = "";
  10749. foreach (String id in ids)
  10750. {
  10751. ErrorMsgs += id + ",";
  10752. }
  10753. if (ErrorMsgs.Length > 1)
  10754. {
  10755. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10756. }
  10757. if (ErrorMsgs.Length < 1)
  10758. {
  10759. ErrorMsgs = "上传成功";
  10760. returnSuccessMsg(ErrorMsgs);
  10761. }
  10762. else
  10763. {
  10764. returnErrorMsg("以下订单" + ErrorMsgs);
  10765. }
  10766. }
  10767. // 删除文件夹及其内容
  10768. /* Directory.Delete(localDirectory, true);*/
  10769. }
  10770. catch { }
  10771. }
  10772. public void get_center_data()
  10773. {
  10774. int userId = CurrentUser.UserID;
  10775. string postCode = CurrentUser.UserPost.Post.Code;
  10776. List<string> lw = new List<string>();
  10777. List<string> ww = new List<string>();
  10778. DateTime currentTime = DateTime.Now;
  10779. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10780. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10781. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10782. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10783. string sql = " SELECT ";
  10784. string startTime = "2023-10-01 11:22:31";
  10785. //设计
  10786. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10787. {
  10788. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10789. 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));
  10790. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10791. 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));
  10792. }
  10793. //客服
  10794. else if (postCode == "CustomerService" || postCode == "Director")
  10795. {
  10796. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10797. 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));
  10798. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10799. 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));
  10800. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10801. 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));
  10802. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10803. 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));
  10804. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10805. 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));
  10806. }
  10807. //售后
  10808. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10809. {
  10810. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10811. 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));
  10812. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10813. 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));
  10814. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10815. 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));
  10816. }
  10817. //下单部
  10818. else if (postCode == "Place" || postCode == "PlaceMr")
  10819. {
  10820. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10821. 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));
  10822. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10823. 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));
  10824. }
  10825. //车间
  10826. else if (postCode == "Supplier")
  10827. {
  10828. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10829. 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));
  10830. }
  10831. DataTable dt = new DataTable();
  10832. if (lw.Count > 0)
  10833. {
  10834. sql += string.Join(" , ", lw);
  10835. sql += " FROM ";
  10836. sql += string.Join(" , ", ww);
  10837. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10838. }
  10839. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10840. }
  10841. public void get_center_data_list()
  10842. {
  10843. int userId = CurrentUser.UserID;
  10844. string postCode = CurrentUser.UserPost.Post.Code;
  10845. string shopIds = CurrentUser.User.pemShop;
  10846. DataStruct dStruct = GetPostStruct();
  10847. List<string> lw = new List<string>();
  10848. DateTime currentTime = DateTime.Now;
  10849. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10850. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10851. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10852. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10853. string startTime = "2023-10-01 11:22:31";
  10854. int order_type = GetPostInt("order_type");
  10855. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10856. {
  10857. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10858. if (order_type == 0)
  10859. {
  10860. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10861. }
  10862. else if (order_type == 3)
  10863. {
  10864. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10865. }
  10866. else
  10867. {
  10868. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10869. }
  10870. }
  10871. //客服
  10872. if (postCode == "CustomerService" || postCode == "Director")
  10873. {
  10874. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10875. if (order_type == 0)
  10876. {
  10877. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10878. }
  10879. else if (order_type == 1)
  10880. {
  10881. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10882. }
  10883. else if (order_type == 2)
  10884. {
  10885. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10886. }
  10887. else if (order_type == 3)
  10888. {
  10889. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10890. }
  10891. else if (order_type == 4)
  10892. {
  10893. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10894. }
  10895. else
  10896. {
  10897. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10898. }
  10899. }
  10900. //售后
  10901. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10902. {
  10903. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10904. if (shopIds != "")
  10905. {
  10906. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10907. }
  10908. if (order_type == 2)
  10909. {
  10910. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10911. }
  10912. else if (order_type == 4)
  10913. {
  10914. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10915. }
  10916. else if (order_type == 5)
  10917. {
  10918. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10919. }
  10920. else
  10921. {
  10922. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10923. }
  10924. }
  10925. //下单部
  10926. if (postCode == "Place" || postCode == "PlaceMr")
  10927. {
  10928. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10929. if (shopIds != "")
  10930. {
  10931. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10932. }
  10933. else if (order_type == 1)
  10934. {
  10935. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10936. }
  10937. else if (order_type == 2)
  10938. {
  10939. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10940. }
  10941. else
  10942. {
  10943. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10944. }
  10945. }
  10946. //车间
  10947. if (postCode == "Supplier")
  10948. {
  10949. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10950. if (order_type == 5)
  10951. {
  10952. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10953. }
  10954. else
  10955. {
  10956. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10957. }
  10958. }
  10959. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10960. dStruct.Fileds = "tid,ctid";
  10961. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10962. writeGridDataTableJson(dStruct.TotalCount, dt);
  10963. }
  10964. public void aftersale_audit_master()
  10965. {
  10966. if (UrlPostParmsCheck("ctid"))
  10967. {
  10968. string ctid = GetPostString("ctid");
  10969. if (ctid.Length > 0)
  10970. {
  10971. bool result = aftersale_data_change(ctid);
  10972. if (result)
  10973. {
  10974. returnSuccessMsg("修改成功!");
  10975. return;
  10976. }
  10977. }
  10978. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10979. }
  10980. }
  10981. public void aftersale_batch_audit_master()
  10982. {
  10983. if (UrlPostParmsCheck("ctids"))
  10984. {
  10985. string ctids = GetPostString("ctids");
  10986. if (ctids.Length > 0)
  10987. {
  10988. List<string> list = new List<string>();
  10989. string[] ctid_list = ctids.Split(',');
  10990. foreach (var item in ctid_list)
  10991. {
  10992. bool result = aftersale_data_change(item);
  10993. if (!result)
  10994. {
  10995. list.Add(item);
  10996. }
  10997. }
  10998. if (list.Count > 0)
  10999. {
  11000. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  11001. return;
  11002. }
  11003. returnSuccessMsg("修改成功!");
  11004. return;
  11005. }
  11006. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11007. }
  11008. }
  11009. public bool aftersale_data_change(string ctid)
  11010. {
  11011. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11012. if (ceErpTradeCell != null)
  11013. {
  11014. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  11015. ceErpTradeCell.AfterSaleSupplierState = 0;
  11016. StringBuilder sql = new StringBuilder();
  11017. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  11018. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11019. CeErpTradeResponsible.DelByTid(ctid, 0);
  11020. 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 == "不理赔")
  11021. {
  11022. CeErpTradeResponsible.DelByTid(ctid, 1);
  11023. ceErpTradeCell.AfterSaleSupplierState = 1;
  11024. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11025. ceErpTradeCell.AfterSaleState = 4;
  11026. }
  11027. else
  11028. {
  11029. ceErpTradeCell.AfterSaleState = 3;
  11030. }
  11031. bool needCyt = false;
  11032. if (dt != null)
  11033. {
  11034. if (dt.Rows.Count == 1)
  11035. {
  11036. bool isEnd = false;
  11037. foreach (DataRow dr in dt.Rows)
  11038. {
  11039. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11040. {
  11041. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11042. isEnd = true;
  11043. }
  11044. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  11045. {
  11046. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11047. isEnd = true;
  11048. }
  11049. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11050. {
  11051. needCyt = true;
  11052. }
  11053. }
  11054. if (isEnd)
  11055. {
  11056. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11057. ceErpTradeCell.AfterSaleState = 4;
  11058. ceErpTradeCell.AfterSaleSupplierState = 1;
  11059. }
  11060. }
  11061. else
  11062. {
  11063. bool isAll = true;
  11064. foreach (DataRow dr in dt.Rows)
  11065. {
  11066. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11067. {
  11068. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11069. continue;
  11070. }
  11071. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  11072. {
  11073. string path = "";
  11074. int OrgID = 0;
  11075. if (!Convert.IsDBNull(dr["OrgPath"]))
  11076. {
  11077. path = dr["OrgPath"].ToString();
  11078. }
  11079. if (!Convert.IsDBNull(dr["OrgID"]))
  11080. {
  11081. OrgID = Convert.ToInt32(dr["OrgID"]);
  11082. }
  11083. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  11084. {
  11085. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11086. continue;
  11087. }
  11088. }
  11089. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11090. {
  11091. needCyt = true;
  11092. }
  11093. isAll = false;
  11094. }
  11095. if (isAll)
  11096. {
  11097. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11098. ceErpTradeCell.AfterSaleState = 4;
  11099. ceErpTradeCell.AfterSaleSupplierState = 1;
  11100. }
  11101. }
  11102. }
  11103. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  11104. {
  11105. commonHelper.sendCytAfterSale(ceErpTradeCell);
  11106. }
  11107. if (ceErpTradeCell.AfterSaleState == 4)
  11108. {
  11109. ApiVo apiVo = new ApiVo();
  11110. apiVo.orderNumber = ceErpTradeCell.ctid;
  11111. apiVo.actionName = "afterOver";
  11112. designHelper.API_WorkCore(apiVo); //afterOver
  11113. }
  11114. ceErpTradeCell.Update();
  11115. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  11116. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  11117. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  11118. return true;
  11119. }
  11120. return false;
  11121. }
  11122. public void get_erp_wechatorder()
  11123. {
  11124. DataStruct dStruct = GetPostStruct();
  11125. List<string> lw = new List<string>();
  11126. string tid = GetPostString("tid");
  11127. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11128. string shopname = GetPostString("shopname");
  11129. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11130. string buyernick = GetPostString("buyer_nick");
  11131. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11132. string customer = GetPostString("customer");
  11133. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11134. string returndate1 = GetPostString("returndate1");
  11135. string returndate2 = GetPostString("returndate2");
  11136. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11137. if (dw.Length > 0) lw.Add(dw);
  11138. string finishDate1 = GetPostString("finishdate1");
  11139. string finishDate2 = GetPostString("finishdate2");
  11140. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11141. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11142. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11143. dStruct.Order = "created desc";
  11144. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11145. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  11146. writeGridDataTableJson(dStruct.TotalCount, dt);
  11147. }
  11148. public void get_erp_wechatlist_sumprice()
  11149. {
  11150. DataStruct dStruct = GetPostStruct();
  11151. List<string> lw = new List<string>();
  11152. string tid = GetPostString("tid");
  11153. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11154. string shopname = GetPostString("shopname");
  11155. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11156. string buyernick = GetPostString("buyer_nick");
  11157. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11158. string customer = GetPostString("customer");
  11159. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11160. string returndate1 = GetPostString("returndate1");
  11161. string returndate2 = GetPostString("returndate2");
  11162. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11163. if (dw.Length > 0) lw.Add(dw);
  11164. string finishDate1 = GetPostString("finishdate1");
  11165. string finishDate2 = GetPostString("finishdate2");
  11166. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11167. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11168. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11169. string mainWhere = string.Join(" and ", lw.ToArray());
  11170. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  11171. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  11172. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  11173. decimal total = 0;
  11174. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  11175. {
  11176. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  11177. }
  11178. var res = new
  11179. {
  11180. data = total
  11181. };
  11182. string ro_jsond = JsonConvert.SerializeObject(res);
  11183. returnSuccess(ro_jsond);
  11184. return;
  11185. }
  11186. public void get_erp_qr_waitdeliverylist()
  11187. {
  11188. DataStruct dStruct = GetPostStruct();
  11189. List<string> lw = new List<string>();
  11190. string tid = GetPostString("ctid");
  11191. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  11192. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11193. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  11194. var res_objz = new
  11195. {
  11196. restype = 1,
  11197. data = dt
  11198. };
  11199. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  11200. returnSuccess(ro_jsonz);
  11201. }
  11202. public void get_erp_yield_list()
  11203. {
  11204. DataStruct dStruct = GetPostStruct();
  11205. List<string> lw = new List<string>();
  11206. string tid = GetPostString("ctid");
  11207. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11208. string shopname = GetPostString("shopname");
  11209. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11210. string buyernick = GetPostString("buyer_nick");
  11211. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11212. //if (tid.Length == 0 && buyernick.Length == 0)
  11213. //{
  11214. // lw.Add(string.Format("IsRefund<={0}", 1));
  11215. //}
  11216. string customer = GetPostString("customer");
  11217. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11218. string design = GetPostString("design");
  11219. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11220. string orderState = GetPostString("orderState");
  11221. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11222. string address = GetPostString("address");
  11223. 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));
  11224. string sellermemo = GetPostString("seller_memo");
  11225. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11226. string supplier = GetPostString("supplier");
  11227. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11228. string OrderArea = GetPostString("order_area");
  11229. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11230. string placedate1 = GetPostString("placedate1");
  11231. string placedate2 = GetPostString("placedate2");
  11232. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11233. if (fdw.Length > 0) lw.Add(fdw);
  11234. string price1 = GetPostString("price1");
  11235. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11236. string price2 = GetPostString("price2");
  11237. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11238. string unusualCon = GetPostString("unusualcon");
  11239. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11240. string posTag = CurrentUser.UserPost.Post.Code;
  11241. if (posTag == "Supplier")
  11242. {
  11243. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11244. }
  11245. lw.Add(string.Format("OrderState = 6 "));
  11246. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11247. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11248. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11249. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11250. writeGridDataTableJson(dStruct.TotalCount, dt);
  11251. }
  11252. public void change_erp_sup_state()
  11253. {
  11254. if (UrlPostParmsCheck("ctid"))
  11255. {
  11256. string ctid = GetPostString("ctid");
  11257. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11258. if (ceErpTradeCell != null)
  11259. {
  11260. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11261. if (ceErpTradeCellExtend == null)
  11262. {
  11263. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11264. ceErpTradeCellExtend.ctid = ctid;
  11265. ceErpTradeCellExtend.SupState = 1;
  11266. ceErpTradeCellExtend.Create();
  11267. }
  11268. else
  11269. {
  11270. ceErpTradeCellExtend.SupState = 1;
  11271. ceErpTradeCellExtend.Update();
  11272. }
  11273. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11274. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11275. return;
  11276. }
  11277. returnErrorMsg("找不到订单");
  11278. }
  11279. }
  11280. public void supplier_all_downs()
  11281. {
  11282. if (UrlPostParmsCheck("tids"))
  11283. {
  11284. string tids = GetPostString("tids");
  11285. if (tids != null && tids.Length > 0)
  11286. {
  11287. StringBuilder sql = new StringBuilder();
  11288. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11289. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11290. sql = new StringBuilder();
  11291. 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, "下载设计文件");
  11292. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11293. string[] list = tids.Split(',');
  11294. foreach (string ctid in list)
  11295. {
  11296. CeErpSukuraData.createInfo(ctid, 3);
  11297. }
  11298. designHelper.api_approveDesign(tids); //approveDesign
  11299. returnSuccessMsg("下载成功!");
  11300. return;
  11301. }
  11302. returnErrorMsg("下载订单更新失败");
  11303. }
  11304. }
  11305. public void uploaderFileSuccess()
  11306. {
  11307. if (UrlPostParmsCheck("fileName"))
  11308. {
  11309. string fileName = GetPostString("fileName");
  11310. ApiVo apiVo = new ApiVo();
  11311. apiVo.orderNumber = fileName;
  11312. apiVo.actionName = "finishDesign";
  11313. designHelper.API_WorkCore(apiVo);//finishDesign
  11314. returnSuccessMsg("");
  11315. }
  11316. }
  11317. public void get_sample2_order()
  11318. {
  11319. if (UrlPostParmsCheck("ctid"))
  11320. {
  11321. string ctid = GetPostString("ctid");
  11322. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11323. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11324. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11325. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11326. double total = 0.0;
  11327. double order_price = 0.0;
  11328. if (dt_bu.Rows.Count > 0)
  11329. {
  11330. foreach (DataRow dr in dt_bu.Rows)
  11331. {
  11332. total += Convert.ToDouble(dr["payment"]);
  11333. }
  11334. }
  11335. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11336. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11337. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11338. string tid = ctid.Replace("S_", "");
  11339. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11340. double paymant = 0.0;
  11341. if (entity != null)
  11342. {
  11343. paymant = entity.payment;
  11344. }
  11345. string return_reason = "";
  11346. if (dt_after != null && dt_after.Rows.Count > 0)
  11347. {
  11348. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11349. }
  11350. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11351. }
  11352. }
  11353. public void get_erp_design_status()
  11354. {
  11355. string designName = GetPostString("designName");
  11356. DataStruct dStruct = GetPostStruct();
  11357. if (designName.Length > 0)
  11358. {
  11359. 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";
  11360. sql_user += " and Name like '%" + designName + "%'";
  11361. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11362. List<string> ids_list = new List<string>();
  11363. if (user_table.Rows.Count > 0)
  11364. {
  11365. foreach (DataRow item in user_table.Rows)
  11366. {
  11367. ids_list.Add(item["id"].ToString());
  11368. string ids_s = item["TeamIds"].ToString();
  11369. if (ids_s.Length > 0)
  11370. {
  11371. ids_list.AddRange(ids_s.Split(','));
  11372. }
  11373. }
  11374. }
  11375. HashSet<string> set = new HashSet<string>(ids_list);
  11376. ids_list = set.ToList();
  11377. if (ids_list.Count > 0)
  11378. {
  11379. 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));
  11380. dStruct.MainWhere = sql;
  11381. DataTable dt = null;
  11382. dt = WebCache.GetData("view_ErpUser", dStruct);
  11383. writeGridDataTableJson(dStruct.TotalCount, dt);
  11384. }
  11385. }
  11386. }
  11387. public void change_erp_order_price()
  11388. {
  11389. string ctid = GetPostString("ctid");
  11390. double price = GetPostDouble("price");
  11391. if (ctid.Length > 0)
  11392. {
  11393. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11394. if (ceErpTradeCellExtend == null)
  11395. {
  11396. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11397. ceErpTradeCellExtend.ctid = ctid;
  11398. ceErpTradeCellExtend.payment_cyt = price;
  11399. ceErpTradeCellExtend.Create();
  11400. }
  11401. else
  11402. {
  11403. ceErpTradeCellExtend.payment_cyt = price;
  11404. ceErpTradeCellExtend.Update();
  11405. }
  11406. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11407. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11408. {
  11409. ceErpDataSendOrderInfo.isSync = false;
  11410. ceErpDataSendOrderInfo.Update();
  11411. }
  11412. if (ceErpDataSendOrderInfo == null)
  11413. {
  11414. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11415. ceErpDataSendOrderInfo.isSync = false;
  11416. ceErpDataSendOrderInfo.ctid = ctid;
  11417. ceErpDataSendOrderInfo.Create();
  11418. }
  11419. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11420. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11421. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11422. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11423. {
  11424. dataSendOrderBean dataSendOrderBean = null;
  11425. foreach (DataRow item in dth.Rows)
  11426. {
  11427. try
  11428. {
  11429. dataSendOrderBean = new dataSendOrderBean();
  11430. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11431. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11432. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11433. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11434. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11435. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11436. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11437. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11438. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11439. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11440. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11441. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11442. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11443. if (result != null)
  11444. {
  11445. if ("0".Equals(result.errcode))
  11446. {
  11447. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11448. }
  11449. else
  11450. {
  11451. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11452. }
  11453. }
  11454. }
  11455. catch (Exception ex)
  11456. {
  11457. }
  11458. }
  11459. }
  11460. returnSuccessMsg("修改成功!");
  11461. return;
  11462. }
  11463. returnErrorMsg("找不到订单");
  11464. }
  11465. public void find_he_together()
  11466. {
  11467. string ctid = GetPostString("ctid");
  11468. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11469. List<string> list = new List<string>();
  11470. if (ceErpTradeCell != null)
  11471. {
  11472. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11473. {
  11474. 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);
  11475. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11476. if (table != null && table.Rows.Count > 0)
  11477. {
  11478. foreach (TableRow row in table.Rows)
  11479. {
  11480. }
  11481. }
  11482. }
  11483. }
  11484. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11485. }
  11486. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11487. {
  11488. //chy----19
  11489. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11490. //GD-CYT-----64
  11491. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11492. //ZHX----3
  11493. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11494. //JK----97
  11495. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11496. //ZT----70
  11497. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11498. //GD-CYTUV---126
  11499. {126, new Dictionary<string, string> {{"uv", "uv"}}},
  11500. //LHCY-----98
  11501. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11502. //XD-----90
  11503. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11504. //CYCY-----14
  11505. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}},
  11506. //THLZY----122
  11507. {122, new Dictionary<string, string> {{ "烫画", "烫画" }, { "冷转印", "冷转印" }}}
  11508. };
  11509. //其他改名
  11510. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11511. {
  11512. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11513. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11514. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11515. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11516. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11517. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11518. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11519. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" },{ 129,"种子纸"},{ 125,"胶带"}
  11520. };
  11521. //不统计
  11522. List<int> no_suppliers = new List<int>()
  11523. {
  11524. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11525. };
  11526. //配件单
  11527. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11528. {
  11529. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11530. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11531. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11532. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11533. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11534. {"旗杆",new List<string>(){ "班旗" } },
  11535. {"牙签",new List<string>(){ "不干胶" } }
  11536. };
  11537. public void get_place_order_data()
  11538. {
  11539. string date1 = GetPostString("date1");
  11540. string date2 = GetPostString("date2");
  11541. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11542. DateTime start = DateTime.Parse(starttime);
  11543. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11544. DateTime end = DateTime.Parse(endtime);
  11545. if (date1 != null && date1.Length > 0)
  11546. {
  11547. DateTime dateTime = DateTime.Parse(date1);
  11548. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11549. start = DateTime.Parse(starttime);
  11550. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11551. end = DateTime.Parse(endtime);
  11552. }
  11553. if (date2 != null && date2.Length > 0)
  11554. {
  11555. DateTime dateTime = DateTime.Parse(date2);
  11556. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11557. end = DateTime.Parse(endtime);
  11558. }
  11559. string startMonthDate = commonHelper.FirstDayOfMonth(DateTime.Now).ToString("yyyy-MM-dd 00:00:00");
  11560. string endMonthDate = commonHelper.LastDayOfMonth(DateTime.Now).ToString("yyyy-MM-dd 23:59:59");
  11561. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,UnusualTime,FinishPlaceTime,OrderState,FinishDeliveryTime,AfterSaleState=0,AfterSaleReason = '' 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);
  11562. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11563. sql = string.Format("SELECT SupplierId, ProductId, seller_memo, ProductCount, ProductName, payment, SupplierName, UnusualTime, FinishPlaceTime, OrderState, FinishDeliveryTime, AfterSaleState,AfterSaleReason FROM view_ErpTradeCell WHERE ( AfterSalePreTime BETWEEN '{0}' AND '{1}' ) AND IsSample = 0 AND SupplierId > 0 AND FinishPlaceTime IS NOT NULL", startMonthDate, endMonthDate);
  11564. DataTable afterSaleData = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11565. data.Merge(afterSaleData);
  11566. //不干胶-----1,卡片-----29
  11567. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11568. foreach (DataRow row in data.Rows)
  11569. {
  11570. int productId = Convert.ToInt32(row["ProductId"]);
  11571. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11572. if (no_suppliers.Contains(supplierId))
  11573. {
  11574. continue;
  11575. }
  11576. string seller_memo = row["seller_memo"].ToString();
  11577. bool ispj = false;//是否配件单
  11578. bool isfirst = true;//第一个配
  11579. maps.Keys.ForEach(key =>
  11580. {
  11581. //备注包含配件
  11582. if (seller_memo.Contains(key) && isfirst)
  11583. {
  11584. List<string> list = maps[key];
  11585. ispj = true;
  11586. isfirst = false;
  11587. for (int i = 0; i < list.Count; i++)
  11588. {
  11589. if (seller_memo.Contains(list[i]))
  11590. {
  11591. ispj = false;
  11592. break;
  11593. }
  11594. }
  11595. }
  11596. });
  11597. if (ispj)
  11598. {
  11599. continue;
  11600. }
  11601. seller_memo = seller_memo.Replace("UV", "uv");
  11602. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11603. //吊牌归到卡片
  11604. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11605. seller_memo = seller_memo.Replace("卡套", "卡片");
  11606. seller_memo = seller_memo.Replace("封套", "卡片");
  11607. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11608. seller_memo = seller_memo.Replace("腰封", "卡片");
  11609. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11610. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11611. seller_memo = seller_memo.Replace("横幅", "条幅");
  11612. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11613. string map_key = "";
  11614. string type = "";
  11615. if (supplierMap.ContainsKey(supplierId))
  11616. {
  11617. foreach (var kvp in supplierMap[supplierId])
  11618. {
  11619. if (seller_memo.Contains(kvp.Key))
  11620. {
  11621. map_key = kvp.Value;
  11622. type = kvp.Value;
  11623. break;
  11624. }
  11625. }
  11626. }
  11627. if (map_key == "")
  11628. {
  11629. type = "其他";
  11630. map_key = "其他";
  11631. }
  11632. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11633. {
  11634. map_key = suppliers[supplierId];
  11635. }
  11636. if (supplierId == 70)
  11637. {
  11638. supplierId = 70;
  11639. }
  11640. map_key += "_" + row["SupplierName"].ToString();
  11641. Dictionary<string, int> map = null;
  11642. if (other_map.ContainsKey(map_key))
  11643. {
  11644. other_map.TryGetValue(map_key, out map);
  11645. }
  11646. else
  11647. {
  11648. map = new Dictionary<string, int>();
  11649. map.Add("dayDev", 0);//当天出货
  11650. map.Add("dayTotal", 0);//下单总数
  11651. map.Add("payTotal", 0);//500以上
  11652. map.Add("today", 0);//当天出货数量
  11653. map.Add("unusua", 0);//异常数
  11654. map.Add("aftersale", 0);//异常数
  11655. other_map.Add(map_key, map);
  11656. other_map.TryGetValue(map_key, out map);
  11657. }
  11658. int afterSaleState = Convert.ToInt32(row["AfterSaleState"]);
  11659. if (afterSaleState == 0)
  11660. {
  11661. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11662. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11663. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11664. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11665. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11666. {
  11667. map["dayTotal"]++;
  11668. if (supplierId == 97)
  11669. {
  11670. supplierId = 97;
  11671. }
  11672. }
  11673. if (Convert.ToDecimal(row["payment"]) >= 500)
  11674. {
  11675. map["payTotal"]++;
  11676. }
  11677. bool istoday = false;
  11678. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11679. {
  11680. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11681. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11682. {
  11683. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11684. {
  11685. map["today"]++;
  11686. }
  11687. }
  11688. else
  11689. {
  11690. if (supplierId == 80)
  11691. {
  11692. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11693. {
  11694. map["today"]++;
  11695. }
  11696. }
  11697. else if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11698. {
  11699. map["today"]++;
  11700. istoday = true;
  11701. }
  11702. }
  11703. }
  11704. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11705. {
  11706. map["unusua"]++;
  11707. }
  11708. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11709. //GD-CYT-----64
  11710. DateTime two = palceTimeStart.AddHours(14);
  11711. DateTime three = palceTimeStart.AddHours(15);
  11712. DateTime four = palceTimeStart.AddHours(16);
  11713. DateTime six = palceTimeStart.AddHours(18);
  11714. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11715. {
  11716. //下午四点前 500-1000
  11717. string count = row["ProductCount"].ToString();
  11718. if (count != null && count.Length > 0)
  11719. {
  11720. int productCount = commonHelper.getPlaceProductCount(count);
  11721. if (productCount >= 500 && productCount <= 1000)
  11722. {
  11723. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11724. {
  11725. map["dayDev"]++;
  11726. }
  11727. }
  11728. }
  11729. }
  11730. //UV
  11731. else if ("uv".Equals(type))
  11732. {
  11733. //ZT----70
  11734. //ZHX----3
  11735. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11736. {
  11737. map["dayDev"]++;
  11738. }
  11739. //JK----97
  11740. //HZX----105
  11741. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11742. {
  11743. map["dayDev"]++;
  11744. }
  11745. if (DateTime.Compare(FinishPlaceTime, six) < 0 && (supplierId == 126))
  11746. {
  11747. map["dayDev"]++;
  11748. }
  11749. }
  11750. //帆布---52|条幅---27
  11751. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11752. {
  11753. //LHCY-----98
  11754. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11755. {
  11756. map["dayDev"]++;
  11757. }
  11758. }
  11759. //条幅
  11760. else if ("条幅".Equals(type))
  11761. {
  11762. //XD-----90
  11763. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11764. {
  11765. map["dayDev"]++;
  11766. }
  11767. }
  11768. //桌布
  11769. else if ("桌布".Equals(type))
  11770. {
  11771. //XD-----90
  11772. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11773. {
  11774. map["dayDev"]++;
  11775. }
  11776. }
  11777. //DL---10
  11778. //AYTW---119
  11779. //FS-CYT-DY ----80
  11780. //JK----97
  11781. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11782. {
  11783. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11784. {
  11785. map["dayDev"]++;
  11786. if (supplierId == 80 && istoday)
  11787. {
  11788. Debug.WriteLine(seller_memo);
  11789. }
  11790. }
  11791. }
  11792. // QC---121
  11793. else if (supplierId == 121)
  11794. {
  11795. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11796. {
  11797. map["dayDev"]++;
  11798. }
  11799. }
  11800. }
  11801. else
  11802. {
  11803. if (row["AfterSaleReason"].ToString().Contains("车间责任"))
  11804. {
  11805. map["aftersale"]++;
  11806. }
  11807. }
  11808. }
  11809. DataTable dt = new DataTable();
  11810. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11811. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11812. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11813. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11814. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11815. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11816. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11817. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11818. dt.Columns.Add(new DataColumn("aftersale", typeof(string)));
  11819. other_map.Keys.ForEach(key =>
  11820. {
  11821. DataRow dr = dt.NewRow();
  11822. Dictionary<string, int> map = other_map[key];
  11823. string[] key_list = key.Split('_');
  11824. dr[0] = key_list[0];
  11825. dr[1] = key_list[1];
  11826. if (key_list.Length > 2)
  11827. {
  11828. dr[1] += "(" + key_list[2] + ")";
  11829. }
  11830. dr[2] = map["dayTotal"];
  11831. dr[3] = map["payTotal"];
  11832. dr[4] = map["today"];
  11833. dr[5] = map["unusua"];
  11834. dr[6] = map["dayDev"];
  11835. double rate = 0.00;
  11836. if (map["dayDev"] > 0)
  11837. {
  11838. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11839. }
  11840. dr[7] = rate.ToString();
  11841. dr[8] = map["aftersale"];
  11842. dt.Rows.Add(dr);
  11843. });
  11844. DataView dv = new DataView(dt);
  11845. dv.Sort = "SupplierName";
  11846. //dv.Sort = "ProductName desc";
  11847. DataTable dtNew = dv.ToTable();
  11848. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11849. }
  11850. public void check_order_desing_info()
  11851. {
  11852. string ctid = GetPostString("ctid");
  11853. if (!string.IsNullOrEmpty(ctid))
  11854. {
  11855. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11856. if (ceErpTradeCell != null)
  11857. {
  11858. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11859. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11860. return;
  11861. }
  11862. returnErrorMsg("找不到订单");
  11863. return;
  11864. }
  11865. returnErrorMsg("找不到订单");
  11866. }
  11867. public void get_timeout_detail()
  11868. {
  11869. string poscode = CurrentUser.UserPost.Post.Code;
  11870. DataStruct dStruct = GetPostStruct();
  11871. List<string> lw = new List<string>();
  11872. string id = GetPostString("id");
  11873. string pay_date1 = GetPostString("pay_date1");
  11874. string pay_date2 = GetPostString("pay_date2");
  11875. int type = GetPostInt("type");
  11876. if (type == 0)
  11877. {
  11878. if (pay_date1.Length > 0)
  11879. {
  11880. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11881. }
  11882. if (pay_date2.Length > 0)
  11883. {
  11884. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11885. }
  11886. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11887. }
  11888. if (type == 1)
  11889. {
  11890. if (pay_date1.Length > 0)
  11891. {
  11892. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11893. }
  11894. if (pay_date2.Length > 0)
  11895. {
  11896. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11897. }
  11898. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11899. }
  11900. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11901. DataTable dt = null;
  11902. dt = WebCache.GetData("view_orderlist", dStruct);
  11903. writeGridDataTableJson(dStruct.TotalCount, dt);
  11904. }
  11905. public void saveUrgentChargePrice()
  11906. {
  11907. string ctid = GetPostString("ctid");
  11908. if (!string.IsNullOrEmpty(ctid))
  11909. {
  11910. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11911. if (ceErpTradeCell != null)
  11912. {
  11913. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11914. if (prices <= 100)
  11915. {
  11916. returnErrorMsg("此订单金额不足100元,无法加急。");
  11917. return;
  11918. }
  11919. double price = GetPostDouble("price");
  11920. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11921. if (ceErpTradeCellExtend == null)
  11922. {
  11923. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11924. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11925. }
  11926. ceErpTradeCellExtend.urgentCharge = price;
  11927. if (ceErpTradeCellExtend.ID > 0)
  11928. {
  11929. ceErpTradeCellExtend.Update();
  11930. }
  11931. else
  11932. {
  11933. ceErpTradeCellExtend.Save();
  11934. }
  11935. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11936. returnSuccessMsg("修改成功!");
  11937. return;
  11938. }
  11939. returnErrorMsg("找不到订单");
  11940. return;
  11941. }
  11942. returnErrorMsg("找不到订单");
  11943. }
  11944. public void finish_erp_order()
  11945. {
  11946. string ctid = GetPostString("ctid");
  11947. if (!string.IsNullOrEmpty(ctid))
  11948. {
  11949. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11950. {
  11951. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11952. if (ceErpTradeCell != null)
  11953. {
  11954. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11955. ceErpTradeCell.Update();
  11956. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11957. returnSuccessMsg("修改成功!");
  11958. return;
  11959. }
  11960. }
  11961. }
  11962. returnErrorMsg("找不到订单");
  11963. }
  11964. public void get_trade_order_list()
  11965. {
  11966. string tid = GetPostString("tid");
  11967. if (!string.IsNullOrEmpty(tid))
  11968. {
  11969. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11970. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11971. writeGridDataTableJson(data.Rows.Count, data);
  11972. return;
  11973. }
  11974. returnErrorMsg("找不到订单");
  11975. }
  11976. public void save_cell_spu()
  11977. {
  11978. string ctid = GetPostString("ctid");
  11979. string spu_id = GetPostString("spu_id");
  11980. if (!string.IsNullOrEmpty(ctid))
  11981. {
  11982. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11983. if (ceErpTradeCellExtend == null)
  11984. {
  11985. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11986. ceErpTradeCellExtend.ctid = ctid;
  11987. }
  11988. ceErpTradeCellExtend.spu_id = spu_id;
  11989. if (!string.IsNullOrEmpty(spu_id))
  11990. {
  11991. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11992. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  11993. }
  11994. if (ceErpTradeCellExtend.ID == 0)
  11995. {
  11996. ceErpTradeCellExtend.Create();
  11997. }
  11998. else
  11999. {
  12000. ceErpTradeCellExtend.Update();
  12001. }
  12002. returnSuccessMsg("修改成功!");
  12003. return;
  12004. }
  12005. returnErrorMsg("找不到订单");
  12006. }
  12007. public void change_express_info()
  12008. {
  12009. string ctid = GetPostString("ctid");
  12010. string transNo = GetPostString("transNo");
  12011. string transCom = GetPostString("transCom");
  12012. if (!string.IsNullOrEmpty(ctid))
  12013. {
  12014. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12015. if (ceErpTradeCellExtend == null)
  12016. {
  12017. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12018. ceErpTradeCellExtend.ctid = ctid;
  12019. }
  12020. ceErpTradeCellExtend.modExpressNo = transNo;
  12021. ceErpTradeCellExtend.modExpressCom = transCom;
  12022. ceErpTradeCellExtend.readMod = 2;
  12023. if (ceErpTradeCellExtend.ID == 0)
  12024. {
  12025. ceErpTradeCellExtend.Create();
  12026. }
  12027. else
  12028. {
  12029. ceErpTradeCellExtend.Update();
  12030. }
  12031. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  12032. returnSuccessMsg("修改成功!");
  12033. return;
  12034. }
  12035. returnErrorMsg("找不到订单");
  12036. }
  12037. public void get_change_express_list()
  12038. {
  12039. DataStruct dStruct = GetPostStruct();
  12040. List<string> lw = new List<string>();
  12041. int st = 2;
  12042. string tid = GetPostString("ctid");
  12043. if (tid.Length > 0)
  12044. {
  12045. string select_tid = getTidByCtid(tid);
  12046. lw.Add(string.Format("tid='{0}'", select_tid));
  12047. }
  12048. string shopname = GetPostString("shopname");
  12049. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12050. string buyernick = GetPostString("buyer_nick");
  12051. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12052. string sellermemo = GetPostString("seller_memo");
  12053. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12054. string supplier = GetPostString("supplier");
  12055. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12056. string customer = GetPostString("customer");
  12057. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12058. string design = GetPostString("design");
  12059. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12060. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12061. string poscode = CurrentUser.UserPost.Post.Code;
  12062. if (poscode != "SysAdmin")
  12063. {
  12064. string shopid = CurrentUser.User.pemShop;
  12065. lw.Add(string.Format("shopId in ({0})", shopid));
  12066. }
  12067. lw.Add("readMod = 2");
  12068. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12069. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  12070. writeGridDataTableJson(dStruct.TotalCount, dt);
  12071. }
  12072. public void deal_express_complete()
  12073. {
  12074. string ctid = GetPostString("ctid");
  12075. if (!string.IsNullOrEmpty(ctid))
  12076. {
  12077. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12078. if (ceErpTradeCellExtend == null)
  12079. {
  12080. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12081. ceErpTradeCellExtend.ctid = ctid;
  12082. }
  12083. ceErpTradeCellExtend.readMod = 1;
  12084. if (ceErpTradeCellExtend.ID == 0)
  12085. {
  12086. ceErpTradeCellExtend.Create();
  12087. }
  12088. else
  12089. {
  12090. ceErpTradeCellExtend.Update();
  12091. }
  12092. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  12093. returnSuccessMsg("修改成功!");
  12094. return;
  12095. }
  12096. returnErrorMsg("找不到订单");
  12097. }
  12098. public void aftersale_return_visit()
  12099. {
  12100. string ctid = GetPostString("ctid");
  12101. if (!string.IsNullOrEmpty(ctid))
  12102. {
  12103. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12104. if (ceErpTradeCellExtend == null)
  12105. {
  12106. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12107. ceErpTradeCellExtend.ctid = ctid;
  12108. }
  12109. ceErpTradeCellExtend.returnVisit = 1;
  12110. if (ceErpTradeCellExtend.ID == 0)
  12111. {
  12112. ceErpTradeCellExtend.Create();
  12113. }
  12114. else
  12115. {
  12116. ceErpTradeCellExtend.Update();
  12117. }
  12118. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12119. if (ceErpTradeAfterSaleExtend != null)
  12120. {
  12121. ceErpTradeAfterSaleExtend.TextResult = "";
  12122. ceErpTradeAfterSaleExtend.Update();
  12123. }
  12124. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  12125. returnSuccessMsg("修改成功!");
  12126. return;
  12127. }
  12128. returnErrorMsg("找不到订单");
  12129. }
  12130. public void orderPlaceInfo()
  12131. {
  12132. string ctids = GetPostString("ctids");
  12133. string[] list = ctids.Split(',');
  12134. foreach (string ctid in list)
  12135. {
  12136. CeErpSukuraData.createInfo(ctid, 3);
  12137. }
  12138. StringBuilder sql = new StringBuilder();
  12139. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  12140. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  12141. designHelper.api_approveDesign(ctids); //approveDesign
  12142. returnSuccessMsg("");
  12143. }
  12144. public void get_issue_list()
  12145. {
  12146. DataStruct dStruct = GetPostStruct();
  12147. List<string> lw = new List<string>();
  12148. int st = 2;
  12149. string tid = GetPostString("ctid");
  12150. if (tid.Length > 0)
  12151. {
  12152. string select_tid = getTidByCtid(tid);
  12153. lw.Add(string.Format("tid='{0}'", select_tid));
  12154. }
  12155. string shopname = GetPostString("shopname");
  12156. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12157. string buyernick = GetPostString("buyer_nick");
  12158. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12159. string sellermemo = GetPostString("seller_memo");
  12160. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12161. string supplier = GetPostString("supplier");
  12162. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12163. string customer = GetPostString("customer");
  12164. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12165. string design = GetPostString("design");
  12166. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12167. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12168. string poscode = CurrentUser.UserPost.Post.Code;
  12169. if (poscode != "SysAdmin")
  12170. {
  12171. string shopid = CurrentUser.User.pemShop;
  12172. lw.Add(string.Format("shopId in ({0})", shopid));
  12173. }
  12174. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  12175. {
  12176. lw.Add("IssueState = 1");
  12177. }
  12178. else
  12179. {
  12180. string iisstate = GetPostString("iisstate");
  12181. if ("1".Equals(iisstate))
  12182. {
  12183. lw.Add("IssueState =1");
  12184. }
  12185. else if ("2".Equals(iisstate))
  12186. {
  12187. lw.Add("IssueState = 2");
  12188. }
  12189. else
  12190. {
  12191. lw.Add("IssueState > 0");
  12192. }
  12193. }
  12194. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12195. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  12196. writeGridDataTableJson(dStruct.TotalCount, dt);
  12197. }
  12198. public void saveIssueContent()
  12199. {
  12200. string ctid = GetPostString("ctid");
  12201. if (!string.IsNullOrEmpty(ctid))
  12202. {
  12203. string content = GetPostString("content");
  12204. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12205. if (ceErpTradeAfterSaleExtend == null)
  12206. {
  12207. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  12208. ceErpTradeAfterSaleExtend.tid = ctid;
  12209. }
  12210. ceErpTradeAfterSaleExtend.IssueContent = content;
  12211. ceErpTradeAfterSaleExtend.IssueState = 1;
  12212. if (ceErpTradeAfterSaleExtend.ID > 0)
  12213. {
  12214. ceErpTradeAfterSaleExtend.Update();
  12215. }
  12216. else
  12217. {
  12218. ceErpTradeAfterSaleExtend.Create();
  12219. }
  12220. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  12221. returnSuccessMsg("添加成功!");
  12222. return;
  12223. }
  12224. returnErrorMsg("找不到订单");
  12225. }
  12226. public void dealIssueContent()
  12227. {
  12228. string ctid = GetPostString("ctid");
  12229. if (!string.IsNullOrEmpty(ctid))
  12230. {
  12231. string content = GetPostString("content");
  12232. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12233. if (ceErpTradeAfterSaleExtend != null)
  12234. {
  12235. ceErpTradeAfterSaleExtend.IssueState = 2;
  12236. ceErpTradeAfterSaleExtend.Update();
  12237. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  12238. returnSuccessMsg("修改完成!");
  12239. return;
  12240. }
  12241. }
  12242. returnErrorMsg("找不到订单");
  12243. }
  12244. public void set_tid_attachments()
  12245. {
  12246. string tid = GetPostString("tid");
  12247. string atta = GetPostString("atta");
  12248. if (!string.IsNullOrEmpty(tid))
  12249. {
  12250. if (string.IsNullOrEmpty(atta))
  12251. {
  12252. returnErrorMsg("文件地址为空");
  12253. return;
  12254. }
  12255. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12256. if (ceErpTradeCell != null)
  12257. {
  12258. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12259. if (ceErpTrade == null)
  12260. {
  12261. returnErrorMsg("找不到订单");
  12262. return;
  12263. }
  12264. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12265. bool isSend = false;
  12266. if (dt != null && dt.Rows.Count > 0)
  12267. {
  12268. foreach (DataRow row in dt.Rows)
  12269. {
  12270. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12271. {
  12272. isSend = true;
  12273. }
  12274. }
  12275. if (isSend)
  12276. {
  12277. returnErrorMsg("已发货无法修改");
  12278. return;
  12279. }
  12280. ceErpTrade.Attachments = atta;
  12281. ceErpTrade.Update();
  12282. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12283. returnSuccessMsg("上传成功!");
  12284. return;
  12285. }
  12286. }
  12287. }
  12288. returnErrorMsg("找不到订单");
  12289. }
  12290. public void get_tid_attachments()
  12291. {
  12292. string tid = GetPostString("tid");
  12293. if (!string.IsNullOrEmpty(tid))
  12294. {
  12295. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12296. if (ceErpTradeCell != null)
  12297. {
  12298. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12299. if (ceErpTrade == null)
  12300. {
  12301. returnErrorMsg("找不到订单");
  12302. return;
  12303. }
  12304. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12305. return;
  12306. }
  12307. }
  12308. returnErrorMsg("找不到订单");
  12309. }
  12310. public void check_erp_sameorders()
  12311. {
  12312. if (UrlPostParmsCheck("ctid"))
  12313. {
  12314. string eid = GetPostString("ctid");
  12315. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12316. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12317. if (entity != null && ceErpTrade != null)
  12318. {
  12319. if (entity.OrderState > 6)
  12320. {
  12321. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12322. return;
  12323. }
  12324. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12325. List<string> ids = new List<string>();
  12326. if (dt != null && dt.Rows.Count > 1)
  12327. {
  12328. bool needhe = true;
  12329. foreach (DataRow dr in dt.Rows)
  12330. {
  12331. ids.Add("'" + dr["ctid"] + "'");
  12332. /* //备注有合包
  12333. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12334. {
  12335. needhe = true;
  12336. }
  12337. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12338. {
  12339. needhe = true;
  12340. }
  12341. //顺丰快递
  12342. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12343. {
  12344. needhe = true;
  12345. }*/
  12346. }
  12347. if (!needhe)
  12348. {
  12349. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12350. return;
  12351. }
  12352. StringBuilder sql = new StringBuilder();
  12353. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12354. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12355. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12356. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12357. foreach (DataRow dr in dt.Rows)
  12358. {
  12359. dr["dstate"] = 0;
  12360. dr["dnumber"] = 0;
  12361. foreach (DataRow row in dt1.Rows)
  12362. {
  12363. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12364. {
  12365. dr["dstate"] = 2;
  12366. dr["default"] = 1;
  12367. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12368. }
  12369. }
  12370. if (eid.Equals(dr["ctid"].ToString()))
  12371. {
  12372. dr["dstate"] = 1;
  12373. dr["default"] = 1;
  12374. }
  12375. }
  12376. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12377. return;
  12378. }
  12379. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12380. return;
  12381. }
  12382. returnErrorMsg("未找到订单");
  12383. return;
  12384. }
  12385. returnErrorMsg("缺少必要的参数");
  12386. }
  12387. public void get_mark_number()
  12388. {
  12389. string eid = GetPostString("ctid");
  12390. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12391. if (entity != null)
  12392. {
  12393. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12394. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12395. int current = 1;
  12396. if (ceErpDeliverMark == null)
  12397. {
  12398. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12399. List<string> ids = new List<string>();
  12400. if (dt != null && dt.Rows.Count > 1)
  12401. {
  12402. foreach (DataRow dr in dt.Rows)
  12403. {
  12404. ids.Add("'" + dr["ctid"] + "'");
  12405. }
  12406. //查询已有的编号
  12407. StringBuilder sql = new StringBuilder();
  12408. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12409. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12410. if (dt1 == null || dt1.Rows.Count == 0)
  12411. {
  12412. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12413. List<int> list_number = new List<int>();
  12414. foreach (DataRow row in numbers.Rows)
  12415. {
  12416. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12417. }
  12418. //查询空余编号
  12419. for (int i = 0; i < list_number.Count + 2; i++)
  12420. {
  12421. if (!list_number.Contains(current))
  12422. {
  12423. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12424. //防止查询过程中有新数据生成
  12425. if (ceErpDeliverMark1 == null)
  12426. {
  12427. break;
  12428. }
  12429. }
  12430. current++;
  12431. }
  12432. }
  12433. else
  12434. {
  12435. foreach (DataRow row in dt1.Rows)
  12436. {
  12437. current = Convert.ToInt32(row["markNumber"]);
  12438. }
  12439. }
  12440. ceErpDeliverMark = new CeErpDeliverMark();
  12441. ceErpDeliverMark.ctid = eid;
  12442. ceErpDeliverMark.createtime = DateTime.Now;
  12443. if (ceErpTrade != null)
  12444. {
  12445. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12446. }
  12447. ceErpDeliverMark.markNumber = current;
  12448. ceErpDeliverMark.Create();
  12449. }
  12450. }
  12451. else
  12452. {
  12453. current = ceErpDeliverMark.markNumber;
  12454. }
  12455. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12456. return;
  12457. }
  12458. }
  12459. public void aftersaleCytSend()
  12460. {
  12461. string ctid = GetPostString("ctid");
  12462. if (!string.IsNullOrEmpty(ctid))
  12463. {
  12464. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12465. if (ceErpTradeCell != null)
  12466. {
  12467. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12468. }
  12469. returnSuccessMsg("推送成功");
  12470. return;
  12471. }
  12472. returnErrorMsg("缺少必要的参数");
  12473. }
  12474. public void packOrderInfo()
  12475. {
  12476. string ctids = GetPostString("ctids");
  12477. if (!string.IsNullOrEmpty(ctids))
  12478. {
  12479. string[] ctid_list = ctids.Split(',');
  12480. if (ctid_list.Length > 20)
  12481. {
  12482. returnErrorMsg("单次下载次数不能超过20个");
  12483. return;
  12484. }
  12485. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12486. StringBuilder sql = new StringBuilder();
  12487. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12488. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12489. int supplierId = 0;
  12490. StringBuilder insterSql = new StringBuilder();
  12491. for (int i = 0; i < dt.Rows.Count; i++)
  12492. {
  12493. DataRow row = dt.Rows[i];
  12494. if (i == 0)
  12495. {
  12496. supplierId = Convert.ToInt32(row["SupplierId"]);
  12497. }
  12498. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12499. {
  12500. returnErrorMsg("同车间的订单才能一起打包");
  12501. return;
  12502. }
  12503. int orderState = Convert.ToInt32(row["OrderState"]);
  12504. if (orderState != 5)
  12505. {
  12506. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12507. return;
  12508. }
  12509. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12510. }
  12511. CeErpPackData ceErpPackData = new CeErpPackData();
  12512. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  12513. ceErpPackData.supplierId = supplierId;
  12514. ceErpPackData.createtime = DateTime.Now;
  12515. ceErpPackData.createBy = CurrentUser.UserID;
  12516. ceErpPackData.createName = CurrentUser.UserName;
  12517. ceErpPackData.Create();
  12518. if (ceErpPackData.ID > 0)
  12519. {
  12520. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12521. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12522. }
  12523. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12524. returnSuccessMsg("打包成功");
  12525. return;
  12526. }
  12527. returnErrorMsg("缺少必要的参数");
  12528. }
  12529. public void rePackOrderInfo()
  12530. {
  12531. string id = GetPostString("id");
  12532. if (!string.IsNullOrEmpty(id))
  12533. {
  12534. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12535. if (ceErpPackData == null)
  12536. {
  12537. returnSuccessMsg("查无数据");
  12538. return;
  12539. }
  12540. ceErpPackData.upStatus = 0;
  12541. ceErpPackData.message = "";
  12542. ceErpPackData.Update();
  12543. returnSuccessMsg("打包成功");
  12544. return;
  12545. }
  12546. returnErrorMsg("缺少必要的参数");
  12547. }
  12548. public void backPackOrderInfo()
  12549. {
  12550. string id = GetPostString("id");
  12551. if (!string.IsNullOrEmpty(id))
  12552. {
  12553. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12554. if (ceErpPackData == null)
  12555. {
  12556. returnSuccessMsg("查无数据");
  12557. return;
  12558. }
  12559. ceErpPackData.upStatus = 4;
  12560. ceErpPackData.Update();
  12561. List<string> list = new List<string>();
  12562. StringBuilder sql = new StringBuilder();
  12563. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12564. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12565. for (int i = 0; i < dt.Rows.Count; i++)
  12566. {
  12567. DataRow row = dt.Rows[i];
  12568. list.Add("'" + row["ctid"].ToString() + "'");
  12569. }
  12570. string textCtids = string.Join(",", list);
  12571. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=5,IsVerifyToSupplier=0,IsReturn=1,ReturnTime=GETDATE(),ReturnReason='无法打包' where ctid in ({0}) and OrderState=6", textCtids));
  12572. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", textCtids, (int)OrderState.下单完成, 0, "无法打包退回"));
  12573. returnSuccessMsg("退回成功");
  12574. return;
  12575. }
  12576. returnErrorMsg("缺少必要的参数");
  12577. }
  12578. public void addPackDownNum()
  12579. {
  12580. string id = GetPostString("id");
  12581. if (!string.IsNullOrEmpty(id))
  12582. {
  12583. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12584. returnSuccessMsg("下载成功");
  12585. return;
  12586. }
  12587. returnErrorMsg("缺少必要的参数");
  12588. }
  12589. public void get_pack_list()
  12590. {
  12591. DataStruct dStruct = GetPostStruct();
  12592. List<string> lw = new List<string>();
  12593. string supplier = GetPostString("supplier");
  12594. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12595. string posTag = CurrentUser.UserPost.Post.Code;
  12596. if (posTag == "Supplier")
  12597. {
  12598. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12599. }
  12600. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12601. dStruct.Order = "createtime desc";
  12602. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12603. writeGridDataTableJson(dStruct.TotalCount, dt);
  12604. }
  12605. public void get_pack_order_list()
  12606. {
  12607. string packId = GetPostString("packId");
  12608. if (string.IsNullOrEmpty(packId))
  12609. {
  12610. returnErrorMsg("缺少必要的参数");
  12611. return;
  12612. }
  12613. StringBuilder sql = new StringBuilder();
  12614. sql.AppendFormat("select c.ctid,c.seller_memo,i.message from CE_ErpPackDataItem i left join CE_ErpTradeCell c on i.ctid=c.ctid where i.packId = {0}", packId);
  12615. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12616. if (dt == null || dt.Rows.Count == 0)
  12617. {
  12618. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12619. return;
  12620. }
  12621. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12622. return;
  12623. }
  12624. public void get_supplier_product_time_list()
  12625. {
  12626. DataStruct dStruct = GetPostStruct();
  12627. List<string> lw = new List<string>();
  12628. string supplier = GetPostString("supplier");
  12629. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12630. string posTag = CurrentUser.UserPost.Post.Code;
  12631. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12632. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12633. writeGridDataTableJson(dStruct.TotalCount, dt);
  12634. }
  12635. public void saveSupplierProductTime()
  12636. {
  12637. string productId = GetPostString("productId");
  12638. if (string.IsNullOrEmpty(productId))
  12639. {
  12640. returnErrorMsg("缺少必要的参数");
  12641. return;
  12642. }
  12643. string productName = GetPostString("productName");
  12644. int supplierId = GetPostInt("supplierId");
  12645. if (supplierId == 0)
  12646. {
  12647. returnErrorMsg("缺少必要的参数");
  12648. return;
  12649. }
  12650. int quantity = GetPostInt("quantity");
  12651. int sendDay = GetPostInt("sendTime");
  12652. string supplierName = GetPostString("supplierName");
  12653. string craft = GetPostString("craft");
  12654. string deadLine = GetPostString("deadLine");
  12655. string dayDeadLine = GetPostString("dayDeadLine");
  12656. try
  12657. {
  12658. int eid = GetPostInt("eid");
  12659. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12660. if (ceErpSupplierProductTime == null)
  12661. {
  12662. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12663. }
  12664. ceErpSupplierProductTime.productId = productId;
  12665. ceErpSupplierProductTime.productName = productName;
  12666. ceErpSupplierProductTime.supplierId = supplierId;
  12667. ceErpSupplierProductTime.supplierName = supplierName;
  12668. ceErpSupplierProductTime.craft = craft;
  12669. ceErpSupplierProductTime.sendDay = sendDay;
  12670. ceErpSupplierProductTime.quantity = quantity;
  12671. if (!string.IsNullOrEmpty(deadLine))
  12672. {
  12673. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12674. }
  12675. if (!string.IsNullOrEmpty(dayDeadLine))
  12676. {
  12677. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12678. }
  12679. if (ceErpSupplierProductTime.ID == 0)
  12680. {
  12681. ceErpSupplierProductTime.Save();
  12682. }
  12683. else
  12684. {
  12685. ceErpSupplierProductTime.Update();
  12686. }
  12687. }
  12688. catch (Exception e)
  12689. {
  12690. }
  12691. returnSuccessMsg("保存成功");
  12692. return;
  12693. }
  12694. public void delSupplierProductTime()
  12695. {
  12696. int eid = GetPostInt("eid");
  12697. if (eid > 0)
  12698. {
  12699. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12700. if (ceErpSupplierProductTime == null)
  12701. {
  12702. returnErrorMsg("查无数据");
  12703. return;
  12704. }
  12705. ceErpSupplierProductTime.Delete();
  12706. returnSuccessMsg("保存成功");
  12707. return;
  12708. }
  12709. returnErrorMsg("缺少必要的参数");
  12710. }
  12711. public void getExpressInfo()
  12712. {
  12713. string ctid = GetPostString("ctid");
  12714. if (!string.IsNullOrEmpty(ctid))
  12715. {
  12716. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12717. if (ceErpTradeCell != null)
  12718. {
  12719. string outSid = ceErpTradeCell.OutSid;
  12720. if (outSid.Length > 0)
  12721. {
  12722. 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);
  12723. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12724. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12725. return;
  12726. }
  12727. }
  12728. returnErrorMsg("查无记录");
  12729. return;
  12730. }
  12731. returnErrorMsg("缺少必要的参数");
  12732. }
  12733. public void getExpressPostData()
  12734. {
  12735. string express = GetPostString("express");
  12736. if (!string.IsNullOrEmpty(express))
  12737. {
  12738. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12739. if (ceErpExpressInfo != null)
  12740. {
  12741. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12742. return;
  12743. }
  12744. }
  12745. returnErrorMsg("缺少必要的参数");
  12746. }
  12747. public void checkSupplierOrder()
  12748. {
  12749. string ctids = GetPostString("ctids");
  12750. if (ctids != null)
  12751. {
  12752. List<string> list = new List<string>();
  12753. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  12754. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12755. for (int i = 0; i < dt.Rows.Count; i++)
  12756. {
  12757. DataRow row = dt.Rows[i];
  12758. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  12759. {
  12760. continue;
  12761. }
  12762. list.Add(row["seller_memo"].ToString());
  12763. }
  12764. if (list.Count > 0)
  12765. {
  12766. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", "'" + ctids.Replace(",", "','") + "'", (int)OrderState.下单完成, CurrentUser.UserID, "点击下载按钮"));
  12767. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  12768. return;
  12769. }
  12770. }
  12771. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  12772. return;
  12773. }
  12774. public void addPersonId()
  12775. {
  12776. string tid = GetPostString("tid");
  12777. string personId = GetPostString("personId");
  12778. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12779. if (ceErpTrade != null)
  12780. {
  12781. ceErpTrade.receiver_zip = personId;
  12782. ceErpTrade.Update();
  12783. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  12784. returnSuccessMsg("保存成功");
  12785. return;
  12786. }
  12787. returnErrorMsg("缺少必要的参数");
  12788. }
  12789. public void addDeliveryPaymant()
  12790. {
  12791. string tid = GetPostString("tid");
  12792. string paymant = GetPostString("paymant");
  12793. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12794. if (ceErpTrade != null)
  12795. {
  12796. if (!string.IsNullOrEmpty(paymant))
  12797. {
  12798. ceErpTrade.delivery_paymant = Convert.ToDouble(paymant);
  12799. }
  12800. ceErpTrade.Update();
  12801. LogHelper.addLog(tid, CurrentUser.UserID, "偏远物流费:" + paymant, 6);
  12802. returnSuccessMsg("保存成功");
  12803. return;
  12804. }
  12805. returnErrorMsg("缺少必要的参数");
  12806. }
  12807. public void saveCellFile()
  12808. {
  12809. string tid = GetPostString("tid");
  12810. string ctid = GetPostString("ctid");
  12811. string urls = GetPostString("urls");
  12812. string type = GetPostString("type");
  12813. string del = GetPostString("del");
  12814. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  12815. {
  12816. if (tradeCellFile == TradeCellFile.AUTH_FILE)
  12817. {
  12818. ctid = tid;
  12819. }
  12820. if ("1".Equals(del))
  12821. {
  12822. CeErpTradeCellFile.delByCtid(tid, ctid, tradeCellFile.ToString());
  12823. }
  12824. string[] list = urls.Split(',');
  12825. if (!string.IsNullOrEmpty(urls) && list.Length > 0)
  12826. {
  12827. foreach (string item in list)
  12828. {
  12829. CeErpTradeCellFile ceErpTradeCellFile = new CeErpTradeCellFile(tid, ctid, item, tradeCellFile.ToString());
  12830. ceErpTradeCellFile.Create();
  12831. LogHelper.addLog(ctid, CurrentUser.UserID, "上传客户文件:" + item, 6);
  12832. }
  12833. }
  12834. returnSuccessMsg("保存成功");
  12835. return;
  12836. }
  12837. returnErrorMsg("缺少必要的参数");
  12838. }
  12839. public void getCellFile()
  12840. {
  12841. string tid = GetPostString("tid");
  12842. string ctid = GetPostString("ctid");
  12843. string type = GetPostString("type");
  12844. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  12845. {
  12846. if (tradeCellFile == TradeCellFile.AUTH_FILE)
  12847. {
  12848. ctid = tid;
  12849. }
  12850. string sql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeCellFile] WHERE isDel=0 and tid='{0}' and ctid='{1}' and type='{2}';", tid, ctid, tradeCellFile);
  12851. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12852. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  12853. return;
  12854. }
  12855. returnErrorMsg("缺少必要的参数");
  12856. }
  12857. public void delCellFile()
  12858. {
  12859. string id = GetPostString("id");
  12860. if (string.IsNullOrEmpty(id))
  12861. {
  12862. returnErrorMsg("缺少必要的参数");
  12863. return;
  12864. }
  12865. CeErpTradeCellFile ceErpTradeCellFile = CeErpTradeCellFile.Get(id);
  12866. CeErpTradeCellFile.delByID(id);
  12867. LogHelper.addLog(ceErpTradeCellFile.ctid, CurrentUser.UserID, "删除客户文件", 6);
  12868. returnSuccessMsg("保存成功");
  12869. }
  12870. public void getInvoiceOrder()
  12871. {
  12872. string tid = GetPostString("tid");
  12873. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12874. List<string> tids = new List<string>();
  12875. if (!string.IsNullOrEmpty(ceErpTrade.buyer_nick) && !string.IsNullOrEmpty(ceErpTrade.buyer_id))
  12876. {
  12877. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WHERE buyer_id = '{0}' AND seller_nick = '{1}' order by pay_time desc;", ceErpTrade.buyer_id, ceErpTrade.seller_nick);
  12878. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12879. foreach (DataRow dr in dt.Rows)
  12880. {
  12881. tids.Add("'" + dr["tid"].ToString() + "'");
  12882. }
  12883. }
  12884. else
  12885. {
  12886. tids.Add("'" + ceErpTrade.tid + "'");
  12887. }
  12888. DataTable cell_dt = new DataTable();
  12889. if (tids.Count > 0)
  12890. {
  12891. cell_dt = DbHelper.DbConn.ExecuteDataset(string.Format("SELECT * FROM [dbo].[CE_ErpTradeCell] WHERE tid in ({0});", string.Join(",", tids))).Tables[0];
  12892. }
  12893. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(cell_dt));
  12894. return;
  12895. }
  12896. }
  12897. }