sync.order.cs 660 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135
  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. if (CurrentUser.UserID == 73)
  2401. {
  2402. userPost = "SysAdmin";
  2403. }
  2404. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2405. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2406. if (response.msg != "设计共创:成功")
  2407. {
  2408. returnErrorMsg(response.msg);
  2409. return;
  2410. }
  2411. entity.DispatchSort = 2;
  2412. }
  2413. else
  2414. {
  2415. if (entity.DispatchSort == 2)
  2416. {
  2417. ApiVo apiVo = new ApiVo();
  2418. apiVo.actionName = "closeDesign";
  2419. apiVo.orderNumber = entity.ctid;
  2420. designHelper.API_WorkCore(apiVo);//closeDesign
  2421. }
  2422. entity.DispatchSort = 0;
  2423. }
  2424. entity.DesignUserId = userid;
  2425. entity.WaitDesignTime = DateTime.Now;
  2426. entity.UpdateTime = DateTime.Now;
  2427. entity.Update();
  2428. string name = commonHelper.getUserNameById(userid);
  2429. commonHelper.UpdateRelationOrder(entity.ctid);
  2430. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2431. }
  2432. }
  2433. returnSuccessMsg("操作成功!");
  2434. return;
  2435. }
  2436. }
  2437. public string getTidByCtid(string ctid)
  2438. {
  2439. string tid = "";
  2440. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2441. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2442. if (dataTable != null && dataTable.Rows.Count > 0)
  2443. {
  2444. tid = dataTable.Rows[0]["tid"].ToString();
  2445. }
  2446. return tid;
  2447. }
  2448. public List<string> getTidByCtidMore(string ctid)
  2449. {
  2450. 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);
  2451. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2452. List<string> list = new List<string>();
  2453. if (dataTable != null && dataTable.Rows.Count > 0)
  2454. {
  2455. foreach (DataRow item in dataTable.Rows)
  2456. {
  2457. list.Add("'" + item["tid"].ToString() + "'");
  2458. }
  2459. }
  2460. return list;
  2461. }
  2462. public List<string> getTidByCtidLike(string ctid)
  2463. {
  2464. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2465. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2466. List<string> list = new List<string>();
  2467. if (dataTable != null && dataTable.Rows.Count > 0)
  2468. {
  2469. foreach (DataRow item in dataTable.Rows)
  2470. {
  2471. list.Add("'" + item["tid"].ToString() + "'");
  2472. }
  2473. }
  2474. return list;
  2475. }
  2476. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2477. {
  2478. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2479. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2480. List<string> list = new List<string>();
  2481. if (dataTable != null && dataTable.Rows.Count > 0)
  2482. {
  2483. foreach (DataRow item in dataTable.Rows)
  2484. {
  2485. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2486. {
  2487. continue;
  2488. }
  2489. list.Add("'" + item["receiverId"].ToString() + "'");
  2490. }
  2491. }
  2492. return list;
  2493. }
  2494. public void get_erp_myorderlist()
  2495. {
  2496. DataStruct dStruct = GetPostStruct();
  2497. List<string> lw = new List<string>();
  2498. string tid = GetPostString("ctid");
  2499. if (tid.Length > 0)
  2500. {
  2501. string select_tid = getTidByCtid(tid);
  2502. lw.Add(string.Format("tid='{0}'", select_tid));
  2503. }
  2504. else
  2505. {
  2506. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2507. }
  2508. //12-1 修改
  2509. string urgent = GetPostString("urgent");
  2510. string back = GetPostString("back");
  2511. string offlineSearch = GetPostString("offlineSearch");
  2512. if (!string.IsNullOrWhiteSpace(urgent))
  2513. {
  2514. if (urgent.Equals("true"))
  2515. {
  2516. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2517. }
  2518. }
  2519. if (!string.IsNullOrWhiteSpace(back))
  2520. {
  2521. if (back.Equals("true"))
  2522. {
  2523. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2524. }
  2525. }
  2526. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2527. {
  2528. if (offlineSearch.Equals("true"))
  2529. {
  2530. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2531. }
  2532. }
  2533. //end
  2534. string shopname = GetPostString("shopname");
  2535. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2536. string buyernick = GetPostString("buyer_nick");
  2537. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2538. string design = GetPostString("design");
  2539. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2540. string orderState = GetPostString("orderState");
  2541. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2542. string sellermemo = GetPostString("seller_memo");
  2543. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2544. string date1 = GetPostString("date1");
  2545. string date2 = GetPostString("date2");
  2546. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2547. if (dw.Length > 0) lw.Add(dw);
  2548. string price1 = GetPostString("price1");
  2549. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2550. string price2 = GetPostString("price2");
  2551. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2552. string urgency = GetPostString("urgency");
  2553. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2554. string after = GetPostString("after");
  2555. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2556. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2557. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2558. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2559. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2560. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2561. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2562. if (dt != null && dt.Rows.Count > 0)
  2563. {
  2564. foreach (DataRow dr in dt.Rows)
  2565. {
  2566. try
  2567. {
  2568. // 对象操作
  2569. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2570. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2571. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2572. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2573. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2574. if (dStruct.PageSize != 100000)
  2575. {
  2576. if (dr["DispatchSort"].ToString() == "2")
  2577. {
  2578. dr["gongchuang"] = 200;
  2579. }
  2580. else if ("外协".Equals(dr["ToType"].ToString()))
  2581. {
  2582. dr["gongchuang"] = 200;
  2583. }
  2584. else if ("内部".Equals(dr["ToType"].ToString()))
  2585. {
  2586. dr["gongchuang"] = -1;
  2587. }
  2588. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2589. {
  2590. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2591. dr["gongchuang"] = response.code;
  2592. }
  2593. }
  2594. }
  2595. catch (NullReferenceException ex)
  2596. {
  2597. }
  2598. }
  2599. }
  2600. writeGridDataTableJson(dStruct.TotalCount, dt);
  2601. }
  2602. public void get_erp_myreturnorderlist()
  2603. {
  2604. DataStruct dStruct = GetPostStruct();
  2605. List<string> lw = new List<string>();
  2606. string tid = GetPostString("ctid");
  2607. if (tid.Length > 0)
  2608. {
  2609. string select_tid = getTidByCtid(tid);
  2610. lw.Add(string.Format("tid='{0}'", select_tid));
  2611. }
  2612. else
  2613. {
  2614. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2615. }
  2616. string shopname = GetPostString("shopname");
  2617. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2618. string buyernick = GetPostString("buyer_nick");
  2619. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2620. string design = GetPostString("design");
  2621. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2622. string orderState = GetPostString("orderState");
  2623. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2624. string sellermemo = GetPostString("seller_memo");
  2625. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2626. string date1 = GetPostString("date1");
  2627. string date2 = GetPostString("date2");
  2628. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2629. if (dw.Length > 0) lw.Add(dw);
  2630. string price1 = GetPostString("price1");
  2631. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2632. string price2 = GetPostString("price2");
  2633. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2634. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2635. {
  2636. lw.Add(string.Format("CusOrgID = 94"));
  2637. }
  2638. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2639. {
  2640. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2641. }
  2642. else
  2643. {
  2644. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2645. }
  2646. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2647. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2648. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2649. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2650. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2651. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2652. if (dt != null && dt.Rows.Count > 0)
  2653. {
  2654. foreach (DataRow dr in dt.Rows)
  2655. {
  2656. try
  2657. {
  2658. // 对象操作
  2659. if (dStruct.PageSize != 100000)
  2660. {
  2661. if (dr["DispatchSort"].ToString() == "2")
  2662. {
  2663. dr["gongchuang"] = 200;
  2664. }
  2665. else if ("外协".Equals(dr["ToType"].ToString()))
  2666. {
  2667. dr["gongchuang"] = 200;
  2668. }
  2669. else if ("内部".Equals(dr["ToType"].ToString()))
  2670. {
  2671. dr["gongchuang"] = -1;
  2672. }
  2673. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2674. {
  2675. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2676. dr["gongchuang"] = response.code;
  2677. }
  2678. }
  2679. }
  2680. catch (NullReferenceException ex)
  2681. {
  2682. // 处理空引用异常
  2683. }
  2684. }
  2685. }
  2686. writeGridDataTableJson(dStruct.TotalCount, dt);
  2687. }
  2688. public void get_erp_myorderlist_pregather()
  2689. {
  2690. string date1 = GetPostString("date1");
  2691. string date2 = GetPostString("date2");
  2692. int userId = CurrentUser.UserID; //客服id
  2693. string orderWhere = "";
  2694. List<string> lw = new List<string>();
  2695. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2696. if (dw.Length > 0) lw.Add(dw);
  2697. lw.Add(string.Format("CustomerUserId={0}", userId));
  2698. lw.Add(string.Format("OrderState<9"));
  2699. orderWhere = string.Join(" and ", lw.ToArray());
  2700. string orderWhere2 = "";
  2701. List<string> lw2 = new List<string>();
  2702. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2703. if (dw2.Length > 0) lw2.Add(dw2);
  2704. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2705. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2706. string sql = string.Format("select *" +
  2707. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2708. "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 " +
  2709. "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 " +
  2710. "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");
  2711. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2712. //writeGridDataTableJson(dt.Rows.Count, dt);
  2713. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2714. }
  2715. public void upd_erp_publishorder()
  2716. {
  2717. if (UrlPostParmsCheck("ctid"))
  2718. {
  2719. string eid = GetPostString("ctid");
  2720. CeErpTradeCell entity = null;
  2721. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2722. if (entity != null)
  2723. {
  2724. entity.OrderState = 0; //发布后,变为待抢单
  2725. entity.Update();
  2726. commonHelper.UpdateRelationOrder(entity.ctid);
  2727. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2728. returnSuccessMsg("发布成功!");
  2729. return;
  2730. }
  2731. returnErrorMsg("找不到记录");
  2732. }
  2733. }
  2734. public void get_erp_my_tiporder()
  2735. {
  2736. StringBuilder sql = new StringBuilder();
  2737. int userId = 0;
  2738. if (CurrentUser != null) userId = CurrentUser.UserID;
  2739. string posCode = CurrentUser.UserPost.Post.Code;
  2740. string isTipedAfterSaleVerify = GetPostString("af");
  2741. DataTable dt = new DataTable();
  2742. if (posCode != "Supplier")
  2743. {
  2744. if (posCode == "CustomerService" || posCode == "Director")
  2745. {
  2746. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2747. }
  2748. else if (posCode == "Place" || posCode == "PlaceMr")
  2749. {
  2750. }
  2751. else
  2752. {
  2753. string teamIds = CurrentUser.User.TeamIds;
  2754. if (teamIds == "")
  2755. {
  2756. teamIds = "0";
  2757. }
  2758. 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);
  2759. }
  2760. if (sql.Length > 0)
  2761. {
  2762. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2763. }
  2764. }
  2765. if (dt.Rows.Count <= 0)
  2766. {
  2767. string key = "aftersale_order_" + userId;
  2768. if (RedisHelper.HasKey(key))
  2769. {
  2770. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2771. dt.Columns.Add("ctid", typeof(string));
  2772. dt.Columns.Add("IsReadTag", typeof(int));
  2773. foreach (var i in list)
  2774. {
  2775. DataRow data = dt.NewRow();
  2776. data["ctid"] = i;
  2777. data["IsReadTag"] = 4;
  2778. dt.Rows.Add(data);
  2779. }
  2780. RedisHelper.StringDelete(key);
  2781. }
  2782. }
  2783. if (dt.Rows.Count <= 0)
  2784. {
  2785. sql = new StringBuilder();
  2786. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2787. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2788. }
  2789. if (posCode == "Supplier")
  2790. {
  2791. string ids = CurrentUser.User.pemVend;
  2792. if (ids != null && ids.Length > 0)
  2793. {
  2794. string[] ids_list = ids.Split(',');
  2795. foreach (var item in ids_list)
  2796. {
  2797. string key = "return_order_" + item;
  2798. if (RedisHelper.HasKey(key))
  2799. {
  2800. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2801. dt.Columns.Add("ctid", typeof(string));
  2802. dt.Columns.Add("IsReadTag", typeof(int));
  2803. foreach (var i in list)
  2804. {
  2805. DataRow data = dt.NewRow();
  2806. data["ctid"] = i;
  2807. data["IsReadTag"] = 1;
  2808. dt.Rows.Add(data);
  2809. }
  2810. RedisHelper.StringDelete(key);
  2811. }
  2812. }
  2813. }
  2814. if (dt.Rows.Count <= 0)
  2815. {
  2816. sql = new StringBuilder();
  2817. 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);
  2818. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2819. }
  2820. }
  2821. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2822. }
  2823. public void reset_erp_tiporder()
  2824. {
  2825. string ids = GetPostString("ids");
  2826. string[] ctidList = ids.Split(',');
  2827. foreach (string ctid in ctidList)
  2828. {
  2829. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2830. if (enty != null)
  2831. {
  2832. enty.IsReadTag = 0;
  2833. enty.Update();
  2834. }
  2835. }
  2836. returnSuccessMsg("成功!");
  2837. return;
  2838. }
  2839. public void get_erp_designlist()
  2840. {
  2841. DataStruct dStruct = GetPostStruct();
  2842. List<string> lw = new List<string>();
  2843. string tid = GetPostString("ctid");
  2844. if (tid.Length > 0)
  2845. {
  2846. string select_tid = getTidByCtid(tid);
  2847. lw.Add(string.Format("tid='{0}'", select_tid));
  2848. }
  2849. string shopname = GetPostString("shopname");
  2850. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2851. string buyernick = GetPostString("buyer_nick");
  2852. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2853. string customer = GetPostString("customer");
  2854. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2855. string design = GetPostString("design");
  2856. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2857. string orderState = GetPostString("orderState");
  2858. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2859. lw.Add(string.Format("OrderState<6"));
  2860. string address = GetPostString("address");
  2861. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2862. string sellermemo = GetPostString("seller_memo");
  2863. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2864. string date1 = GetPostString("date1");
  2865. string date2 = GetPostString("date2");
  2866. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2867. if (dw.Length > 0) lw.Add(dw);
  2868. string apdate1 = GetPostString("apdate1");
  2869. string apdate2 = GetPostString("apdate2");
  2870. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2871. if (dwap.Length > 0) lw.Add(dwap);
  2872. string price1 = GetPostString("price1");
  2873. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2874. string price2 = GetPostString("price2");
  2875. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2876. string designTime = GetPostString("designtime");
  2877. if (designTime.Length > 0)
  2878. {
  2879. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2880. }
  2881. string usershop = CurrentUser.User.pemShop;
  2882. if (usershop.Length > 0)
  2883. {
  2884. lw.Add(string.Format("shopId in ({0})", usershop));
  2885. }
  2886. int myOrgid = CurrentUser.UserPost.OrgID;
  2887. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2888. if (myOrgCode.IndexOf("Designer") != -1)
  2889. {
  2890. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2891. {
  2892. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2893. }
  2894. else
  2895. {
  2896. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2897. }
  2898. }
  2899. else
  2900. {
  2901. string orgId = GetPostString("designerhd");
  2902. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2903. }
  2904. if (tid.Length > 0 || buyernick.Length > 0)
  2905. {
  2906. lw.Add(string.Format("OrderState >= 3"));
  2907. }
  2908. else
  2909. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2910. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2911. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2912. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2913. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2914. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2915. if (dt != null && dt.Rows.Count > 0)
  2916. {
  2917. foreach (DataRow dr in dt.Rows)
  2918. {
  2919. try
  2920. {
  2921. // 对象操作
  2922. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2923. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2924. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2925. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2926. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2927. if (dStruct.PageSize != 100000)
  2928. {
  2929. if (dr["DispatchSort"].ToString() == "2")
  2930. {
  2931. dr["gongchuang"] = 200;
  2932. }
  2933. else if ("外协".Equals(dr["ToType"].ToString()))
  2934. {
  2935. dr["gongchuang"] = 200;
  2936. }
  2937. else if ("内部".Equals(dr["ToType"].ToString()))
  2938. {
  2939. dr["gongchuang"] = -1;
  2940. }
  2941. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2942. {
  2943. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2944. dr["gongchuang"] = response.code;
  2945. }
  2946. }
  2947. }
  2948. catch (NullReferenceException ex)
  2949. {
  2950. }
  2951. }
  2952. }
  2953. writeGridDataTableJson(dStruct.TotalCount, dt);
  2954. }
  2955. public void get_erp_mydesignlist()
  2956. {
  2957. DataStruct dStruct = GetPostStruct();
  2958. List<string> lw = new List<string>();
  2959. string tid = GetPostString("ctid");
  2960. if (tid.Length > 0)
  2961. {
  2962. string select_tid = getTidByCtid(tid);
  2963. lw.Add(string.Format("tid='{0}'", select_tid));
  2964. }
  2965. string shopname = GetPostString("shopname");
  2966. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2967. string buyernick = GetPostString("buyer_nick");
  2968. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2969. string customer = GetPostString("customer");
  2970. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2971. string orderState = GetPostString("orderState");
  2972. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2973. //lw.Add(string.Format("OrderState<6"));
  2974. string date1 = GetPostString("date1");
  2975. string date2 = GetPostString("date2");
  2976. string dw = GetDateWhere("pay_time", date1, date2);
  2977. if (dw.Length > 0) lw.Add(dw);
  2978. string apdate1 = GetPostString("apdate1");
  2979. string apdate2 = GetPostString("apdate2");
  2980. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2981. if (dwap.Length > 0) lw.Add(dwap);
  2982. string price1 = GetPostString("price1");
  2983. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2984. string price2 = GetPostString("price2");
  2985. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2986. string olddownload = GetPostString("olddown");
  2987. if (olddownload == "1")
  2988. {
  2989. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2990. }
  2991. else if (olddownload == "2")
  2992. {
  2993. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2994. }
  2995. string sellermemo = GetPostString("seller_memo");
  2996. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2997. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2998. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2999. {
  3000. if (CurrentUser.User.TeamIds.Length > 0)
  3001. {
  3002. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  3003. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3004. else
  3005. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3006. }
  3007. else
  3008. {
  3009. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  3010. }
  3011. }
  3012. if (tid.Length <= 0)
  3013. {
  3014. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  3015. }
  3016. lw.Add(string.Format("IsReturn!=3"));
  3017. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  3018. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3019. string teamids = CurrentUser.User.TeamIds.ToString();
  3020. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3021. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  3022. if (dt != null && dt.Rows.Count > 0)
  3023. {
  3024. foreach (DataRow dr in dt.Rows)
  3025. {
  3026. try
  3027. {
  3028. // 对象操作
  3029. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  3030. ceErpTradeCell.ctid = dr["ctid"].ToString();
  3031. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  3032. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  3033. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  3034. if (dStruct.PageSize != 100000)
  3035. {
  3036. if (dr["DispatchSort"].ToString() == "2")
  3037. {
  3038. dr["gongchuang"] = 200;
  3039. }
  3040. else if ("外协".Equals(dr["ToType"].ToString()))
  3041. {
  3042. dr["gongchuang"] = 200;
  3043. }
  3044. else if ("内部".Equals(dr["ToType"].ToString()))
  3045. {
  3046. dr["gongchuang"] = -1;
  3047. }
  3048. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  3049. {
  3050. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  3051. dr["gongchuang"] = response.code;
  3052. }
  3053. }
  3054. }
  3055. catch (NullReferenceException ex)
  3056. {
  3057. }
  3058. }
  3059. }
  3060. writeGridDataTableJson(dStruct.TotalCount, dt);
  3061. }
  3062. public void set_erp_startdesign()
  3063. {
  3064. if (UrlPostParmsCheck("ctid"))
  3065. {
  3066. string eid = GetPostString("ctid");
  3067. CeErpTradeCell entity = null;
  3068. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3069. if (entity != null)
  3070. {
  3071. if (entity.OrderState != 3)
  3072. {
  3073. returnErrorMsg("请刷新,订单已经设计了");
  3074. return;
  3075. }
  3076. entity.StartDesignTime = DateTime.Now;
  3077. entity.OrderState = 4;
  3078. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  3079. {
  3080. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3081. entity.SupplierId = suid;
  3082. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3083. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3084. }
  3085. entity.UpdateTime = DateTime.Now;
  3086. //entity.MakeSupplier = suname;
  3087. entity.Update();
  3088. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3089. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3090. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  3091. commonHelper.getCytPrice(entity);
  3092. returnSuccessMsg("操作成功!");
  3093. return;
  3094. }
  3095. returnErrorMsg("找不到记录");
  3096. }
  3097. }
  3098. public void ins_erp_designselfmemo()
  3099. {
  3100. if (UrlPostParmsCheck("ctid"))
  3101. {
  3102. string eid = GetPostString("ctid");
  3103. string con = GetPostString("con");
  3104. CeErpTradeCell entity = null;
  3105. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3106. if (entity != null)
  3107. {
  3108. entity.DesignSelfMemo = con;
  3109. entity.Update();
  3110. returnSuccessMsg("操作成功!");
  3111. return;
  3112. }
  3113. returnErrorMsg("找不到记录");
  3114. }
  3115. }
  3116. public void ins_erp_designprice()
  3117. {
  3118. if (UrlPostParmsCheck("ctid"))
  3119. {
  3120. string eid = GetPostString("ctid");
  3121. int uid = CurrentUser.UserID;
  3122. string userName = CurrentUser.UserName;
  3123. CeErpTradeCell entity = null;
  3124. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3125. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3126. if (entitys == null)
  3127. {
  3128. entitys = new CeErpDesignerBill();
  3129. }
  3130. if (entity != null)
  3131. {
  3132. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3133. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3134. entity.StartDesignTime = DateTime.Now;
  3135. entity.OrderState = 4;
  3136. string suname = "";
  3137. if (entity.SupplierId == 0)
  3138. {
  3139. int sid = commonHelper.autoDistributeToSupplier(entity);
  3140. entity.SupplierId = sid;
  3141. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3142. }
  3143. entity.Update();
  3144. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3145. if (ceErpUserPost != null)
  3146. {
  3147. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3148. if (ceErpPost != null)
  3149. {
  3150. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3151. {
  3152. entitys.tid = entity.ctid;
  3153. entitys.oid = entity.tid;
  3154. entitys.uid = uid;
  3155. entitys.userName = userName;
  3156. entitys.designerType = 1;
  3157. entitys.designerTypeText = "内部设计师";
  3158. entitys.price = Convert.ToDouble(GetPostString("price"));
  3159. entitys.designNum = GetPostInt("designNum");
  3160. entitys.modifyNum = GetPostInt("modifyNum");
  3161. entitys.designSize = GetPostString("designSize");
  3162. entitys.modifySize = GetPostString("modifySize");
  3163. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3164. {
  3165. entitys.create_time = DateTime.Now;
  3166. entitys.create_u_id = uid;
  3167. entitys.create_u_name = userName;
  3168. entitys.Save();
  3169. }
  3170. else
  3171. {
  3172. entitys.update_time = DateTime.Now;
  3173. entitys.update_u_id = uid;
  3174. entitys.update_u_name = userName;
  3175. entitys.Update();
  3176. }
  3177. }
  3178. }
  3179. }
  3180. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3181. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3182. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3183. if (suname != "")
  3184. {
  3185. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3186. }
  3187. commonHelper.getCytPrice(entity);
  3188. returnSuccessMsg("操作成功!");
  3189. return;
  3190. }
  3191. returnErrorMsg("找不到记录");
  3192. }
  3193. }
  3194. public void upload_erp_filecomplete()
  3195. {
  3196. if (UrlPostParmsCheck("ctid"))
  3197. {
  3198. string eid = GetPostString("ctid");
  3199. CeErpTradeCell entity = null;
  3200. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3201. if (entity != null)
  3202. {
  3203. entity.OrderState = 5; //设计完成
  3204. entity.Update();
  3205. returnSuccessMsg(eid + "上传成功,设计完成!");
  3206. return;
  3207. }
  3208. returnErrorMsg("找不到订单记录");
  3209. }
  3210. }
  3211. public void get_erp_designovertimelist()
  3212. {
  3213. DataStruct dStruct = GetPostStruct();
  3214. List<string> lw = new List<string>();
  3215. string tid = GetPostString("ctid");
  3216. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3217. string shopname = GetPostString("shopname");
  3218. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3219. string buyernick = GetPostString("buyer_nick");
  3220. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3221. string ResponsibleMan = GetPostString("responsible");
  3222. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3223. string date1 = GetPostString("date1");
  3224. string date2 = GetPostString("date2");
  3225. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3226. if (dw.Length > 0) lw.Add(dw);
  3227. string price1 = GetPostString("price1");
  3228. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3229. string price2 = GetPostString("price2");
  3230. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3231. string orderState = GetPostString("orderState");
  3232. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3233. string sellermemo = GetPostString("seller_memo");
  3234. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3235. lw.Add(string.Format("UnusualTag=3"));
  3236. lw.Add(string.Format("IsRefund<={0}", 1));
  3237. dStruct.Order = "WaitDesignTime desc";
  3238. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3239. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3240. writeGridDataTableJson(dStruct.TotalCount, dt);
  3241. }
  3242. //设计管理 获取抢单大厅列表
  3243. public void get_erp_grabinglist()
  3244. {
  3245. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3246. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3247. bool oldOrder = false;
  3248. if (org != null)
  3249. {
  3250. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3251. }
  3252. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3253. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3254. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3255. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3256. //先处理订单数据
  3257. if (dt.Rows.Count > 0)
  3258. {
  3259. Dictionary<string, int> design = null;
  3260. int count = 0;
  3261. foreach (DataRow row in dt.Rows)
  3262. {
  3263. if (map.ContainsKey(row["ShopId"].ToString()))
  3264. {
  3265. map.TryGetValue(row["ShopId"].ToString(), out design);
  3266. }
  3267. else
  3268. {
  3269. design = new Dictionary<string, int>();
  3270. }
  3271. if (design.ContainsKey(row["ProductId"].ToString()))
  3272. {
  3273. design.TryGetValue(row["ProductId"].ToString(), out count);
  3274. }
  3275. count++;
  3276. design[row["ProductId"].ToString()] = count;
  3277. map[row["ShopId"].ToString()] = design;
  3278. }
  3279. }
  3280. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3281. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3282. //把店铺排序和技能排序分类
  3283. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3284. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3285. if (design_dt.Rows.Count > 0)
  3286. {
  3287. Dictionary<string, string> design = null;
  3288. List<string> shopIds = null;
  3289. foreach (DataRow row in design_dt.Rows)
  3290. {
  3291. if ("0".Equals(row["designId"].ToString()))
  3292. {
  3293. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3294. {
  3295. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3296. }
  3297. else
  3298. {
  3299. shopIds = new List<string>();
  3300. }
  3301. shopIds.Add(row["shopId"].ToString());
  3302. shop_orders[row["orders"].ToString()] = shopIds;
  3303. }
  3304. else
  3305. {
  3306. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3307. {
  3308. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3309. }
  3310. else
  3311. {
  3312. design = new Dictionary<string, string>();
  3313. }
  3314. design[row["orders"].ToString()] = row["designId"].ToString();
  3315. design_orders[row["shopId"].ToString()] = design;
  3316. }
  3317. }
  3318. //处理成key value后根据key排序
  3319. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3320. foreach (List<string> val in shop_orders.Values)
  3321. {
  3322. if (val != null)
  3323. {
  3324. foreach (string key in val)
  3325. {
  3326. if (design_orders.ContainsKey(key.ToString()))
  3327. {
  3328. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3329. }
  3330. }
  3331. }
  3332. }
  3333. }
  3334. //校验哪个优先级有订单
  3335. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3336. foreach (string key in shop_orders.Keys)
  3337. {
  3338. List<string> ids = null;
  3339. shop_orders.TryGetValue(key, out ids);
  3340. //id为shopid
  3341. foreach (string id in ids)
  3342. {
  3343. Dictionary<string, int> list = null;
  3344. Dictionary<string, string> desing = null;
  3345. map.TryGetValue(id, out list);
  3346. design_orders.TryGetValue(id, out desing);
  3347. if (list != null && desing != null)
  3348. {
  3349. foreach (var item in desing)
  3350. {
  3351. int count = 0;
  3352. if (list.ContainsKey(item.Value))
  3353. {
  3354. list.TryGetValue(item.Value, out count);
  3355. if (count > 0)
  3356. {
  3357. designIds[id] = item.Value;
  3358. break;
  3359. }
  3360. }
  3361. }
  3362. }
  3363. }
  3364. if (designIds.Count > 0)
  3365. {
  3366. break;
  3367. }
  3368. }
  3369. DataTable table = new DataTable();
  3370. table.Columns.Add("tid", typeof(string));
  3371. table.Columns.Add("ctid", typeof(string));
  3372. table.Columns.Add("seller_nick", typeof(string));
  3373. table.Columns.Add("productName", typeof(string));
  3374. table.Columns.Add("pay_time", typeof(string));
  3375. table.Columns.Add("seller_memo", typeof(string));
  3376. if (designIds.Count > 0)
  3377. {
  3378. string shopId = "";
  3379. string productId = "";
  3380. foreach (var designInfo in designIds)
  3381. {
  3382. shopId = designInfo.Key;
  3383. productId = designInfo.Value;
  3384. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3385. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3386. if (dt.Rows.Count > 0)
  3387. {
  3388. foreach (DataRow row in dt.Rows)
  3389. {
  3390. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3391. {
  3392. DataRow data = table.NewRow();
  3393. data["ctid"] = row["ctid"].ToString();
  3394. data["tid"] = row["tid"].ToString();
  3395. data["seller_nick"] = ceErpShop.ShopName;
  3396. data["pay_time"] = row["pay_time"].ToString();
  3397. data["seller_memo"] = row["seller_memo"].ToString();
  3398. data["productName"] = ceErpProduct.PType;
  3399. table.Rows.Add(data);
  3400. }
  3401. }
  3402. }
  3403. }
  3404. }
  3405. writeGridDataTableJson(table.Rows.Count, table);
  3406. }
  3407. private object rushLockObject = new object();
  3408. public void set_erp_grabingorder()
  3409. {
  3410. if (UrlPostParmsCheck("ctid"))
  3411. {
  3412. int total = CurrentUser.User.Person.Total;
  3413. int userId = CurrentUser.User.ID;
  3414. int noFinish = CurrentUser.User.Person.NoFinish;
  3415. int finalization = CurrentUser.User.Person.Finalization;
  3416. string eids = GetPostString("ctid");
  3417. string key = "RushKey_" + userId;
  3418. int count = 0;
  3419. if (erpRedis.RedisHelper.KeyExists(key))
  3420. {
  3421. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3422. if (redisCount != null)
  3423. {
  3424. count = Convert.ToInt32(redisCount);
  3425. }
  3426. }
  3427. if (count >= total)
  3428. {
  3429. returnErrorMsg("半小时内已经抢" + total + "单");
  3430. return;
  3431. }
  3432. string[] ctidlist = eids.Split(',');
  3433. if (count + ctidlist.Length > total)
  3434. {
  3435. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3436. return;
  3437. }
  3438. int itag = 0;
  3439. lock (rushLockObject)
  3440. {
  3441. if (ctidlist.Length > 0)
  3442. {
  3443. string[] dtList = new string[ctidlist.Length];
  3444. for (int i = 0; i < ctidlist.Length; i++)
  3445. {
  3446. dtList[i] = "'" + ctidlist[i] + "'";
  3447. }
  3448. 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"));
  3449. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3450. if (dt_user.Rows.Count > 0)
  3451. {
  3452. int doing = 0;//未定稿
  3453. int finish = 0;//已完成
  3454. foreach (DataRow dr in dt_user.Rows)
  3455. {
  3456. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3457. {
  3458. doing++;
  3459. }
  3460. else
  3461. {
  3462. finish++;
  3463. }
  3464. }
  3465. if (doing >= noFinish)
  3466. {
  3467. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3468. return;
  3469. }
  3470. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3471. {
  3472. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3473. return;
  3474. }
  3475. }
  3476. //校验选择单子状态
  3477. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3478. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3479. if (dt.Rows.Count > 0)
  3480. {
  3481. List<string> list = new List<string>();
  3482. foreach (DataRow dr in dt.Rows)
  3483. {
  3484. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3485. {
  3486. list.Add(dr["ctid"].ToString());
  3487. }
  3488. }
  3489. if (list.Count > 0)
  3490. {
  3491. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3492. return;
  3493. }
  3494. }
  3495. foreach (string ctid in ctidlist)
  3496. {
  3497. CeErpTradeCell entity = null;
  3498. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3499. if (entity != null)
  3500. {
  3501. entity.OrderState = 3;
  3502. entity.DesignUserId = CurrentUser.UserID;
  3503. entity.WaitDesignTime = DateTime.Now;
  3504. entity.StartDesignTime = DateTime.Now;
  3505. entity.Update();
  3506. commonHelper.UpdateRelationOrder(entity.ctid);
  3507. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3508. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3509. itag++;
  3510. }
  3511. }
  3512. }
  3513. }
  3514. count += ctidlist.Length;
  3515. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3516. if (itag == 0)
  3517. returnErrorMsg("没有找到相关订单");
  3518. else
  3519. returnSuccessMsg("抢单成功!");
  3520. return;
  3521. }
  3522. }
  3523. public void get_erp_waitorderlist()
  3524. {
  3525. DataStruct dStruct = GetPostStruct();
  3526. List<string> lw = new List<string>();
  3527. string tid = GetPostString("ctid");
  3528. if (tid.Length > 0)
  3529. {
  3530. string select_tid = getTidByCtid(tid);
  3531. lw.Add(string.Format("tid='{0}'", select_tid));
  3532. }
  3533. string shopname = GetPostString("shopname");
  3534. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3535. string buyernick = GetPostString("buyer_nick");
  3536. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3537. string customer = GetPostString("customer");
  3538. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3539. string design = GetPostString("design");
  3540. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3541. string orderState = GetPostString("orderState");
  3542. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3543. string supplier = GetPostString("supplier");
  3544. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3545. string sellermemo = GetPostString("seller_memo");
  3546. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3547. string otherMemo = GetPostString("otherMemo");
  3548. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3549. string address = GetPostString("address");
  3550. 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));
  3551. string date1 = GetPostString("date1");
  3552. string date2 = GetPostString("date2");
  3553. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3554. if (dw.Length > 0) lw.Add(dw);
  3555. string price1 = GetPostString("price1");
  3556. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3557. string price2 = GetPostString("price2");
  3558. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3559. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3560. lw.Add(string.Format("IsSample != 2 "));
  3561. lw.Add(string.Format("OrderState = 5 "));
  3562. lw.Add(string.Format("IsRefund<={0}", 1));
  3563. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3564. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3565. string pagesize = GetPostString("pagesize");
  3566. if (pagesize != null)
  3567. {
  3568. dStruct.PageSize = 200;
  3569. }
  3570. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3571. List<string> tids = new List<string>();
  3572. if (dt != null)
  3573. {
  3574. dt.Columns.Add("compenPrice", typeof(double));
  3575. foreach (DataRow dr in dt.Rows)
  3576. {
  3577. if (Convert.IsDBNull(dr["compenPrice"]))
  3578. {
  3579. dr["compenPrice"] = 0;
  3580. }
  3581. tids.Add("'" + dr["tid"].ToString() + "'");
  3582. 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();
  3583. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3584. {
  3585. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3586. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3587. entity.SupplierId = suid;
  3588. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3589. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3590. entity.Update();
  3591. }
  3592. }
  3593. }
  3594. if (tids.Count > 0)
  3595. {
  3596. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3597. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3598. if (dt_price != null && dt_price.Rows.Count > 0)
  3599. {
  3600. foreach (DataRow dr in dt_price.Rows)
  3601. {
  3602. foreach (DataRow row in dt.Rows)
  3603. {
  3604. if (row["tid"].Equals(dr["ptid"]))
  3605. {
  3606. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3607. break;
  3608. }
  3609. }
  3610. }
  3611. }
  3612. }
  3613. writeGridDataTableJson(dStruct.TotalCount, dt);
  3614. }
  3615. public void get_erp_supplierwaitorderlist()
  3616. {
  3617. DataStruct dStruct = GetPostStruct();
  3618. List<string> lw = new List<string>();
  3619. string tid = GetPostString("ctid");
  3620. if (tid.Length > 0)
  3621. {
  3622. string select_tid = getTidByCtid(tid);
  3623. lw.Add(string.Format("tid='{0}'", select_tid));
  3624. }
  3625. string shopname = GetPostString("shopname");
  3626. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3627. string sellermemo = GetPostString("seller_memo");
  3628. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3629. string date1 = GetPostString("date1");
  3630. string date2 = GetPostString("date2");
  3631. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3632. if (dw.Length > 0) lw.Add(dw);
  3633. lw.Add(string.Format("OrderState = 5 "));
  3634. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3635. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3636. {
  3637. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3638. }
  3639. string supplier = GetPostString("supplier");
  3640. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3641. {
  3642. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3643. }
  3644. lw.Add(string.Format("IsRefund<={0}", 1));
  3645. dStruct.Order = "FinishDesignTime desc";
  3646. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3647. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3648. if (dt != null)
  3649. {
  3650. foreach (DataRow dr in dt.Rows)
  3651. {
  3652. 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();
  3653. }
  3654. }
  3655. writeGridDataTableJson(dStruct.TotalCount, dt);
  3656. }
  3657. public void upd_erp_verifytosupplier()
  3658. {
  3659. if (UrlPostParmsCheck("ctid"))
  3660. {
  3661. string eids = GetPostString("ctid");
  3662. CeErpTradeCell entity = null;
  3663. string[] eidsList = eids.Split(',');
  3664. if (eidsList.Length <= 0)
  3665. {
  3666. returnErrorMsg("订单号不能空");
  3667. return;
  3668. }
  3669. List<string> tLst = new List<string>();
  3670. foreach (string ctidstr in eidsList)
  3671. {
  3672. tLst.Add("'" + ctidstr + "'");
  3673. CeErpDataSendOrderInfo.createObject(ctidstr);
  3674. }
  3675. string needtids = string.Join(",", tLst.ToArray());
  3676. StringBuilder sql = new StringBuilder();
  3677. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3678. 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);
  3679. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3680. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3681. returnSuccessMsg("操作成功!");
  3682. return;
  3683. /**foreach (string ctidstr in eidsList)
  3684. {
  3685. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3686. if (entity != null)
  3687. {
  3688. if (entity.SupplierId == 0)
  3689. {
  3690. continue;
  3691. }
  3692. entity.IsVerifyToSupplier = true;
  3693. if (entity.IsReturn == 1) //1是供应商打回
  3694. {
  3695. entity.IsReturn = 0;
  3696. }
  3697. entity.FinishPlaceTime = DateTime.Now;
  3698. entity.PlaceUserId = CurrentUser.UserID;
  3699. entity.Update();
  3700. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3701. }
  3702. }
  3703. returnSuccessMsg("操作成功!");
  3704. return;**/
  3705. }
  3706. }
  3707. public void upd_erp_supplierback()
  3708. {
  3709. if (UrlPostParmsCheck("ctid"))
  3710. {
  3711. string eid = GetPostString("ctid");
  3712. string reason = GetPostString("returnreason");
  3713. CeErpTradeCell entity = null;
  3714. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3715. if (entity != null)
  3716. {
  3717. string message = "操作成功!";
  3718. string isDown = "";
  3719. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3720. {
  3721. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3722. isDown = "被点击下载";
  3723. }
  3724. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3725. {
  3726. string key = "return_order_" + entity.SupplierId;
  3727. List<string> list = new List<string>();
  3728. if (RedisHelper.HasKey(key))
  3729. {
  3730. object data = RedisHelper.StringGet(key);
  3731. list = Convert.ToString(data).Split(',').ToList();
  3732. }
  3733. list.Add(eid);
  3734. RedisHelper.StringSet(key, string.Join(",", list));
  3735. }
  3736. entity.IsVerifyToSupplier = false;
  3737. entity.IsReturn = 1;
  3738. entity.IsHaveNewOrder = 0;
  3739. entity.ReturnTime = DateTime.Now;
  3740. entity.ReturnReason = reason;
  3741. if (entity.OrderState == 6)
  3742. {
  3743. entity.OrderState = 5;
  3744. }
  3745. entity.Update();
  3746. CeErpSukuraData.createInfo(entity.ctid, 5);
  3747. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3748. returnSuccessMsg(message);
  3749. return;
  3750. }
  3751. returnErrorMsg("找不到订单记录");
  3752. }
  3753. }
  3754. public void upd_erp_toaftersaleorder()
  3755. {
  3756. if (UrlPostParmsCheck("ctid"))
  3757. {
  3758. string eid = GetPostString("ctid");
  3759. string reason = GetPostString("returnreason");
  3760. CeErpTradeCell entity = null;
  3761. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3762. if (entity != null)
  3763. {
  3764. if (entity.isAfterSaleOrder != 1)
  3765. {
  3766. returnErrorMsg("带S的售后单才能打回给售后");
  3767. return;
  3768. }
  3769. if (entity.OrderState >= 5)
  3770. {
  3771. returnErrorMsg("已经设计完成了不能打回给售后");
  3772. return;
  3773. }
  3774. entity.OrderState = 0;
  3775. entity.IsReturn = 3;
  3776. entity.ReturnTime = DateTime.Now;
  3777. entity.UpdateTime = DateTime.Now;
  3778. entity.ReturnReason = reason;
  3779. entity.Update();
  3780. CeErpSukuraData.createInfo(entity.ctid, 5);
  3781. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3782. returnSuccessMsg("操作成功!");
  3783. return;
  3784. }
  3785. returnErrorMsg("找不到订单记录");
  3786. }
  3787. }
  3788. public void upd_erp_aftersaletodesign()
  3789. {
  3790. if (UrlPostParmsCheck("ctid"))
  3791. {
  3792. string eid = GetPostString("ctid");
  3793. CeErpTradeCell entity = null;
  3794. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3795. if (entity != null)
  3796. {
  3797. entity.OrderState = 3;
  3798. entity.IsReturn = 0;
  3799. entity.UpdateTime = DateTime.Now;
  3800. entity.Update();
  3801. CeErpSukuraData.createInfo(entity.ctid, 5);
  3802. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3803. returnSuccessMsg("操作成功!");
  3804. return;
  3805. }
  3806. returnErrorMsg("找不到订单记录");
  3807. }
  3808. }
  3809. public void assign_erp_supplier()
  3810. {
  3811. if (UrlPostParmsCheck("ctid"))
  3812. {
  3813. string eids = GetPostString("ctid");
  3814. int sid = GetPostInt("SupplierName");
  3815. string fromTag = GetPostString("tag");
  3816. string[] eidList = eids.Split(',');
  3817. if (eidList.Length <= 0)
  3818. {
  3819. returnErrorMsg("指派不能为空");
  3820. return;
  3821. }
  3822. string errMsg = "";
  3823. string suname = commonHelper.getSupplierNameById(sid);
  3824. foreach (string ctid in eidList)
  3825. {
  3826. CeErpTradeCell entity = null;
  3827. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3828. if (entity != null)
  3829. {
  3830. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3831. {
  3832. errMsg += (ctid + "指派失败!!!");
  3833. continue;
  3834. }
  3835. entity.SupplierId = sid;
  3836. entity.Update();
  3837. commonHelper.UpdateRelationOrder(entity.ctid);
  3838. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3839. if (entity.OrderState >= 6)
  3840. {
  3841. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3842. //{
  3843. // string msl = entity.MakeSupplier;
  3844. // string[] mslist = msl.Split(',');
  3845. // 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);
  3846. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3847. //}
  3848. //else
  3849. //{
  3850. StringBuilder sql = new StringBuilder();
  3851. 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);
  3852. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3853. //}
  3854. }
  3855. }
  3856. else
  3857. {
  3858. continue;
  3859. }
  3860. }
  3861. if (errMsg.Length > 0)
  3862. {
  3863. returnErrorMsg(errMsg);
  3864. return;
  3865. }
  3866. returnSuccessMsg("操作成功!");
  3867. return;
  3868. }
  3869. }
  3870. public void assign_erp_makesupplier()
  3871. {
  3872. if (UrlPostParmsCheck("ctid"))
  3873. {
  3874. string eids = GetPostString("ctid");
  3875. string sname = GetPostString("SupplierName");
  3876. string[] eidList = eids.Split(',');
  3877. if (eidList.Length <= 0)
  3878. {
  3879. returnErrorMsg("指派不能为空");
  3880. return;
  3881. }
  3882. List<string> tLst = new List<string>();
  3883. foreach (string ctid in eidList)
  3884. {
  3885. CeErpTradeCell entity = null;
  3886. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3887. if (entity != null)
  3888. {
  3889. entity.MakeSupplier = sname;
  3890. entity.Update();
  3891. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3892. tLst.Add("'" + ctid + "'");
  3893. }
  3894. else
  3895. {
  3896. continue;
  3897. }
  3898. }
  3899. string ctids = string.Join(",", tLst.ToArray());
  3900. StringBuilder sql2 = new StringBuilder();
  3901. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3902. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3903. returnSuccessMsg("操作成功!");
  3904. return;
  3905. }
  3906. }
  3907. public void ins_erp_returnreason()
  3908. {
  3909. if (UrlPostParmsCheck("ctid"))
  3910. {
  3911. string eid = GetPostString("ctid");
  3912. CeErpTradeCell entity = null;
  3913. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3914. string userpost = CurrentUser.UserPost.Post.Code;
  3915. if (entity != null)
  3916. {
  3917. bool isPlace = false;
  3918. if (entity.OrderState > 6)
  3919. {
  3920. returnErrorMsg("已发货无法打回!");
  3921. return;
  3922. }
  3923. if (entity.OrderState == 6)
  3924. {
  3925. isPlace = true;
  3926. }
  3927. bool isNeedUpdateCell2 = false;
  3928. if (entity.OrderState >= 6)
  3929. {
  3930. isNeedUpdateCell2 = true;
  3931. }
  3932. int returnTag = 2;
  3933. if (userpost == "Supplier")
  3934. {
  3935. returnTag = 1;
  3936. }
  3937. int toType = GetPostInt("totype");
  3938. string fromType = "3";
  3939. if (entity.OrderState < 5)
  3940. {
  3941. fromType = "3";
  3942. }
  3943. else
  3944. {
  3945. fromType = "4";
  3946. }
  3947. if (entity.IsXianHuo == 0)
  3948. {
  3949. if (returnTag == 2)
  3950. {
  3951. if (toType == 1)
  3952. {
  3953. entity.OrderState = 0;
  3954. entity.ReturnUserType = 1;
  3955. string clearman = GetPostString("clearman");
  3956. if (!string.IsNullOrEmpty(clearman))
  3957. {
  3958. entity.DesignUserId = 0;
  3959. }
  3960. }
  3961. else
  3962. {
  3963. entity.OrderState = 3;
  3964. entity.ReturnUserType = 2;
  3965. }
  3966. entity.IsReadTag = 1;
  3967. }
  3968. else if (returnTag == 1)
  3969. {
  3970. entity.OrderState = 5;
  3971. }
  3972. entity.IsVerifyToSupplier = false;
  3973. }
  3974. if (entity.IsXianHuo == 1)
  3975. {
  3976. entity.OrderState = 5;
  3977. }
  3978. entity.UnusualTag = 0;
  3979. entity.UnusualTime = null;
  3980. entity.UnusualCon = "";
  3981. entity.IsReturn = returnTag;
  3982. entity.ReturnTime = DateTime.Now;
  3983. entity.UpdateTime = DateTime.Now;
  3984. entity.ReturnReason = GetPostString("returnreason");
  3985. entity.Update();
  3986. if (entity.OrderState == 3)
  3987. {
  3988. ApiVo apiVo = new ApiVo();
  3989. apiVo.orderNumber = entity.ctid;
  3990. apiVo.actionName = "rebutDesign";
  3991. apiVo.orderRemarks = entity.ReturnReason;
  3992. designHelper.API_WorkCore(apiVo);//rebutDesign
  3993. }
  3994. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3995. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3996. {
  3997. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3998. }
  3999. CeErpSukuraData.createInfo(entity.ctid, 5);
  4000. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4001. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4002. if (isPlace)
  4003. {
  4004. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  4005. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4006. if (dth != null && dth.Rows.Count > 0)
  4007. {
  4008. dataSendOrderBean dataSendOrderBean = null;
  4009. foreach (DataRow item in dth.Rows)
  4010. {
  4011. try
  4012. {
  4013. dataSendOrderBean = new dataSendOrderBean();
  4014. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  4015. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  4016. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  4017. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  4018. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  4019. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  4020. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  4021. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  4022. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  4023. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  4024. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  4025. dataSendOrderBean.Radio1723534706288 = "打回";
  4026. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  4027. if (result != null)
  4028. {
  4029. if ("0".Equals(result.errcode))
  4030. {
  4031. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  4032. }
  4033. else
  4034. {
  4035. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  4036. }
  4037. }
  4038. }
  4039. catch (Exception ex)
  4040. {
  4041. }
  4042. }
  4043. }
  4044. }
  4045. if (isNeedUpdateCell2)
  4046. {
  4047. if (entity.MakeSupplier.IndexOf(",") != -1)
  4048. {
  4049. StringBuilder sql2 = new StringBuilder();
  4050. 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);
  4051. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4052. }
  4053. else
  4054. {
  4055. StringBuilder sql2 = new StringBuilder();
  4056. 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);
  4057. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4058. }
  4059. }
  4060. returnSuccessMsg("操作成功!");
  4061. return;
  4062. }
  4063. returnErrorMsg("找不到订单记录");
  4064. }
  4065. }
  4066. public void cyt_erp_returnreason()
  4067. {
  4068. if (UrlPostParmsCheck("ctid"))
  4069. {
  4070. string eid = GetPostString("ctid");
  4071. CeErpTradeCell entity = null;
  4072. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4073. string userpost = CurrentUser.UserPost.Post.Code;
  4074. if (entity != null)
  4075. {
  4076. if (entity.OrderState > 6)
  4077. {
  4078. returnErrorMsg("已发货无法打回!");
  4079. return;
  4080. }
  4081. JObject jsonObject = new JObject
  4082. {
  4083. { "Userid", "77886" },
  4084. { "Pwd", "lt666888" },
  4085. { "LTOrderId",eid }
  4086. };
  4087. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  4088. JObject jsonObjects = JObject.Parse(response);
  4089. string msg = (string)jsonObjects["msg"];
  4090. if (msg != "取消成功")
  4091. {
  4092. returnErrorMsg(msg);
  4093. return;
  4094. }
  4095. bool isNeedUpdateCell2 = false;
  4096. if (entity.OrderState >= 6)
  4097. {
  4098. isNeedUpdateCell2 = true;
  4099. }
  4100. int returnTag = 2;
  4101. if (userpost == "Supplier")
  4102. {
  4103. returnTag = 1;
  4104. }
  4105. if (entity.IsXianHuo == 0)
  4106. {
  4107. if (returnTag == 2)
  4108. {
  4109. int toType = GetPostInt("totype");
  4110. if (toType == 1)
  4111. {
  4112. entity.OrderState = 0;
  4113. entity.ReturnUserType = 1;
  4114. }
  4115. else
  4116. {
  4117. entity.OrderState = 4;
  4118. entity.ReturnUserType = 2;
  4119. }
  4120. entity.IsReadTag = 1;
  4121. }
  4122. else if (returnTag == 1)
  4123. {
  4124. entity.OrderState = 5;
  4125. }
  4126. entity.IsVerifyToSupplier = false;
  4127. }
  4128. entity.UnusualTag = 0;
  4129. entity.UnusualTime = null;
  4130. entity.UnusualCon = "";
  4131. entity.IsReturn = returnTag;
  4132. entity.ReturnTime = DateTime.Now;
  4133. entity.ReturnReason = GetPostString("returnreason");
  4134. entity.Update();
  4135. if (entity.OrderState == 4)
  4136. {
  4137. ApiVo apiVo = new ApiVo();
  4138. apiVo.orderNumber = entity.ctid;
  4139. apiVo.actionName = "rebutDesign";
  4140. apiVo.orderRemarks = entity.ReturnReason;
  4141. designHelper.API_WorkCore(apiVo);//rebutDesign
  4142. }
  4143. CeErpSukuraData.createInfo(entity.ctid, 5);
  4144. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4145. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4146. if (isNeedUpdateCell2)
  4147. {
  4148. if (entity.MakeSupplier.IndexOf(",") != -1)
  4149. {
  4150. StringBuilder sql2 = new StringBuilder();
  4151. 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);
  4152. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4153. }
  4154. else
  4155. {
  4156. StringBuilder sql2 = new StringBuilder();
  4157. 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);
  4158. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4159. }
  4160. }
  4161. returnSuccessMsg("操作成功!");
  4162. return;
  4163. }
  4164. returnErrorMsg("找不到订单记录");
  4165. }
  4166. }
  4167. public void upd_erp_xianhuoreturntag()
  4168. {
  4169. if (UrlPostParmsCheck("ctid"))
  4170. {
  4171. string eids = GetPostString("ctid");
  4172. string[] ctids = eids.Split(',');
  4173. foreach (string ctid in ctids)
  4174. {
  4175. CeErpTradeCell entity = null;
  4176. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4177. if (entity != null)
  4178. {
  4179. entity.IsReturn = 0;
  4180. entity.Update();
  4181. CeErpSukuraData.createInfo(entity.ctid, 5);
  4182. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4183. }
  4184. }
  4185. returnSuccessMsg("操作成功!");
  4186. return;
  4187. }
  4188. }
  4189. public void get_erp_waitdeliverylist()
  4190. {
  4191. DataStruct dStruct = GetPostStruct();
  4192. List<string> lw = new List<string>();
  4193. string tid = GetPostString("ctid");
  4194. if (tid.Length > 0)
  4195. {
  4196. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4197. if (tid.Length > 5)
  4198. {
  4199. List<string> tids = getTidByCtidLike(tid);
  4200. if (tids.Count > 0 && tids.Count < 10)
  4201. {
  4202. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4203. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4204. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4205. {
  4206. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4207. }*/
  4208. }
  4209. }
  4210. lw.Add(tid_sql);
  4211. }
  4212. string shopname = GetPostString("shopname");
  4213. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4214. string buyernick = GetPostString("buyer_nick");
  4215. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4216. //if (tid.Length == 0 && buyernick.Length == 0)
  4217. //{
  4218. // lw.Add(string.Format("IsRefund<={0}", 1));
  4219. //}
  4220. string customer = GetPostString("customer");
  4221. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4222. string design = GetPostString("design");
  4223. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4224. string orderState = GetPostString("orderState");
  4225. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4226. string address = GetPostString("address");
  4227. 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));
  4228. string sellermemo = GetPostString("seller_memo");
  4229. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4230. string supplier = GetPostString("supplier");
  4231. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4232. string OrderArea = GetPostString("order_area");
  4233. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4234. string placedate1 = GetPostString("placedate1");
  4235. string placedate2 = GetPostString("placedate2");
  4236. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4237. if (fdw.Length > 0) lw.Add(fdw);
  4238. string price1 = GetPostString("price1");
  4239. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4240. string price2 = GetPostString("price2");
  4241. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4242. string unusualCon = GetPostString("unusualcon");
  4243. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4244. string otherMemo = GetPostString("otherMemo");
  4245. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4246. string posTag = CurrentUser.UserPost.Post.Code;
  4247. if (posTag == "Supplier")
  4248. {
  4249. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4250. }
  4251. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4252. lw.Add(string.Format("type != 'PDD' "));
  4253. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4254. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4255. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4256. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4257. writeGridDataTableJson(dStruct.TotalCount, dt);
  4258. }
  4259. public void get_erp_changedeliverylist()
  4260. {
  4261. DataStruct dStruct = GetPostStruct();
  4262. List<string> lw = new List<string>();
  4263. string tid = GetPostString("ctid");
  4264. if (tid.Length > 0)
  4265. {
  4266. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4267. if (tid.Length > 5)
  4268. {
  4269. List<string> tids = getTidByCtidLike(tid);
  4270. if (tids.Count > 0 && tids.Count < 10)
  4271. {
  4272. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4273. }
  4274. }
  4275. lw.Add(tid_sql);
  4276. }
  4277. string shopname = GetPostString("shopname");
  4278. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4279. string buyernick = GetPostString("buyer_nick");
  4280. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4281. //if (tid.Length == 0 && buyernick.Length == 0)
  4282. //{
  4283. // lw.Add(string.Format("IsRefund<={0}", 1));
  4284. //}
  4285. string customer = GetPostString("customer");
  4286. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4287. string design = GetPostString("design");
  4288. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4289. string orderState = GetPostString("orderState");
  4290. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4291. string address = GetPostString("address");
  4292. 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));
  4293. string sellermemo = GetPostString("seller_memo");
  4294. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4295. string supplier = GetPostString("supplier");
  4296. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4297. string OrderArea = GetPostString("order_area");
  4298. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4299. string placedate1 = GetPostString("placedate1");
  4300. string placedate2 = GetPostString("placedate2");
  4301. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4302. if (fdw.Length > 0) lw.Add(fdw);
  4303. string price1 = GetPostString("price1");
  4304. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4305. string price2 = GetPostString("price2");
  4306. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4307. string unusualCon = GetPostString("unusualcon");
  4308. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4309. string otherMemo = GetPostString("otherMemo");
  4310. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4311. string posTag = CurrentUser.UserPost.Post.Code;
  4312. if (posTag == "Supplier")
  4313. {
  4314. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4315. }
  4316. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4317. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4318. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4319. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4320. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4321. /*if (tid.Length > 0)
  4322. {
  4323. List<string> tids = new List<string>();
  4324. if (dt != null && dt.Rows.Count > 0)
  4325. {
  4326. foreach (DataRow item in dt.Rows)
  4327. {
  4328. tids.Add("'" + item["tid"] + "'");
  4329. }
  4330. }
  4331. if (tids.Count > 0)
  4332. {
  4333. lw.RemoveAt(0);
  4334. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4335. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4336. dt = WebCache.GetData("view_erptradecell", dStruct);
  4337. }
  4338. }*/
  4339. writeGridDataTableJson(dStruct.TotalCount, dt);
  4340. }
  4341. public void get_erp_pddderiving()
  4342. {
  4343. DataStruct dStruct = GetPostStruct();
  4344. List<string> lw = new List<string>();
  4345. string tid = GetPostString("ctid");
  4346. if (tid.Length > 0)
  4347. {
  4348. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4349. if (tid.Length > 5)
  4350. {
  4351. List<string> tids = getTidByCtidLike(tid);
  4352. if (tids.Count > 0 && tids.Count < 10)
  4353. {
  4354. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4355. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4356. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4357. {
  4358. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4359. }*/
  4360. }
  4361. }
  4362. lw.Add(tid_sql);
  4363. }
  4364. string shopname = GetPostString("shopname");
  4365. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4366. string buyernick = GetPostString("buyer_nick");
  4367. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4368. //if (tid.Length == 0 && buyernick.Length == 0)
  4369. //{
  4370. // lw.Add(string.Format("IsRefund<={0}", 1));
  4371. //}
  4372. string customer = GetPostString("customer");
  4373. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4374. string design = GetPostString("design");
  4375. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4376. string orderState = GetPostString("orderState");
  4377. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4378. string address = GetPostString("address");
  4379. 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));
  4380. string sellermemo = GetPostString("seller_memo");
  4381. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4382. string supplier = GetPostString("supplier");
  4383. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4384. string OrderArea = GetPostString("order_area");
  4385. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4386. string placedate1 = GetPostString("placedate1");
  4387. string placedate2 = GetPostString("placedate2");
  4388. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4389. if (fdw.Length > 0) lw.Add(fdw);
  4390. string price1 = GetPostString("price1");
  4391. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4392. string price2 = GetPostString("price2");
  4393. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4394. string unusualCon = GetPostString("unusualcon");
  4395. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4396. string posTag = CurrentUser.UserPost.Post.Code;
  4397. if (posTag == "Supplier")
  4398. {
  4399. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4400. }
  4401. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4402. lw.Add(string.Format("type = 'PDD' "));
  4403. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4404. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4405. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4406. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4407. /*if (tid.Length > 0)
  4408. {
  4409. List<string> tids = new List<string>();
  4410. if (dt != null && dt.Rows.Count > 0)
  4411. {
  4412. foreach (DataRow item in dt.Rows)
  4413. {
  4414. tids.Add("'" + item["tid"] + "'");
  4415. }
  4416. }
  4417. if (tids.Count > 0)
  4418. {
  4419. lw.RemoveAt(0);
  4420. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4421. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4422. dt = WebCache.GetData("view_erptradecell", dStruct);
  4423. }
  4424. }*/
  4425. writeGridDataTableJson(dStruct.TotalCount, dt);
  4426. }
  4427. public void get_erp_jdderiving()
  4428. {
  4429. DataStruct dStruct = GetPostStruct();
  4430. List<string> lw = new List<string>();
  4431. string tid = GetPostString("ctid");
  4432. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4433. string shopname = GetPostString("shopname");
  4434. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4435. string buyernick = GetPostString("buyer_nick");
  4436. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4437. //if (tid.Length == 0 && buyernick.Length == 0)
  4438. //{
  4439. // lw.Add(string.Format("IsRefund<={0}", 1));
  4440. //}
  4441. string customer = GetPostString("customer");
  4442. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4443. string design = GetPostString("design");
  4444. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4445. string orderState = GetPostString("orderState");
  4446. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4447. string address = GetPostString("address");
  4448. 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));
  4449. string sellermemo = GetPostString("seller_memo");
  4450. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4451. string supplier = GetPostString("supplier");
  4452. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4453. string OrderArea = GetPostString("order_area");
  4454. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4455. string placedate1 = GetPostString("placedate1");
  4456. string placedate2 = GetPostString("placedate2");
  4457. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4458. if (fdw.Length > 0) lw.Add(fdw);
  4459. string price1 = GetPostString("price1");
  4460. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4461. string price2 = GetPostString("price2");
  4462. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4463. string unusualCon = GetPostString("unusualcon");
  4464. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4465. string posTag = CurrentUser.UserPost.Post.Code;
  4466. if (posTag == "Supplier")
  4467. {
  4468. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4469. }
  4470. lw.Add(string.Format("OrderState = 6 "));
  4471. lw.Add(string.Format("type = 'JD' "));
  4472. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4473. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4474. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4475. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4476. writeGridDataTableJson(dStruct.TotalCount, dt);
  4477. }
  4478. public void get_erp_demoorderlist()
  4479. {
  4480. DataStruct dStruct = GetPostStruct();
  4481. List<string> lw = new List<string>();
  4482. string tid = GetPostString("ctid");
  4483. if (tid.Length > 0)
  4484. {
  4485. string select_tid = getTidByCtid(tid);
  4486. lw.Add(string.Format("tid='{0}'", select_tid));
  4487. }
  4488. string shopname = GetPostString("shopname");
  4489. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4490. string buyernick = GetPostString("buyer_nick");
  4491. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4492. string customer = GetPostString("customer");
  4493. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4494. string design = GetPostString("design");
  4495. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4496. string orderState = GetPostString("orderState");
  4497. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4498. string address = GetPostString("address");
  4499. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4500. string sellermemo = GetPostString("seller_memo");
  4501. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4502. string supplier = GetPostString("supplier");
  4503. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4504. string OrderArea = GetPostString("order_area");
  4505. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4506. string date1 = GetPostString("date1");
  4507. string date2 = GetPostString("date2");
  4508. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4509. if (dw.Length > 0) lw.Add(dw);
  4510. string price1 = GetPostString("price1");
  4511. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4512. string price2 = GetPostString("price2");
  4513. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4514. string posTag = CurrentUser.UserPost.Post.Code;
  4515. if (posTag == "Supplier")
  4516. {
  4517. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4518. }
  4519. //lw.Add(string.Format("OrderState = 6 "));
  4520. lw.Add(string.Format("IsSample={0}", 3));
  4521. lw.Add(string.Format("IsRefund<={0}", 1));
  4522. dStruct.Order = "pay_time desc";
  4523. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4524. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4525. writeGridDataTableJson(dStruct.TotalCount, dt);
  4526. }
  4527. public void save_erp_checkmemo()
  4528. {
  4529. if (UrlPostParmsCheck("ctid"))
  4530. {
  4531. string ctid = GetPostString("ctid");
  4532. CeErpTradeCell entity = null;
  4533. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4534. if (entity != null)
  4535. {
  4536. entity.CheckMemo = GetPostString("CheckMemo");
  4537. entity.Update();
  4538. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4539. if (trade != null)
  4540. {
  4541. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4542. }
  4543. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4544. returnSuccessMsg("保存成功!");
  4545. return;
  4546. }
  4547. returnErrorMsg("找不到记录");
  4548. }
  4549. }
  4550. public void get_erp_returnlist()
  4551. {
  4552. DataStruct dStruct = GetPostStruct();
  4553. List<string> lw = new List<string>();
  4554. string tid = GetPostString("ctid");
  4555. if (tid.Length > 0)
  4556. {
  4557. string select_tid = getTidByCtid(tid);
  4558. lw.Add(string.Format("tid='{0}'", select_tid));
  4559. }
  4560. string shopname = GetPostString("shopname");
  4561. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4562. string buyernick = GetPostString("buyer_nick");
  4563. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4564. string customer = GetPostString("customer");
  4565. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4566. string design = GetPostString("design");
  4567. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4568. string orderState = GetPostString("orderState");
  4569. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4570. string address = GetPostString("address");
  4571. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4572. string sellermemo = GetPostString("seller_memo");
  4573. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4574. string supplier = GetPostString("supplier");
  4575. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4576. string date1 = GetPostString("date1");
  4577. string date2 = GetPostString("date2");
  4578. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4579. if (dw.Length > 0) lw.Add(dw);
  4580. string bdate1 = GetPostString("backdate1");
  4581. string bdate2 = GetPostString("backdate2");
  4582. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4583. if (dw_back.Length > 0) lw.Add(dw_back);
  4584. string price1 = GetPostString("price1");
  4585. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4586. string price2 = GetPostString("price2");
  4587. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4588. lw.Add(string.Format("IsReturn>0"));
  4589. lw.Add(string.Format("IsXianHuo=0"));
  4590. lw.Add(string.Format("IsReturn!=3"));
  4591. string backtype = GetPostString("backtype");
  4592. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4593. dStruct.Order = "FinishDesignTime desc";
  4594. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4595. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4596. writeGridDataTableJson(dStruct.TotalCount, dt);
  4597. }
  4598. public void get_erp_today_sumreturn()
  4599. {
  4600. DataStruct dStruct = GetPostStruct();
  4601. List<string> lw = new List<string>();
  4602. string bdate1 = GetPostString("returnTimeS");
  4603. string bdate2 = GetPostString("returnTimeE");
  4604. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4605. if (dw_back.Length > 0) lw.Add(dw_back);
  4606. lw.Add(string.Format("IsReturn=0"));
  4607. lw.Add(string.Format("IsXianHuo=0"));
  4608. string mainWhere = string.Join(" and ", lw.ToArray());
  4609. string sql = "";
  4610. if (dw_back.Length > 0)
  4611. {
  4612. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4613. }
  4614. else
  4615. {
  4616. 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 + "'";
  4617. }
  4618. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4619. decimal total = 0, today_finish = 0;
  4620. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4621. {
  4622. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4623. }
  4624. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4625. {
  4626. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4627. }
  4628. var res = new
  4629. {
  4630. data = total,
  4631. data1 = today_finish,
  4632. };
  4633. string ro_jsond = JsonConvert.SerializeObject(res);
  4634. returnSuccess(ro_jsond);
  4635. return;
  4636. }
  4637. public void get_erp_allreturnlist()
  4638. {
  4639. DataStruct dStruct = GetPostStruct();
  4640. List<string> lw = new List<string>();
  4641. string tid = GetPostString("ctid");
  4642. if (tid.Length > 0)
  4643. {
  4644. string select_tid = getTidByCtid(tid);
  4645. lw.Add(string.Format("tid='{0}'", select_tid));
  4646. }
  4647. string shopname = GetPostString("shopname");
  4648. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4649. string buyernick = GetPostString("buyer_nick");
  4650. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4651. string customer = GetPostString("customer");
  4652. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4653. string design = GetPostString("design");
  4654. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4655. string orderState = GetPostString("orderState");
  4656. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4657. string address = GetPostString("address");
  4658. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4659. string sellermemo = GetPostString("seller_memo");
  4660. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4661. string supplier = GetPostString("supplier");
  4662. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4663. string date1 = GetPostString("date1");
  4664. string date2 = GetPostString("date2");
  4665. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4666. if (dw.Length > 0) lw.Add(dw);
  4667. string bdate1 = GetPostString("backdate1");
  4668. string bdate2 = GetPostString("backdate2");
  4669. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4670. if (dw_back.Length > 0) lw.Add(dw_back);
  4671. string price1 = GetPostString("price1");
  4672. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4673. string price2 = GetPostString("price2");
  4674. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4675. string backreason = GetPostString("backreason");
  4676. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4677. lw.Add(string.Format("IsXianHuo=0"));
  4678. lw.Add(string.Format("ReturnTime != ''"));
  4679. string backtype = GetPostString("backtype");
  4680. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4681. dStruct.Order = "FinishDesignTime desc";
  4682. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4683. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4684. writeGridDataTableJson(dStruct.TotalCount, dt);
  4685. }
  4686. public void get_erp_aftersalereturnlist()
  4687. {
  4688. DataStruct dStruct = GetPostStruct();
  4689. List<string> lw = new List<string>();
  4690. string tid = GetPostString("ctid");
  4691. if (tid.Length > 0)
  4692. {
  4693. string select_tid = getTidByCtid(tid);
  4694. lw.Add(string.Format("tid='{0}'", select_tid));
  4695. }
  4696. string shopname = GetPostString("shopname");
  4697. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4698. string buyernick = GetPostString("buyer_nick");
  4699. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4700. string customer = GetPostString("customer");
  4701. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4702. string design = GetPostString("design");
  4703. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4704. string orderState = GetPostString("orderState");
  4705. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4706. string address = GetPostString("address");
  4707. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4708. string sellermemo = GetPostString("seller_memo");
  4709. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4710. string supplier = GetPostString("supplier");
  4711. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4712. string date1 = GetPostString("date1");
  4713. string date2 = GetPostString("date2");
  4714. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4715. if (dw.Length > 0) lw.Add(dw);
  4716. string bdate1 = GetPostString("backdate1");
  4717. string bdate2 = GetPostString("backdate2");
  4718. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4719. if (dw_back.Length > 0) lw.Add(dw_back);
  4720. string price1 = GetPostString("price1");
  4721. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4722. string price2 = GetPostString("price2");
  4723. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4724. lw.Add(string.Format("IsReturn=3"));
  4725. string backtype = GetPostString("backtype");
  4726. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4727. string backreason = GetPostString("backreason");
  4728. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4729. dStruct.Order = "ReturnTime desc";
  4730. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4731. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4732. writeGridDataTableJson(dStruct.TotalCount, dt);
  4733. }
  4734. public void get_erp_xianhuoreturnlist()
  4735. {
  4736. DataStruct dStruct = GetPostStruct();
  4737. List<string> lw = new List<string>();
  4738. string tid = GetPostString("ctid");
  4739. if (tid.Length > 0)
  4740. {
  4741. string select_tid = getTidByCtid(tid);
  4742. lw.Add(string.Format("tid='{0}'", select_tid));
  4743. }
  4744. string shopname = GetPostString("shopname");
  4745. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4746. string buyernick = GetPostString("buyer_nick");
  4747. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4748. string customer = GetPostString("customer");
  4749. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4750. string design = GetPostString("design");
  4751. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4752. string orderState = GetPostString("orderState");
  4753. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4754. string address = GetPostString("address");
  4755. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4756. string sellermemo = GetPostString("seller_memo");
  4757. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4758. string supplier = GetPostString("supplier");
  4759. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4760. string OrderArea = GetPostString("order_area");
  4761. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4762. string date1 = GetPostString("date1");
  4763. string date2 = GetPostString("date2");
  4764. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4765. if (dw.Length > 0) lw.Add(dw);
  4766. string price1 = GetPostString("price1");
  4767. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4768. string price2 = GetPostString("price2");
  4769. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4770. string posTag = CurrentUser.UserPost.Post.Code;
  4771. if (posTag == "Supplier")
  4772. {
  4773. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4774. }
  4775. lw.Add(string.Format("OrderState=6 "));
  4776. lw.Add(string.Format("IsXianHuo=1 "));
  4777. lw.Add(string.Format("IsReturn>0 "));
  4778. lw.Add(string.Format("IsReturn!=3"));
  4779. lw.Add(string.Format("IsRefund<={0}", 1));
  4780. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4781. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4782. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4783. writeGridDataTableJson(dStruct.TotalCount, dt);
  4784. }
  4785. public void set_erp_orderdelivery()
  4786. {
  4787. if (UrlPostParmsCheck("ctid"))
  4788. {
  4789. string eid = GetPostString("ctid");
  4790. CeErpTradeCell entity = null;
  4791. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4792. if (entity != null)
  4793. {
  4794. if (entity.OrderState >= 7)
  4795. {
  4796. returnErrorMsg("此单已发货,无需重复发货");
  4797. return;
  4798. }
  4799. if (entity.OrderState != 6)
  4800. {
  4801. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4802. return;
  4803. }
  4804. string shop = GetPostString("seller_nick");
  4805. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4806. string comName = GetPostString("comName");
  4807. string comCode = GetPostString("comCode");
  4808. string outSid = GetPostString("outSid");
  4809. string deliveryType = GetPostString("deliveryType");
  4810. string deliveryMemo = GetPostString("deliveryMemo");
  4811. outSid = outSid.Trim();
  4812. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4813. if (mainEn == null)
  4814. {
  4815. returnErrorMsg("找不到原始订单记录");
  4816. return;
  4817. }
  4818. bool isInitOrderDeliv = false;
  4819. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4820. {
  4821. isInitOrderDeliv = true;
  4822. }
  4823. string apires = "";
  4824. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4825. 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)
  4826. {
  4827. apires = "发货成功true";
  4828. }
  4829. else
  4830. {
  4831. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4832. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4833. }
  4834. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4835. {
  4836. entity.OrderState = 7;//发货后订单已发货
  4837. entity.OutSid = outSid;
  4838. entity.MemoOpt = 0;
  4839. entity.UpdateTime = DateTime.Now;
  4840. entity.FinishDeliveryTime = DateTime.Now;
  4841. entity.Update();
  4842. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4843. commonHelper.UpdateRelationOrder(entity.ctid);
  4844. //还要插入快递信息到 快递信息表
  4845. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4846. exinfo.tid = eid;
  4847. exinfo.out_sid = outSid;
  4848. exinfo.company_code = comCode;
  4849. exinfo.company_name = comName;
  4850. exinfo.delivery_memo = deliveryMemo;
  4851. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4852. exinfo.deliveryType = deliveryType;
  4853. exinfo.Create();
  4854. returnSuccessMsg("发货操作成功!");
  4855. commonHelper.UpdateRelationOrder(entity.ctid);
  4856. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4857. CeErpSukuraData.createInfo(entity.ctid, 4);
  4858. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  4859. {
  4860. commonHelper.sendCytExpress(exinfo);
  4861. }
  4862. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4863. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid + ",备注:" + deliveryMemo, entity.OrderState);
  4864. }
  4865. else
  4866. {
  4867. string errmsg = commonHelper.KeepChinese(apires);
  4868. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4869. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4870. }
  4871. return;
  4872. }
  4873. returnErrorMsg("找不到订单记录");
  4874. }
  4875. }
  4876. public void set_erp_multidelivery()
  4877. {
  4878. string eids = GetPostString("tids");
  4879. string[] eidList = eids.Split(',');
  4880. if (eidList.Length <= 0)
  4881. {
  4882. returnErrorMsg("发货不能为空");
  4883. return;
  4884. }
  4885. foreach (string ctid in eidList)
  4886. {
  4887. if (ctid.Length <= 0) continue;
  4888. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4889. if (expInfo != null)
  4890. {
  4891. StringBuilder sql = new StringBuilder();
  4892. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4893. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4894. if (dt.Rows.Count > 0)
  4895. {
  4896. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4897. {
  4898. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4899. expInfo.state = "异常";
  4900. expInfo.isMultiDelivery = 1;
  4901. expInfo.Update();
  4902. continue;
  4903. }
  4904. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4905. {
  4906. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4907. expInfo.state = "异常";
  4908. expInfo.Update();
  4909. continue;
  4910. }
  4911. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4912. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4913. bool isInitOrderDeliv = false;
  4914. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4915. {
  4916. isInitOrderDeliv = true;
  4917. expInfo.isMultiDelivery = 1;
  4918. }
  4919. if (ctid.IndexOf("N") != -1)
  4920. {
  4921. StringBuilder sqlbucha = new StringBuilder();
  4922. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4923. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4924. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4925. commonHelper.UpdateRelationOrder(ctid);
  4926. expInfo.delivery_memo = "发货成功";
  4927. expInfo.state = "发货成功";
  4928. expInfo.isMultiDelivery = 1;
  4929. expInfo.Update();
  4930. }
  4931. else
  4932. {
  4933. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4934. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4935. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4936. {
  4937. expInfo.delivery_memo = "发货成功";
  4938. expInfo.state = "发货成功";
  4939. expInfo.isMultiDelivery = 1;
  4940. expInfo.Update();
  4941. commonHelper.UpdateRelationOrder(ctid);
  4942. CeErpSukuraData.createInfo(ctid, 4);
  4943. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4944. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4945. }
  4946. else
  4947. {
  4948. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4949. expInfo.state = "异常";
  4950. expInfo.Update();
  4951. }
  4952. }
  4953. }
  4954. }
  4955. }
  4956. returnSuccessMsg("操作完成");
  4957. }
  4958. public void reset_erp_memoopt()
  4959. {
  4960. if (UrlPostParmsCheck("ctid"))
  4961. {
  4962. string eid = GetPostString("ctid");
  4963. CeErpTradeCell entity = null;
  4964. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4965. if (entity != null)
  4966. {
  4967. string stropt = "";
  4968. if (entity.MemoOpt == 1)
  4969. {
  4970. stropt = "“改稿”";
  4971. }
  4972. else if (entity.MemoOpt == 2)
  4973. {
  4974. stropt = "“定稿”";
  4975. }
  4976. else if (entity.MemoOpt == 3)
  4977. {
  4978. stropt = "“完成查货”";
  4979. CeErpSukuraData.createInfo(entity.ctid, 6);
  4980. }
  4981. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4982. entity.UpdateTime = DateTime.Now;
  4983. entity.MemoOpt = 0;
  4984. entity.Update();
  4985. returnSuccessMsg("操作成功!");
  4986. return;
  4987. }
  4988. returnErrorMsg("找不到记录");
  4989. }
  4990. }
  4991. public void get_erp_deliveryunusual()
  4992. {
  4993. DataStruct dStruct = GetPostStruct();
  4994. List<string> lw = new List<string>();
  4995. string tid = GetPostString("ctid");
  4996. if (tid.Length > 0)
  4997. {
  4998. string select_tid = getTidByCtid(tid);
  4999. lw.Add(string.Format("tid='{0}'", select_tid));
  5000. }
  5001. string shopname = GetPostString("shopname");
  5002. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5003. string buyernick = GetPostString("buyer_nick");
  5004. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5005. string customer = GetPostString("customer");
  5006. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5007. string design = GetPostString("design");
  5008. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5009. string sellermemo = GetPostString("seller_memo");
  5010. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5011. string supplier = GetPostString("supplier");
  5012. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5013. string date1 = GetPostString("date1");
  5014. string date2 = GetPostString("date2");
  5015. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5016. if (dw.Length > 0) lw.Add(dw);
  5017. string placedate1 = GetPostString("placedate1");
  5018. string placedate2 = GetPostString("placedate2");
  5019. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5020. if (dw_place.Length > 0) lw.Add(dw_place);
  5021. string price1 = GetPostString("price1");
  5022. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5023. string price2 = GetPostString("price2");
  5024. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5025. string unusualCon = GetPostString("unusualcon");
  5026. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  5027. string posTag = CurrentUser.UserPost.Post.Code;
  5028. if (posTag == "Supplier")
  5029. {
  5030. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5031. }
  5032. lw.Add(string.Format("OrderState = 6"));
  5033. lw.Add(string.Format("UnusualTag = 5"));
  5034. lw.Add(string.Format("IsRefund<={0}", 1));
  5035. dStruct.Order = "FinishPlaceTime desc";
  5036. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5037. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5038. writeGridDataTableJson(dStruct.TotalCount, dt);
  5039. }
  5040. public void get_erp_deliveryedlist()
  5041. {
  5042. DataStruct dStruct = GetPostStruct();
  5043. List<string> lw = new List<string>();
  5044. string tid = GetPostString("ctid");
  5045. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5046. string shopname = GetPostString("shopname");
  5047. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5048. string buyernick = GetPostString("buyer_nick");
  5049. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5050. string customer = GetPostString("customer");
  5051. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5052. string design = GetPostString("design");
  5053. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5054. string sellermemo = GetPostString("seller_memo");
  5055. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5056. string logistics = GetPostString("logistics");
  5057. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5058. string date1 = GetPostString("date1");
  5059. string date2 = GetPostString("date2");
  5060. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5061. //if (dw.Length > 0) lw.Add(dw);
  5062. string placedate1 = GetPostString("placedate1");
  5063. string placedate2 = GetPostString("placedate2");
  5064. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5065. if (fdw.Length > 0) lw.Add(fdw);
  5066. string devdate1 = GetPostString("deliverydate1");
  5067. string devdate2 = GetPostString("deliverydate2");
  5068. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5069. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5070. string price1 = GetPostString("price1");
  5071. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5072. string price2 = GetPostString("price2");
  5073. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5074. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5075. {
  5076. if (tid.Length > 0)
  5077. {
  5078. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5079. if (tid.Length > 5)
  5080. {
  5081. List<string> tids = getTidByCtidLike(tid);
  5082. if (tids.Count > 0 && tids.Count < 10)
  5083. {
  5084. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5085. }
  5086. }
  5087. lw.Add(tid_sql);
  5088. }
  5089. if (buyernick.Length > 0)
  5090. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5091. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5092. if (dw.Length > 0) lw.Add(dw);
  5093. }
  5094. else
  5095. {
  5096. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  5097. }
  5098. string posTag = CurrentUser.UserPost.Post.Code;
  5099. if (posTag == "Supplier")
  5100. {
  5101. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5102. }
  5103. else
  5104. {
  5105. string supplier = GetPostString("supplier");
  5106. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5107. }
  5108. lw.Add(string.Format(" OrderState IN (7, 8)"));
  5109. lw.Add(string.Format("type != 'PDD' "));
  5110. lw.Add(string.Format("IsRefund!={0}", 2));
  5111. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5112. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5113. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5114. /*if (tid.Length > 0)
  5115. {
  5116. List<string> tids = new List<string>();
  5117. if (dt != null && dt.Rows.Count > 0)
  5118. {
  5119. foreach (DataRow item in dt.Rows)
  5120. {
  5121. tids.Add("'" + item["tid"] + "'");
  5122. }
  5123. }
  5124. if (tids.Count > 0)
  5125. {
  5126. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5127. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5128. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5129. dt = WebCache.GetData("view_erptradecell", dStruct);
  5130. }
  5131. }*/
  5132. if (dt != null)
  5133. {
  5134. foreach (DataRow dr in dt.Rows)
  5135. {
  5136. 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();
  5137. }
  5138. }
  5139. writeGridDataTableJson(dStruct.TotalCount, dt);
  5140. }
  5141. public void get_erp_pdddeliveryed()
  5142. {
  5143. DataStruct dStruct = GetPostStruct();
  5144. List<string> lw = new List<string>();
  5145. string tid = GetPostString("ctid");
  5146. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5147. string shopname = GetPostString("shopname");
  5148. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5149. string buyernick = GetPostString("buyer_nick");
  5150. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5151. string customer = GetPostString("customer");
  5152. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5153. string design = GetPostString("design");
  5154. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5155. string sellermemo = GetPostString("seller_memo");
  5156. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5157. string logistics = GetPostString("logistics");
  5158. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5159. string date1 = GetPostString("date1");
  5160. string date2 = GetPostString("date2");
  5161. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5162. //if (dw.Length > 0) lw.Add(dw);
  5163. string placedate1 = GetPostString("placedate1");
  5164. string placedate2 = GetPostString("placedate2");
  5165. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5166. if (fdw.Length > 0) lw.Add(fdw);
  5167. string devdate1 = GetPostString("deliverydate1");
  5168. string devdate2 = GetPostString("deliverydate2");
  5169. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5170. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5171. string price1 = GetPostString("price1");
  5172. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5173. string price2 = GetPostString("price2");
  5174. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5175. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5176. {
  5177. if (tid.Length > 0)
  5178. {
  5179. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5180. if (tid.Length > 5)
  5181. {
  5182. List<string> tids = getTidByCtidLike(tid);
  5183. if (tids.Count > 0 && tids.Count < 10)
  5184. {
  5185. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5186. }
  5187. }
  5188. lw.Add(tid_sql);
  5189. }
  5190. if (buyernick.Length > 0)
  5191. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5192. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5193. if (dw.Length > 0) lw.Add(dw);
  5194. }
  5195. else
  5196. {
  5197. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5198. }
  5199. string posTag = CurrentUser.UserPost.Post.Code;
  5200. if (posTag == "Supplier")
  5201. {
  5202. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5203. }
  5204. else
  5205. {
  5206. string supplier = GetPostString("supplier");
  5207. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5208. }
  5209. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5210. lw.Add(string.Format("type = 'PDD' "));
  5211. lw.Add(string.Format("IsRefund!={0}", 2));
  5212. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5213. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5214. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5215. /* if (tid.Length > 0)
  5216. {
  5217. List<string> tids = new List<string>();
  5218. if (dt != null && dt.Rows.Count > 0)
  5219. {
  5220. foreach (DataRow item in dt.Rows)
  5221. {
  5222. tids.Add("'" + item["tid"] + "'");
  5223. }
  5224. }
  5225. if (tids.Count > 0)
  5226. {
  5227. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5228. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5229. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5230. dt = WebCache.GetData("view_erptradecell", dStruct);
  5231. }
  5232. }*/
  5233. foreach (DataRow dr in dt.Rows)
  5234. {
  5235. 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();
  5236. }
  5237. writeGridDataTableJson(dStruct.TotalCount, dt);
  5238. }
  5239. public void get_erp_jddeliveryed()
  5240. {
  5241. DataStruct dStruct = GetPostStruct();
  5242. List<string> lw = new List<string>();
  5243. string tid = GetPostString("ctid");
  5244. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5245. string shopname = GetPostString("shopname");
  5246. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5247. string buyernick = GetPostString("buyer_nick");
  5248. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5249. string customer = GetPostString("customer");
  5250. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5251. string design = GetPostString("design");
  5252. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5253. string sellermemo = GetPostString("seller_memo");
  5254. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5255. string date1 = GetPostString("date1");
  5256. string date2 = GetPostString("date2");
  5257. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5258. //if (dw.Length > 0) lw.Add(dw);
  5259. string placedate1 = GetPostString("placedate1");
  5260. string placedate2 = GetPostString("placedate2");
  5261. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5262. if (fdw.Length > 0) lw.Add(fdw);
  5263. string devdate1 = GetPostString("deliverydate1");
  5264. string devdate2 = GetPostString("deliverydate2");
  5265. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5266. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5267. string price1 = GetPostString("price1");
  5268. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5269. string price2 = GetPostString("price2");
  5270. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5271. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5272. {
  5273. if (tid.Length > 0)
  5274. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5275. if (buyernick.Length > 0)
  5276. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5277. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5278. if (dw.Length > 0) lw.Add(dw);
  5279. }
  5280. else
  5281. {
  5282. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5283. }
  5284. string posTag = CurrentUser.UserPost.Post.Code;
  5285. if (posTag == "Supplier")
  5286. {
  5287. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5288. }
  5289. else
  5290. {
  5291. string supplier = GetPostString("supplier");
  5292. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5293. }
  5294. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5295. lw.Add(string.Format("type = 'JD' "));
  5296. lw.Add(string.Format("IsRefund!={0}", 2));
  5297. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5298. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5299. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5300. foreach (DataRow dr in dt.Rows)
  5301. {
  5302. 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();
  5303. }
  5304. writeGridDataTableJson(dStruct.TotalCount, dt);
  5305. }
  5306. public void get_erp_allplacelist()
  5307. {
  5308. DataStruct dStruct = GetPostStruct();
  5309. List<string> lw = new List<string>();
  5310. string tid = GetPostString("ctid");
  5311. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5312. string shopname = GetPostString("shopname");
  5313. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5314. string buyernick = GetPostString("buyer_nick");
  5315. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5316. string customer = GetPostString("customer");
  5317. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5318. string design = GetPostString("design");
  5319. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5320. string sellermemo = GetPostString("seller_memo");
  5321. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5322. string supplier = GetPostString("supplier");
  5323. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5324. string date1 = GetPostString("date1");
  5325. string date2 = GetPostString("date2");
  5326. string pldate1 = GetPostString("placedate1");
  5327. string pldate2 = GetPostString("placedate2");
  5328. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5329. //if (dw.Length > 0) lw.Add(dw);
  5330. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5331. {
  5332. if (tid.Length > 0)
  5333. {
  5334. string select_tid = getTidByCtid(tid);
  5335. lw.Add(string.Format("tid='{0}'", select_tid));
  5336. }
  5337. if (buyernick.Length > 0)
  5338. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5339. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5340. if (dw.Length > 0) lw.Add(dw);
  5341. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5342. if (dw_place.Length > 0) lw.Add(dw_place);
  5343. }
  5344. else
  5345. {
  5346. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5347. {
  5348. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5349. }
  5350. }
  5351. string price1 = GetPostString("price1");
  5352. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5353. string price2 = GetPostString("price2");
  5354. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5355. string posTag = CurrentUser.UserPost.Post.Code;
  5356. if (posTag == "Supplier")
  5357. {
  5358. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5359. }
  5360. lw.Add(string.Format("OrderState >= 6"));
  5361. lw.Add(string.Format("IsSample != 2 "));
  5362. //lw.Add(string.Format("isDianziOrder = 0 "));
  5363. lw.Add(string.Format("SupplierId > 0 "));
  5364. //lw.Add(string.Format("IsRefund<={0}", 1));
  5365. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5366. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5367. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5368. foreach (DataRow dr in dt.Rows)
  5369. {
  5370. 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();
  5371. }
  5372. writeGridDataTableJson(dStruct.TotalCount, dt);
  5373. }
  5374. public void get_erp_financeallplacelist()
  5375. {
  5376. DataStruct dStruct = GetPostStruct();
  5377. List<string> lw = new List<string>();
  5378. string tid = GetPostString("ctid");
  5379. string shopname = GetPostString("shopname");
  5380. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5381. string buyernick = GetPostString("buyer_nick");
  5382. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5383. string customer = GetPostString("customer");
  5384. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5385. string design = GetPostString("design");
  5386. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5387. string sellermemo = GetPostString("seller_memo");
  5388. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5389. string supplier = GetPostString("supplier");
  5390. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5391. string date1 = GetPostString("date1");
  5392. string date2 = GetPostString("date2");
  5393. string pldate1 = GetPostString("placedate1");
  5394. string pldate2 = GetPostString("placedate2");
  5395. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5396. {
  5397. if (tid.Length > 0)
  5398. {
  5399. string select_tid = getTidByCtid(tid);
  5400. lw.Add(string.Format("tid='{0}'", select_tid));
  5401. }
  5402. if (buyernick.Length > 0)
  5403. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5404. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5405. if (dw.Length > 0) lw.Add(dw);
  5406. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5407. if (dw_place.Length > 0) lw.Add(dw_place);
  5408. }
  5409. else
  5410. {
  5411. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5412. {
  5413. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5414. }
  5415. }
  5416. string price1 = GetPostString("price1");
  5417. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5418. string price2 = GetPostString("price2");
  5419. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5420. string posTag = CurrentUser.UserPost.Post.Code;
  5421. if (posTag == "Supplier")
  5422. {
  5423. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5424. }
  5425. //lw.Add(string.Format("OrderState >= 6"));
  5426. lw.Add(string.Format("IsSample != 2 "));
  5427. lw.Add(string.Format("isDianziOrder = 0 "));
  5428. //lw.Add(string.Format("IsRefund<={0}", 1));
  5429. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5430. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5431. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5432. foreach (DataRow dr in dt.Rows)
  5433. {
  5434. 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();
  5435. }
  5436. writeGridDataTableJson(dStruct.TotalCount, dt);
  5437. }
  5438. public void get_erp_expresslist()
  5439. {
  5440. int listtype = GetInt("ltype");
  5441. DataStruct dStruct = GetPostStruct();
  5442. List<string> lw = new List<string>();
  5443. string tid = GetPostString("tid");
  5444. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5445. string outsid = GetPostString("out_sid");
  5446. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5447. string importer = GetPostString("ImportUserName");
  5448. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5449. string file = GetPostString("import_file");
  5450. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5451. string printman = GetPostString("printman");
  5452. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5453. string date1 = GetPostString("date1");
  5454. string date2 = GetPostString("date2");
  5455. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5456. if (dw.Length > 0) lw.Add(dw);
  5457. string fdate1 = GetPostString("finishdate1");
  5458. string fdate2 = GetPostString("finishdate2");
  5459. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5460. if (fdw.Length > 0) lw.Add(fdw);
  5461. string supplierId = GetPostString("supplierId");
  5462. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5463. if (listtype == 1)
  5464. {
  5465. lw.Add(string.Format("importUserId !=0"));
  5466. }
  5467. string posTag = CurrentUser.UserPost.Post.Code;
  5468. if (posTag == "Supplier")
  5469. {
  5470. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5471. }
  5472. if (dStruct.PageSize != 100000)
  5473. {
  5474. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5475. }
  5476. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5477. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5478. writeGridDataTableJson(dStruct.TotalCount, dt);
  5479. }
  5480. public void set_erp_buchaorderdelivery()
  5481. {
  5482. if (UrlPostParmsCheck("ctid"))
  5483. {
  5484. string eid = GetPostString("ctid");
  5485. CeErpTradeCell entity = null;
  5486. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5487. if (entity != null)
  5488. {
  5489. if (entity.IsSample != 2)
  5490. {
  5491. returnErrorMsg("补差价单才能标记为已发货");
  5492. return;
  5493. }
  5494. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5495. entity.OrderState = 7;
  5496. entity.Update();
  5497. returnSuccessMsg("操作成功!");
  5498. return;
  5499. }
  5500. returnErrorMsg("找不到记录");
  5501. }
  5502. }
  5503. public void get_stdtemplates()
  5504. {
  5505. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5506. //string res = taobaoHelper.test();
  5507. string res = apiHelper.API_PrintTemplate();
  5508. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5509. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5510. {
  5511. int sidx = res.IndexOf("error_code");
  5512. int eidx = res.IndexOf("success");
  5513. string msg = res.Substring(sidx, eidx - sidx);
  5514. returnErrorMsg(msg);
  5515. return;
  5516. }
  5517. if (res.Length <= 0)
  5518. {
  5519. returnErrorMsg("模板数据为空!");
  5520. return;
  5521. }
  5522. ReturnSuccess(res);
  5523. }
  5524. public void cancel_print_order()
  5525. {
  5526. if (UrlPostParmsCheck("ctid"))
  5527. {
  5528. string ctid = GetPostString("ctid");
  5529. CeErpTradeCell entity = null;
  5530. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5531. if (entity != null)
  5532. {
  5533. string res = "";
  5534. string code = entity.LastBillWaybillCode;
  5535. if (code == "")
  5536. {
  5537. code = entity.OutSid;
  5538. }
  5539. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5540. XLog.SaveLog(0, "取消面单" + res);
  5541. }
  5542. }
  5543. }
  5544. public void set_erp_printwaybill()
  5545. {
  5546. if (UrlPostParmsCheck("ctid"))
  5547. {
  5548. string ctid = GetPostString("ctid");
  5549. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5550. string cpName = GetPostString("cpname");
  5551. string isTogether = GetPostString("together");
  5552. string printType = GetPostString("printType");
  5553. //var res_obj = new
  5554. //{
  5555. // restype = 1,
  5556. // 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\"}"
  5557. //};
  5558. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5559. //ReturnSuccess(ro_json);
  5560. //return;
  5561. bool isUseLastWayBillCode = false;
  5562. CeErpTradeCell entity = null;
  5563. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5564. if (entity != null)
  5565. {
  5566. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5567. {
  5568. isUseLastWayBillCode = true;
  5569. }
  5570. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5571. {
  5572. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5573. return;
  5574. }
  5575. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5576. {
  5577. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5578. return;
  5579. }
  5580. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5581. {
  5582. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5583. return;
  5584. }
  5585. }
  5586. string res = "";
  5587. Api_waybill_code_response_Obj fullObj = null;
  5588. string pData_str = "";
  5589. string curUseWayBillCode = "";
  5590. if (isUseLastWayBillCode == false)
  5591. {
  5592. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5593. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5594. if (res.IndexOf("failure") != -1)
  5595. {
  5596. //int idx = res.IndexOf("sub_message");
  5597. //int idx2 = res.IndexOf("flag");
  5598. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5599. string errMsgNeed = commonHelper.KeepChinese(res);
  5600. var res_objd = new
  5601. {
  5602. restype = 0,
  5603. data = "获取面单失败" + errMsgNeed
  5604. };
  5605. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5606. returnSuccess(ro_jsond);
  5607. if (res.IndexOf("停发") != -1)
  5608. {
  5609. entity.UnusualCon = "物流停发";
  5610. entity.Update();
  5611. }
  5612. //returnErrorMsg("获取面单失败,"+emsg);
  5613. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5614. return;
  5615. }
  5616. else if (res.IndexOf("errorMsg") != -1)
  5617. {
  5618. //int idx = res.IndexOf("errorMsg");
  5619. //int idx2 = res.IndexOf("}]}");
  5620. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5621. string errMsgNeed = commonHelper.KeepChinese(res);
  5622. var res_objf = new
  5623. {
  5624. restype = 0,
  5625. data = "获取面单失败2" + errMsgNeed
  5626. };
  5627. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5628. if (res.IndexOf("停发") != -1)
  5629. {
  5630. entity.UnusualCon = "物流停发";
  5631. entity.Update();
  5632. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5633. if (trade != null)
  5634. {
  5635. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5636. }
  5637. }
  5638. returnSuccess(ro_jsonf);
  5639. //returnErrorMsg("获取面单失败," + emsg);
  5640. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5641. return;
  5642. }
  5643. try
  5644. {
  5645. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5646. //res = res.Replace(" ", "");
  5647. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5648. }
  5649. catch (Exception ex)
  5650. {
  5651. XLog.SaveLog(0, "生成fullObj" + res);
  5652. var res_objf = new
  5653. {
  5654. restype = 0,
  5655. data = "生成fullObj发生错误" + ex.Message
  5656. };
  5657. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5658. returnSuccess(ro_jsonf);
  5659. return;
  5660. }
  5661. if (fullObj.response.data.content.Count > 0)
  5662. {
  5663. ContentItem codeObj = fullObj.response.data.content[0];
  5664. if (cpCode.IndexOf("SFFQ-") != -1)
  5665. {
  5666. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5667. }
  5668. else
  5669. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5670. curUseWayBillCode = codeObj.waybillCode;
  5671. }
  5672. else
  5673. {
  5674. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5675. var res_objf = new
  5676. {
  5677. restype = 0,
  5678. data = "生成fullObj找不到快递单号waybillCode"
  5679. };
  5680. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5681. returnSuccess(ro_jsonf);
  5682. return;
  5683. }
  5684. }
  5685. else
  5686. {
  5687. //使用上次打印的快递单号
  5688. if (cpCode == "SFFQ-LY")
  5689. {
  5690. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5691. }
  5692. else
  5693. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5694. curUseWayBillCode = entity.LastBillWaybillCode;
  5695. }
  5696. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5697. {
  5698. var res_obje = new
  5699. {
  5700. restype = 0,
  5701. data = "获取加密打印数据失败"
  5702. };
  5703. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5704. returnSuccess(ro_jsone);
  5705. entity.LastBillCpCode = cpCode;
  5706. entity.LastBillWaybillCode = curUseWayBillCode;
  5707. entity.Update();
  5708. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5709. //returnErrorMsg("获取加密打印数据失败");
  5710. return;
  5711. }
  5712. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5713. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5714. string btnType = "";
  5715. string errorMsg = "";
  5716. if (entity != null)
  5717. {
  5718. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5719. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5720. //cpcode是 YTO-CAINIAO
  5721. //string comCode = cpCode.Split('-')[0].ToString();
  5722. string apires = "";
  5723. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5724. //isTogether=2是新的合包弹窗
  5725. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5726. {
  5727. if (ctid.IndexOf("N") != -1)
  5728. {
  5729. apires = "发货成功";
  5730. }
  5731. else
  5732. {
  5733. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5734. }
  5735. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5736. //打单后发货
  5737. StringBuilder sql = new StringBuilder();
  5738. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5739. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5740. {
  5741. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5742. }
  5743. else
  5744. {
  5745. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5746. }
  5747. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5748. foreach (DataRow row in dt.Rows)
  5749. {
  5750. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5751. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5752. {
  5753. try
  5754. {
  5755. btnType = "待发货";
  5756. entity.OutSid = curUseWayBillCode;
  5757. entity.OrderState = 7;
  5758. entity.IsUrgency = false;
  5759. entity.LastBillCpCode = "";
  5760. entity.LastBillWaybillCode = "";
  5761. entity.FinishDeliveryTime = DateTime.Now;
  5762. entity.IsReturn = 0;
  5763. entity.MemoOpt = 0;
  5764. entity.UpdateTime = DateTime.Now;
  5765. entity.Update();
  5766. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5767. //还要插入快递信息到 快递信息表
  5768. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5769. exinfo.tid = entity.ctid;
  5770. exinfo.out_sid = curUseWayBillCode;
  5771. exinfo.company_code = cpCode;
  5772. exinfo.company_name = cpName;
  5773. exinfo.supplierUserName = supplierName;
  5774. exinfo.deliveryType = "发货成功";
  5775. exinfo.print_time = DateTime.Now;
  5776. exinfo.printUser = CurrentUser.UserName;
  5777. exinfo.postData = pData_str;
  5778. exinfo.Create();
  5779. commonHelper.UpdateRelationOrder(entity.ctid);
  5780. CeErpSukuraData.createInfo(ctid, 4);
  5781. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5782. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  5783. {
  5784. commonHelper.sendCytExpress(exinfo);
  5785. }
  5786. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5787. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5788. }
  5789. catch (Exception ex)
  5790. {
  5791. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5792. }
  5793. }
  5794. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5795. {
  5796. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5797. if (entity.OrderState == 6)
  5798. {
  5799. entity.OrderState = 7;
  5800. }
  5801. entity.UpdateTime = DateTime.Now;
  5802. entity.FinishDeliveryTime = DateTime.Now;
  5803. btnType = "已发货";
  5804. entity.Update();
  5805. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5806. exinfo.tid = entity.ctid;
  5807. exinfo.out_sid = curUseWayBillCode;
  5808. exinfo.company_code = cpCode;
  5809. exinfo.company_name = cpName;
  5810. exinfo.supplierUserName = supplierName;
  5811. exinfo.deliveryType = "发货成功";
  5812. exinfo.print_time = DateTime.Now;
  5813. exinfo.printUser = CurrentUser.UserName;
  5814. exinfo.postData = pData_str;
  5815. exinfo.Create();
  5816. commonHelper.UpdateRelationOrder(entity.ctid);
  5817. CeErpSukuraData.createInfo(entity.ctid, 4);
  5818. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  5819. {
  5820. commonHelper.sendCytExpress(exinfo);
  5821. }
  5822. //不处理
  5823. }
  5824. else
  5825. {
  5826. entity.UpdateTime = DateTime.Now;
  5827. entity.LastBillCpCode = cpCode;
  5828. entity.LastBillWaybillCode = curUseWayBillCode;
  5829. entity.Update();
  5830. string errmsg = commonHelper.KeepChinese(apires);
  5831. var res_objz = new
  5832. {
  5833. restype = 0,
  5834. data = "打单后发货失败"
  5835. };
  5836. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5837. returnSuccess(ro_jsonz);
  5838. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5839. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5840. return;
  5841. }
  5842. }
  5843. }
  5844. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5845. {
  5846. string ctids = GetPostString("ctids");
  5847. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5848. List<string> list = new List<string>();
  5849. List<string> send_list = new List<string>();
  5850. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5851. CeErpTrade ceErpTrade = new CeErpTrade();
  5852. //可合包的合并一起发货
  5853. if (dt == null && string.IsNullOrEmpty(ctids))
  5854. {
  5855. var res_objz = new
  5856. {
  5857. restype = 0,
  5858. data = "打单后发货失败"
  5859. };
  5860. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5861. returnSuccess(ro_jsonz);
  5862. return;
  5863. }
  5864. if (!string.IsNullOrEmpty(ctids))
  5865. {
  5866. StringBuilder sql = new StringBuilder();
  5867. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5868. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5869. }
  5870. foreach (DataRow row in dt.Rows)
  5871. {
  5872. list.Add("'" + row["ctid"] + "'");
  5873. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5874. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5875. if (ctid.IndexOf("N") != -1)
  5876. {
  5877. apires = "发货成功";
  5878. }
  5879. else
  5880. {
  5881. if (!send_list.Contains(ceErpTrade.tid))
  5882. {
  5883. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5884. }
  5885. else
  5886. {
  5887. apires = "发货成功";
  5888. }
  5889. }
  5890. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5891. {
  5892. send_list.Add(ceErpTrade.tid);
  5893. try
  5894. {
  5895. btnType = "待发货";
  5896. ceErpTradeCell.OutSid = curUseWayBillCode;
  5897. ceErpTradeCell.OrderState = 7;
  5898. ceErpTradeCell.IsUrgency = false;
  5899. ceErpTradeCell.LastBillCpCode = "";
  5900. ceErpTradeCell.LastBillWaybillCode = "";
  5901. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5902. ceErpTradeCell.IsReturn = 0;
  5903. ceErpTradeCell.MemoOpt = 0;
  5904. ceErpTradeCell.UpdateTime = DateTime.Now;
  5905. ceErpTradeCell.Update();
  5906. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5907. //还要插入快递信息到 快递信息表
  5908. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5909. exinfo.tid = ceErpTradeCell.ctid;
  5910. exinfo.out_sid = curUseWayBillCode;
  5911. exinfo.company_code = cpCode;
  5912. exinfo.company_name = cpName;
  5913. exinfo.supplierUserName = supplierName;
  5914. exinfo.deliveryType = "发货成功";
  5915. exinfo.print_time = DateTime.Now;
  5916. exinfo.printUser = CurrentUser.UserName;
  5917. exinfo.postData = pData_str;
  5918. exinfo.Create();
  5919. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5920. CeErpSukuraData.createInfo(ctid, 4);
  5921. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5922. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80 || entity.SupplierId == 126)
  5923. {
  5924. commonHelper.sendCytExpress(exinfo);
  5925. }
  5926. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5927. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5928. }
  5929. catch (Exception ex)
  5930. {
  5931. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5932. }
  5933. }
  5934. else
  5935. {
  5936. ceErpTradeCell.UpdateTime = DateTime.Now;
  5937. ceErpTradeCell.LastBillCpCode = cpCode;
  5938. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5939. ceErpTradeCell.Update();
  5940. string errmsg = commonHelper.KeepChinese(apires);
  5941. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5942. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5943. }
  5944. }
  5945. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5946. }
  5947. }
  5948. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5949. var res_obj = new
  5950. {
  5951. restype = 1,
  5952. data = pData_str,
  5953. errorMsg
  5954. };
  5955. string ro_json = JsonConvert.SerializeObject(res_obj);
  5956. ReturnSuccess(ro_json);
  5957. return;
  5958. }
  5959. }
  5960. private string GetUTF8String(byte[] vs)
  5961. {
  5962. throw new NotImplementedException();
  5963. }
  5964. public void set_erp_printwaybill_cn()
  5965. {
  5966. if (UrlPostParmsCheck("ctid"))
  5967. {
  5968. string ctid = GetPostString("ctid");
  5969. string cpCode = GetPostString("cpcode");
  5970. string cpName = GetPostString("cpname");
  5971. string tempUrl = GetPostString("tempurl");
  5972. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5973. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5974. //string res = taobaoHelper.test();
  5975. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5976. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5977. {
  5978. int sidx = res.IndexOf("errorMsg");
  5979. int eidx = res.IndexOf("}");
  5980. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5981. var res_objzxx = new
  5982. {
  5983. restype = 0,
  5984. data = msg
  5985. };
  5986. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5987. returnSuccess(ro_jsonzxx);
  5988. //returnErrorMsg(msg);
  5989. return;
  5990. }
  5991. int idx = res.IndexOf("waybillCode");
  5992. int idx2 = res.IndexOf("printData");
  5993. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5994. string eid = GetPostString("ctid");
  5995. CeErpTradeCell entity = null;
  5996. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5997. if (entity != null)
  5998. {
  5999. string osid = entity.OutSid;
  6000. entity.OutSid = osid + "," + outsid;
  6001. entity.FinishDeliveryTime = DateTime.Now;
  6002. entity.OrderState = 7;
  6003. entity.UpdateTime = DateTime.Now;
  6004. entity.IsReturn = 0;
  6005. entity.Update();
  6006. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  6007. exinfo.tid = entity.ctid;
  6008. exinfo.out_sid = outsid;
  6009. exinfo.company_code = cpCode;
  6010. exinfo.company_name = cpName;
  6011. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  6012. exinfo.deliveryType = "发货成功";
  6013. exinfo.print_time = DateTime.Now;
  6014. exinfo.printUser = CurrentUser.UserName;
  6015. exinfo.Create();
  6016. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  6017. {
  6018. commonHelper.sendCytExpress(exinfo);
  6019. }
  6020. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  6021. }
  6022. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  6023. var res_objz = new
  6024. {
  6025. restype = 1,
  6026. data = res
  6027. };
  6028. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  6029. returnSuccess(ro_jsonz);
  6030. //ReturnSuccess(res);
  6031. }
  6032. }
  6033. ////打单,打印面单 获取面单号
  6034. //public void set_erp_printwaybill()
  6035. //{
  6036. // if (UrlPostParmsCheck("ctid"))
  6037. // {
  6038. // string ctid = GetPostString("ctid");
  6039. // string cpCode = GetPostString("cpcode");
  6040. // string tempUrl = GetPostString("tempurl");
  6041. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6042. // //string res = taobaoHelper.test();
  6043. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6044. // if (res.IndexOf("error_response") != -1)
  6045. // {
  6046. // int sidx = res.IndexOf("sub_msg");
  6047. // int eidx = res.IndexOf("request_id");
  6048. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  6049. // returnErrorMsg(msg);
  6050. // return;
  6051. // }
  6052. // int idx = res.IndexOf("waybill_code");
  6053. // int idx2 = res.IndexOf("}]}");
  6054. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  6055. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  6056. // ReturnSuccess(res);
  6057. // }
  6058. //}
  6059. public void cancel_erp_aftersale()
  6060. {
  6061. if (UrlPostParmsCheck("ctid"))
  6062. {
  6063. string eid = GetPostString("ctid");
  6064. CeErpTradeCell entity = null;
  6065. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6066. if (entity != null)
  6067. {
  6068. //有过处理的售后,取消也不能删除 售 字,保留
  6069. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  6070. {
  6071. entity.AfterSaleState = 4;
  6072. }
  6073. else
  6074. entity.AfterSaleState = 0;
  6075. entity.UpdateTime = DateTime.Now;
  6076. entity.Update();
  6077. returnSuccessMsg("操作成功!");
  6078. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  6079. return;
  6080. }
  6081. returnErrorMsg("找不到订单记录");
  6082. }
  6083. }
  6084. public void get_erp_aftersalelist()
  6085. {
  6086. DataStruct dStruct = GetPostStruct();
  6087. List<string> lw = new List<string>();
  6088. int st = GetInt("st");
  6089. string tid = GetPostString("ctid");
  6090. if (st == 3)
  6091. {
  6092. if (tid.Length > 0)
  6093. {
  6094. string select_tid = getTidByCtid(tid);
  6095. lw.Add(string.Format("tid='{0}'", select_tid));
  6096. }
  6097. }
  6098. else
  6099. {
  6100. if (tid.Length > 0)
  6101. {
  6102. string select_tid = getTidByCtid(tid);
  6103. lw.Add(string.Format("tid='{0}'", select_tid));
  6104. }
  6105. }
  6106. string shopname = GetPostString("shopname");
  6107. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6108. string buyernick = GetPostString("buyer_nick");
  6109. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  6110. string sellermemo = GetPostString("seller_memo");
  6111. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6112. string orderState = GetPostString("orderState");
  6113. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  6114. string afterState = GetPostString("afterstate");
  6115. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6116. string date1 = GetPostString("date1");
  6117. string date2 = GetPostString("date2");
  6118. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6119. if (dw.Length > 0) lw.Add(dw);
  6120. string price1 = GetPostString("price1");
  6121. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6122. string price2 = GetPostString("price2");
  6123. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6124. //lw.Add(string.Format("IsRefund!={0}", 1));
  6125. string reason = GetPostString("reason");
  6126. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6127. string method = GetPostString("method");
  6128. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6129. string handler = GetPostString("handler");
  6130. if (handler.Length > 0)
  6131. {
  6132. lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6133. }
  6134. string handledate1 = GetPostString("handledate1");
  6135. string handledate2 = GetPostString("handledate2");
  6136. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6137. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6138. string finish1 = GetPostString("finishdate1");
  6139. string finish2 = GetPostString("finishdate2");
  6140. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6141. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6142. string afterdate1 = GetPostString("afterdate1");
  6143. string afterdate2 = GetPostString("afterdate2");
  6144. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6145. if (afterDate.Length > 0) lw.Add(afterDate);
  6146. string supplier = GetPostString("supplier");
  6147. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6148. string responsible = GetPostString("responsibleman");
  6149. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6150. string customer = GetPostString("customer");
  6151. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6152. string design = GetPostString("design");
  6153. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6154. string afterMemoType = GetPostString("aftermemotype");
  6155. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6156. string posCode = CurrentUser.UserPost.Post.Code;
  6157. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6158. //{
  6159. // string vstate = GetPostString("vstate");
  6160. // if (vstate.Length > 0)
  6161. // {
  6162. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6163. // }
  6164. // if (posCode == "Supplier")
  6165. // {
  6166. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6167. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6168. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6169. // }
  6170. // else
  6171. // {
  6172. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6173. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6174. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6175. // {
  6176. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6177. // }
  6178. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6179. // {
  6180. // int orgid = CurrentUser.UserPost.OrgID;
  6181. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6182. // }
  6183. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6184. // {
  6185. // string shopid = CurrentUser.User.pemShop;
  6186. // lw.Add(string.Format("shopId in ({0})", shopid));
  6187. // }
  6188. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6189. // //{
  6190. // // int org_id = CurrentUser.UserPost.OrgID;
  6191. // // lw.Add(string.Format("OrgID={0}", org_id));
  6192. // //}
  6193. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6194. // }
  6195. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6196. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6197. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6198. //}
  6199. if (st == 5)
  6200. {
  6201. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6202. {
  6203. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6204. {
  6205. string shopid = CurrentUser.User.pemShop;
  6206. lw.Add(string.Format("shopId in ({0})", shopid));
  6207. }
  6208. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6209. {
  6210. int mrOrgid = CurrentUser.UserPost.OrgID;
  6211. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6212. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6213. }
  6214. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6215. //{
  6216. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6217. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6218. //}
  6219. else
  6220. {
  6221. string userIdStr = "";
  6222. if (posCode == "CustomerService")
  6223. {
  6224. userIdStr = CurrentUser.UserID + "_k";
  6225. }
  6226. else if (posCode == "Designer" || posCode == "wxDesigner")
  6227. {
  6228. userIdStr = CurrentUser.UserID + "_s";
  6229. }
  6230. else if (posCode == "Place")
  6231. {
  6232. userIdStr = CurrentUser.UserID + "_x";
  6233. }
  6234. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6235. }
  6236. }
  6237. string placedate1 = GetPostString("placedate1");
  6238. string placedate2 = GetPostString("placedate2");
  6239. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6240. if (dwplace.Length > 0) lw.Add(dwplace);
  6241. string supState = GetPostString("supState");
  6242. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6243. string searchType = GetPostString("searchType");
  6244. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6245. {
  6246. lw.Add(string.Format("BackNum>1"));
  6247. }
  6248. lw.Add(string.Format("AfterSaleState>0"));
  6249. if (ex_psize > 0)
  6250. {
  6251. if (CurrentUser.UserPost.Post.Code == "Finance")
  6252. dStruct.Order = "pay_time desc";
  6253. else
  6254. dStruct.Order = "HandleTime desc";
  6255. }
  6256. else
  6257. dStruct.Order = "HandleTime desc";
  6258. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6259. DataTable dt = WebCache.GetData("view_test", dStruct);
  6260. writeGridDataTableJson(dStruct.TotalCount, dt);
  6261. }
  6262. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6263. //{
  6264. // lw.Add(string.Format("AfterSaleState=4"));
  6265. // string code = CurrentUser.UserPost.Post.Code;
  6266. // if (code == "CustomerService")
  6267. // {
  6268. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6269. // }
  6270. // else if (code == "Designer" || code == "DesignerMr")
  6271. // {
  6272. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6273. // }
  6274. // else if (code == "Place" || code == "PlaceMr")
  6275. // {
  6276. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6277. // }
  6278. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6279. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6280. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6281. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6282. //}
  6283. //else //处理中的售后,待处理和处理中合并
  6284. //{
  6285. // if (afterState.Length <= 0)
  6286. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6287. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6288. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6289. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6290. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6291. //}
  6292. }
  6293. public void get_erp_disagreeftersalelist()
  6294. {
  6295. DataStruct dStruct = GetPostStruct();
  6296. List<string> lw = new List<string>();
  6297. int st = 2;
  6298. string tid = GetPostString("ctid");
  6299. if (tid.Length > 0)
  6300. {
  6301. string select_tid = getTidByCtid(tid);
  6302. lw.Add(string.Format("tid='{0}'", select_tid));
  6303. }
  6304. string shopname = GetPostString("shopname");
  6305. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6306. string buyernick = GetPostString("buyer_nick");
  6307. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6308. string sellermemo = GetPostString("seller_memo");
  6309. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6310. string orderState = GetPostString("orderState");
  6311. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6312. string afterState = GetPostString("afterstate");
  6313. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6314. string date1 = GetPostString("date1");
  6315. string date2 = GetPostString("date2");
  6316. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6317. if (dw.Length > 0) lw.Add(dw);
  6318. string price1 = GetPostString("price1");
  6319. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6320. string price2 = GetPostString("price2");
  6321. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6322. //lw.Add(string.Format("IsRefund!={0}", 1));
  6323. string reason = GetPostString("reason");
  6324. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6325. string method = GetPostString("method");
  6326. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6327. string handler = GetPostString("handler");
  6328. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6329. string handledate1 = GetPostString("handledate1");
  6330. string handledate2 = GetPostString("handledate2");
  6331. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6332. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6333. string afterdate1 = GetPostString("afterdate1");
  6334. string afterdate2 = GetPostString("afterdate2");
  6335. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6336. if (afterDate.Length > 0) lw.Add(afterDate);
  6337. string backdate1 = GetPostString("backdate1");
  6338. string backdate2 = GetPostString("backdate2");
  6339. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6340. if (backDate.Length > 0) lw.Add(backDate);
  6341. string supplier = GetPostString("supplier");
  6342. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6343. string responsible = GetPostString("responsibleman");
  6344. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6345. string customer = GetPostString("customer");
  6346. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6347. string design = GetPostString("design");
  6348. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6349. string afterSaleMemo = GetPostString("afterSaleMemo");
  6350. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6351. string afterMemoType = GetPostString("aftermemotype");
  6352. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6353. string aftersakereason = GetPostString("aftersakereason");
  6354. if (aftersakereason.Length > 0)
  6355. {
  6356. if (aftersakereason == "1")
  6357. {
  6358. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6359. }
  6360. if (aftersakereason == "2")
  6361. {
  6362. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6363. }
  6364. }
  6365. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6366. string poscode = CurrentUser.UserPost.Post.Code;
  6367. if (poscode != "SysAdmin")
  6368. {
  6369. string shopid = CurrentUser.User.pemShop;
  6370. lw.Add(string.Format("shopId in ({0})", shopid));
  6371. }
  6372. string searchType = GetPostString("searchType");
  6373. if (searchType == "wait")
  6374. {
  6375. lw.Add(string.Format("HandleTime is null"));
  6376. }
  6377. if (searchType == "handling")
  6378. {
  6379. lw.Add(string.Format("HandleTime is not null "));
  6380. }
  6381. if (searchType == "back" || searchType == "puBack")
  6382. {
  6383. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6384. }
  6385. if (searchType == "reBack")
  6386. {
  6387. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6388. }
  6389. if (searchType == "moreBack")
  6390. {
  6391. lw.Add(string.Format("backNum > 1"));
  6392. }
  6393. lw.Add(string.Format("(AfterSaleState=5)"));
  6394. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6395. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6396. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6397. writeGridDataTableJson(dStruct.TotalCount, dt);
  6398. }
  6399. public void get_erp_handlingaftersalelist()
  6400. {
  6401. DataStruct dStruct = GetPostStruct();
  6402. List<string> lw = new List<string>();
  6403. int st = 2;
  6404. string tid = GetPostString("ctid");
  6405. if (tid.Length > 0)
  6406. {
  6407. string select_tid = getTidByCtid(tid);
  6408. lw.Add(string.Format("tid='{0}'", select_tid));
  6409. }
  6410. string shopname = GetPostString("shopname");
  6411. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6412. string buyernick = GetPostString("buyer_nick");
  6413. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6414. string sellermemo = GetPostString("seller_memo");
  6415. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6416. string orderState = GetPostString("orderState");
  6417. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6418. string afterState = GetPostString("afterstate");
  6419. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6420. string date1 = GetPostString("date1");
  6421. string date2 = GetPostString("date2");
  6422. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6423. if (dw.Length > 0) lw.Add(dw);
  6424. string price1 = GetPostString("price1");
  6425. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6426. string price2 = GetPostString("price2");
  6427. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6428. //lw.Add(string.Format("IsRefund!={0}", 1));
  6429. string reason = GetPostString("reason");
  6430. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6431. string method = GetPostString("method");
  6432. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6433. string handler = GetPostString("handler");
  6434. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6435. string handledate1 = GetPostString("handledate1");
  6436. string handledate2 = GetPostString("handledate2");
  6437. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6438. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6439. string afterdate1 = GetPostString("afterdate1");
  6440. string afterdate2 = GetPostString("afterdate2");
  6441. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6442. if (afterDate.Length > 0) lw.Add(afterDate);
  6443. string supplier = GetPostString("supplier");
  6444. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6445. string responsible = GetPostString("responsibleman");
  6446. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6447. string customer = GetPostString("customer");
  6448. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6449. string design = GetPostString("design");
  6450. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6451. string afterSaleMemo = GetPostString("afterSaleMemo");
  6452. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6453. string afterMemoType = GetPostString("aftermemotype");
  6454. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6455. string afterresult = GetPostString("afterresult");
  6456. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6457. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6458. string poscode = CurrentUser.UserPost.Post.Code;
  6459. if (poscode != "SysAdmin")
  6460. {
  6461. string shopid = CurrentUser.User.pemShop;
  6462. lw.Add(string.Format("shopId in ({0})", shopid));
  6463. }
  6464. string searchType = GetPostString("searchType");
  6465. if (searchType == "wait")
  6466. {
  6467. lw.Add(string.Format("HandleTime is null"));
  6468. }
  6469. if (searchType == "documentary")
  6470. {
  6471. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6472. }
  6473. if (searchType == "handling")
  6474. {
  6475. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6476. }
  6477. if (searchType == "back" || searchType == "puBack")
  6478. {
  6479. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6480. }
  6481. if (searchType == "reBack")
  6482. {
  6483. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6484. }
  6485. if (afterState.Length <= 0)
  6486. {
  6487. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6488. }
  6489. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6490. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6491. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6492. writeGridDataTableJson(dStruct.TotalCount, dt);
  6493. }
  6494. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6495. //public void get_erp_back_handlingaftersalelist()
  6496. //{
  6497. // DataStruct dStruct = GetPostStruct();
  6498. // List<string> lw = new List<string>();
  6499. // string tid = GetPostString("ctid");
  6500. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6501. // string shopname = GetPostString("shopname");
  6502. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6503. // string buyernick = GetPostString("buyer_nick");
  6504. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6505. // string sellermemo = GetPostString("seller_memo");
  6506. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6507. // string orderState = GetPostString("orderState");
  6508. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6509. // string afterState = GetPostString("afterstate");
  6510. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6511. // string date1 = GetPostString("date1");
  6512. // string date2 = GetPostString("date2");
  6513. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6514. // if (dw.Length > 0) lw.Add(dw);
  6515. // string price1 = GetPostString("price1");
  6516. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6517. // string price2 = GetPostString("price2");
  6518. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6519. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6520. // string reason = GetPostString("reason");
  6521. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6522. // string method = GetPostString("method");
  6523. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6524. // string handler = GetPostString("handler");
  6525. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6526. // string handledate1 = GetPostString("handledate1");
  6527. // string handledate2 = GetPostString("handledate2");
  6528. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6529. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6530. // string afterdate1 = GetPostString("afterdate1");
  6531. // string afterdate2 = GetPostString("afterdate2");
  6532. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6533. // if (afterDate.Length > 0) lw.Add(afterDate);
  6534. // string supplier = GetPostString("supplier");
  6535. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6536. // string responsible = GetPostString("responsibleman");
  6537. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6538. // string customer = GetPostString("customer");
  6539. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6540. // string design = GetPostString("design");
  6541. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6542. // string afterMemoType = GetPostString("aftermemotype");
  6543. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6544. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6545. // if (afterState.Length <= 0)
  6546. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6547. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6548. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6549. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6550. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6551. //}
  6552. public void get_erp_aftersaleverifylist()
  6553. {
  6554. DataStruct dStruct = GetPostStruct();
  6555. List<string> lw = new List<string>();
  6556. string tid = GetPostString("ctid");
  6557. if (tid.Length > 0)
  6558. {
  6559. string select_tid = getTidByCtid(tid);
  6560. lw.Add(string.Format("otid='{0}'", select_tid));
  6561. }
  6562. string shopname = GetPostString("shopname");
  6563. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6564. string buyernick = GetPostString("buyer_nick");
  6565. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6566. string sellermemo = GetPostString("seller_memo");
  6567. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6568. string orderState = GetPostString("orderState");
  6569. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6570. //lw.Add(string.Format("IsRefund!={0}", 1));
  6571. string reason = GetPostString("reason");
  6572. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6573. string method = GetPostString("method");
  6574. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6575. string handler = GetPostString("handler");
  6576. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6577. string handledate1 = GetPostString("handledate1");
  6578. string handledate2 = GetPostString("handledate2");
  6579. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6580. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6581. string finish1 = GetPostString("finishdate1");
  6582. string finish2 = GetPostString("finishdate2");
  6583. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6584. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6585. string supplier = GetPostString("supplier");
  6586. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6587. string responsible = GetPostString("responsibleman");
  6588. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6589. string posCode = CurrentUser.UserPost.Post.Code;
  6590. string vstate = GetPostString("vstate");
  6591. if (vstate.Length > 0)
  6592. {
  6593. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6594. }
  6595. if (posCode == "Supplier")
  6596. {
  6597. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6598. lw.Add(string.Format("VerifyState = 0"));
  6599. lw.Add("type = 1");
  6600. lw.Add(string.Format("AfterSaleState={0}", 3));
  6601. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6602. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6603. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6604. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6605. writeGridDataTableJson(dStruct.TotalCount, dt);
  6606. }
  6607. else if (posCode == "logistics")
  6608. {
  6609. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6610. lw.Add(string.Format("VerifyState = 0"));
  6611. lw.Add("type = 2");
  6612. lw.Add(string.Format("AfterSaleState={0}", 3));
  6613. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6614. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6615. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6616. writeGridDataTableJson(dStruct.TotalCount, dt);
  6617. }
  6618. else
  6619. {
  6620. lw.Add(string.Format("(AfterSaleState = 3)"));
  6621. lw.Add("type = 0");
  6622. string reasonState = GetPostString("reasonState");
  6623. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "Summarize" || posCode == "Finance")
  6624. {
  6625. if (reasonState == "2")
  6626. {
  6627. lw.Add("VerifyState = 3");
  6628. }
  6629. else if (reasonState == "1")
  6630. {
  6631. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6632. }
  6633. else
  6634. {
  6635. lw.Add("VerifyState in (0,3)");
  6636. }
  6637. //不加条件,可以看全部
  6638. }
  6639. 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")
  6640. {
  6641. int orgid = CurrentUser.UserPost.OrgID;
  6642. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6643. if (string.IsNullOrEmpty(manageOrgId))
  6644. {
  6645. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6646. }
  6647. else
  6648. {
  6649. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6650. }
  6651. if (reasonState == "1")
  6652. {
  6653. lw.Add("VerifyState = 3");
  6654. }
  6655. else if (reasonState == "2")
  6656. {
  6657. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6658. }
  6659. else
  6660. {
  6661. }
  6662. }
  6663. else
  6664. {
  6665. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6666. }
  6667. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6668. //{
  6669. // int org_id = CurrentUser.UserPost.OrgID;
  6670. // lw.Add(string.Format("OrgID={0}", org_id));
  6671. //}
  6672. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6673. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6674. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6675. writeGridDataTableJson(dStruct.TotalCount, dt);
  6676. }
  6677. }
  6678. public void get_erp_finishaftersalelist()
  6679. {
  6680. DataStruct dStruct = GetPostStruct();
  6681. List<string> lw = new List<string>();
  6682. int st = 4;
  6683. string tid = GetPostString("ctid");
  6684. if (tid.Length > 0)
  6685. {
  6686. string select_tid = getTidByCtid(tid);
  6687. lw.Add(string.Format("otid='{0}'", select_tid));
  6688. }
  6689. string shopname = GetPostString("shopname");
  6690. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6691. //lw.Add(string.Format("IsRefund!={0}", 1));
  6692. string reason = GetPostString("reason");
  6693. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6694. string method = GetPostString("method");
  6695. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6696. string buyernick = GetPostString("buyer_nick");
  6697. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6698. string handler = GetPostString("handler");
  6699. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6700. string handledate1 = GetPostString("handledate1");
  6701. string handledate2 = GetPostString("handledate2");
  6702. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6703. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6704. string finish1 = GetPostString("finishdate1");
  6705. string finish2 = GetPostString("finishdate2");
  6706. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6707. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6708. string supplier = GetPostString("supplier");
  6709. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6710. string responsible = GetPostString("responsibleman");
  6711. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6712. string vstate = GetPostString("vstate");
  6713. if (vstate.Length > 0)
  6714. {
  6715. if ("3".Equals(vstate))
  6716. {
  6717. lw.Add(string.Format("IsTem=1"));
  6718. }
  6719. else
  6720. {
  6721. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6722. }
  6723. }
  6724. lw.Add(string.Format("AfterSaleState=4"));
  6725. string code = CurrentUser.UserPost.Post.Code;
  6726. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6727. {
  6728. //不加条件,可以看全部
  6729. }
  6730. else if (code == "Supplier")
  6731. {
  6732. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6733. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6734. lw.Add("type = 1");
  6735. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6736. }
  6737. else if (code == "logistics")
  6738. {
  6739. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6740. lw.Add("type = 2");
  6741. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6742. }
  6743. 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")
  6744. {
  6745. lw.Add("type = 0");
  6746. int orgid = CurrentUser.UserPost.OrgID;
  6747. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6748. if (string.IsNullOrEmpty(manageOrgIds))
  6749. {
  6750. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6751. }
  6752. else
  6753. {
  6754. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6755. }
  6756. }
  6757. else
  6758. {
  6759. lw.Add("type = 0");
  6760. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6761. }
  6762. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6763. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6764. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6765. writeGridDataTableJson(dStruct.TotalCount, dt);
  6766. }
  6767. public void handle_erp_aftersale()
  6768. {
  6769. if (UrlPostParmsCheck("ctid"))
  6770. {
  6771. string eid = GetPostString("ctid");
  6772. string responStr = GetPostString("AfterSaleResponsible");
  6773. if (responStr.Length <= 0)
  6774. {
  6775. returnErrorMsg("售后责任人不能为空");
  6776. return;
  6777. }
  6778. bool isDesign = false;
  6779. double designFree = 0.00;
  6780. int responsibleId = 0;
  6781. CeErpTradeCell entity = null;
  6782. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6783. if (entity != null)
  6784. {
  6785. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6786. string afterMethod = GetPostString("AfterSaleMethod");
  6787. if (isNeedNewOrder == 1)
  6788. {
  6789. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6790. bool ishav = true;
  6791. if (newentity == null)
  6792. {
  6793. newentity = entity.Clone() as CeErpTradeCell;
  6794. ishav = false;
  6795. newentity.ctid = "S_" + entity.ctid;
  6796. newentity.OrderState = 0;
  6797. //唯一标识
  6798. newentity.OrderSn = newentity.ctid;
  6799. string orderSn = dataHelper.getSaleOrderSn();
  6800. if (orderSn != "")
  6801. {
  6802. newentity.OrderSn = orderSn;
  6803. }
  6804. }
  6805. newentity.UpdateTime = DateTime.Now;
  6806. newentity.AfterSaleState = 0;
  6807. newentity.AfterSaleMethod = afterMethod;
  6808. if (!ishav)
  6809. {
  6810. string memo_str = newentity.seller_memo;
  6811. memo_str = memo_str.Replace("(", "(");
  6812. memo_str = memo_str.Replace(")", ")");
  6813. int sIndex = memo_str.IndexOf("(");
  6814. int eIndex = memo_str.IndexOf(")");
  6815. if (sIndex == -1 || eIndex == -1)
  6816. {
  6817. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6818. return;
  6819. }
  6820. string first = memo_str.Substring(0, sIndex + 1);
  6821. string memoCtid = newentity.OrderSn;
  6822. //if (memoCtid.IndexOf("C") != -1)
  6823. //{
  6824. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6825. //if (CIdx.IndexOf("+") != -1)
  6826. //{
  6827. //CIdx = "C" + CIdx.Split('+')[1];
  6828. //}
  6829. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6830. //}
  6831. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6832. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6833. string newMemo = first + memoCtid + last;
  6834. newentity.seller_memo = newMemo;
  6835. newentity.FinishPlaceTime = null;
  6836. newentity.UnusualTag = 0;
  6837. newentity.UnusualCon = "";
  6838. newentity.UnusualTime = null;
  6839. newentity.AfterSaleMemo = "";
  6840. newentity.AfterSaleMethod = afterMethod;
  6841. newentity.AfterSalePreTime = null;
  6842. newentity.AfterSaleReason = "";
  6843. newentity.AfterSaleResponsible = "";
  6844. newentity.AfterSaleState = 0;
  6845. newentity.AfterSaleTime = null;
  6846. newentity.AfterSaleUserId = 0;
  6847. newentity.AfterSaleSupplierState = 0;
  6848. newentity.LastBillWaybillCode = "";
  6849. newentity.LastBillCpCode = "";
  6850. newentity.FinishAfterSaleTime = null;
  6851. newentity.HandleTime = null;
  6852. newentity.IsSF = 0;
  6853. newentity.IsOldCustomer = 0;
  6854. newentity.UrgencyTime = null;
  6855. newentity.ResponsibleUserId = "";
  6856. newentity.IsVerifyToSupplier = false;
  6857. newentity.payment = 0;
  6858. newentity.CheckMemo = "";
  6859. newentity.OutSid = "";
  6860. newentity.CheckOrderTime = null;
  6861. newentity.MemoOpt = 0;
  6862. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6863. }
  6864. newentity.isAfterSaleOrder = 1;
  6865. newentity.IsRefund = 0;
  6866. string receiveMobile = GetPostString("receiver_mobile");
  6867. if (receiveMobile.Length > 0)
  6868. {
  6869. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6870. if (trade != null)
  6871. {
  6872. trade.receiver_name = GetPostString("receiver_name");
  6873. trade.receiver_mobile = receiveMobile;
  6874. trade.receiver_state = GetPostString("receiver_state");
  6875. trade.receiver_city = GetPostString("receiver_city");
  6876. trade.receiver_district = GetPostString("receiver_district");
  6877. trade.receiver_address = GetPostString("receiver_address");
  6878. newentity.IsOffLineOrder = 1;
  6879. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6880. }
  6881. }
  6882. string st = GetPostString("ToState");
  6883. if (st.Length > 0)
  6884. {
  6885. if (newentity.OrderState <= 3)
  6886. {
  6887. newentity.WaitDesignTime = DateTime.Now;
  6888. newentity.StartDesignTime = null;
  6889. newentity.FinishDesignTime = null;
  6890. newentity.OrderState = 3;
  6891. if (st == "下单员")
  6892. {
  6893. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6894. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6895. {
  6896. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6897. }
  6898. }
  6899. else
  6900. {
  6901. newentity.WaitDesignTime = DateTime.Now;
  6902. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6903. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6904. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6905. {
  6906. DataRow user = dt1.Rows[0];
  6907. //找主管
  6908. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6909. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6910. if (dt != null && dt.Rows.Count > 0)
  6911. {
  6912. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6913. newentity.DesignUserId = designMr;
  6914. string key = "aftersale_order_" + designMr;
  6915. if (RedisHelper.HasKey(key))
  6916. {
  6917. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6918. list.Add(newentity.ctid);
  6919. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6920. }
  6921. }
  6922. //账号正常
  6923. if (user["State"].ToString() == "0")
  6924. {
  6925. newentity.DesignUserId = entity.DesignUserId;
  6926. string key = "aftersale_order_" + entity.DesignUserId;
  6927. if (RedisHelper.HasKey(key))
  6928. {
  6929. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6930. list.Add(newentity.ctid);
  6931. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6932. }
  6933. }
  6934. }
  6935. }
  6936. }
  6937. if (entity.IsXianHuo == 1)
  6938. {
  6939. newentity.OrderState = 6;
  6940. entity.FinishPlaceTime = DateTime.Now;
  6941. }
  6942. }
  6943. if (ishav)
  6944. {
  6945. newentity.Update();
  6946. }
  6947. else
  6948. {
  6949. newentity.Create();
  6950. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6951. newCellExtend.ctid = newentity.ctid;
  6952. newCellExtend.orderFrom = 20;
  6953. newCellExtend.orderType = 30;
  6954. if (st == "下单员")
  6955. {
  6956. }
  6957. else
  6958. {
  6959. newCellExtend.ReprintTime = DateTime.Now;
  6960. }
  6961. newCellExtend.Create();
  6962. }
  6963. if (st != "下单员")
  6964. {
  6965. if (entity.DispatchSort == 2)
  6966. {
  6967. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6968. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6969. }
  6970. }
  6971. }
  6972. //处理售后扩展
  6973. string resIdStr = GetPostString("ResponsibleUserId");
  6974. string refundFees = GetPostString("refundFrees");
  6975. int IsComplain = GetPostInt("isComplain");
  6976. int IsBad = GetPostInt("isBad");
  6977. string IsOriginal = GetPostString("isOriginal");
  6978. double diffResultPrice = GetPostDouble("diffResultPrice");
  6979. string textResult = GetPostString("textResult");
  6980. string supplierResponsible = GetPostString("supplierResponsible");
  6981. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6982. if (ceErpTradeAfterSaleExtend == null)
  6983. {
  6984. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6985. ceErpTradeAfterSaleExtend.tid = eid;
  6986. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6987. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6988. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6989. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6990. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6991. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6992. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6993. ceErpTradeAfterSaleExtend.Create();
  6994. }
  6995. else
  6996. {
  6997. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6998. {
  6999. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  7000. }
  7001. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  7002. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  7003. ceErpTradeAfterSaleExtend.TextResult = textResult;
  7004. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  7005. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  7006. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  7007. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7008. ceErpTradeAfterSaleExtend.Update();
  7009. }
  7010. int gysid = GetPostInt("ResponsibleSupId");
  7011. if (entity.AfterSaleUserId == 0)
  7012. {
  7013. entity.AfterSaleUserId = CurrentUser.UserID;
  7014. }
  7015. entity.ResponsibleUserId = resIdStr;
  7016. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  7017. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  7018. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  7019. {
  7020. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7021. int backNum = 0;
  7022. if (number != null)
  7023. {
  7024. backNum = number.BackNum;
  7025. }
  7026. char[] separator = { ',' };
  7027. string[] sArray = resIdStr.Split(separator);
  7028. string[] refundFreeList = { };
  7029. if (refundFees.Length > 0)
  7030. {
  7031. refundFreeList = refundFees.Split(separator);
  7032. }
  7033. int index = -1;
  7034. List<int> responsibleIds = new List<int>();
  7035. foreach (string i in sArray)
  7036. {
  7037. index++;
  7038. if (i.Length <= 0) continue;
  7039. char[] separator2 = { '_' };
  7040. string idstr = i.Split(separator2)[0];
  7041. string idtype = i.Split(separator2)[1];
  7042. double refudFree = 0;
  7043. if (refundFreeList.Length > 0)
  7044. {
  7045. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  7046. }
  7047. if (idtype == "s")
  7048. {
  7049. isDesign = true;
  7050. designFree = refudFree;
  7051. }
  7052. int userId = Convert.ToInt32(idstr);
  7053. int type = 0;
  7054. if (idtype == "g")
  7055. {
  7056. type = 1;
  7057. }
  7058. if (idtype == "w")
  7059. {
  7060. type = 2;
  7061. }
  7062. if (idtype == "t")
  7063. {
  7064. type = 3;
  7065. }
  7066. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  7067. if (ceErpTradeResponsible == null)
  7068. {
  7069. ceErpTradeResponsible = new CeErpTradeResponsible();
  7070. ceErpTradeResponsible.tid = eid;
  7071. ceErpTradeResponsible.UserId = userId;
  7072. ceErpTradeResponsible.createdTime = DateTime.Now;
  7073. ceErpTradeResponsible.type = type;
  7074. if (type == 1)
  7075. {
  7076. ceErpTradeResponsible.IsSup = 1;
  7077. }
  7078. if (type == 2)
  7079. {
  7080. ceErpTradeResponsible.IsFlow = 1;
  7081. }
  7082. }
  7083. int state = 0;
  7084. //已认可的不需要再次认可
  7085. if (sArray.Length > 1 && ceErpTradeResponsible.VerifyState == 1)
  7086. {
  7087. state = 1;
  7088. }
  7089. ceErpTradeResponsible.RefundFee = refudFree;
  7090. ceErpTradeResponsible.VerifyState = state;
  7091. if (userId == 2125 || idtype == "w")
  7092. {
  7093. ceErpTradeResponsible.VerifyState = 1;
  7094. }
  7095. if (idtype == "w" && userId == 101)
  7096. {
  7097. ceErpTradeResponsible.VerifyState = state;
  7098. }
  7099. if (ceErpTradeResponsible.ID > 0)
  7100. {
  7101. ceErpTradeResponsible.Update();
  7102. }
  7103. else
  7104. {
  7105. ceErpTradeResponsible.Create();
  7106. }
  7107. if (isDesign)
  7108. {
  7109. responsibleId = ceErpTradeResponsible.ID;
  7110. }
  7111. responsibleIds.Add(ceErpTradeResponsible.ID);
  7112. }
  7113. CeErpTradeResponsible.ExecuteNonQuery(string.Format("update CE_ErpTradeResponsible set VerifyState =-1 where tid='" + eid + "' and ID NOT IN (" + string.Join(",", responsibleIds) + ")"));
  7114. CeErpTradeResponsible.NumByTid(backNum, eid);
  7115. }
  7116. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  7117. if (ceErpTradeCellExtend != null)
  7118. {
  7119. ceErpTradeCellExtend.returnVisit = 0;
  7120. ceErpTradeCellExtend.Update();
  7121. }
  7122. if (entity.HandleTime != null)
  7123. {
  7124. if (entity.AfterSaleState == 1)
  7125. {
  7126. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  7127. }
  7128. else
  7129. {
  7130. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  7131. }
  7132. }
  7133. else
  7134. {
  7135. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  7136. entity.HandleTime = DateTime.Now;
  7137. }
  7138. bool isCompale = false;
  7139. if (entity.AfterSaleState == 5)
  7140. {
  7141. isCompale = true;
  7142. entity.AfterSaleState = 3;
  7143. }
  7144. entity.AfterSaleSupplierState = 0;
  7145. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7146. {
  7147. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7148. }
  7149. string sImgs = GetPostString("img");
  7150. entity.AfterSaleSupplierImg = sImgs;
  7151. entity.supRefundType = GetPostString("supRefundType");
  7152. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7153. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7154. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7155. entity.AfterSaleMemoType = GetPostString("MemoType");
  7156. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7157. {
  7158. //entity.AfterSaleSupplierState = 2;
  7159. }
  7160. string df = GetPostString("DeductFee");
  7161. if (df == "")
  7162. {
  7163. df = "0";
  7164. }
  7165. string rf = GetPostString("RefundFee");
  7166. if (rf == "")
  7167. {
  7168. rf = "0";
  7169. }
  7170. string pm = GetPostString("AfterSalePayment");
  7171. if (pm == "")
  7172. {
  7173. pm = "0";
  7174. }
  7175. entity.AfterSalePayment = Convert.ToDouble(pm);
  7176. entity.DeductFee = Convert.ToDouble(df);
  7177. entity.RefundFee = Convert.ToDouble(rf);
  7178. entity.UpdateTime = DateTime.Now;
  7179. entity.Update();
  7180. string toState = GetPostString("ToState");
  7181. string original = GetPostString("isOriginal");
  7182. ApiVo apiVo = new ApiVo();
  7183. apiVo.orderNumber = entity.ctid;
  7184. apiVo.actionName = "afterDesign";
  7185. apiVo.orderRemarks = entity.AfterSaleMethod;
  7186. apiVo.reasonRemarks = entity.AfterSaleReason;
  7187. apiVo.isDesign = isDesign;
  7188. apiVo.designFree = designFree;
  7189. apiVo.responsibleId = responsibleId;
  7190. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7191. if (toState == "设计师")
  7192. {
  7193. apiVo.isOriginal = Convert.ToBoolean(original);
  7194. }
  7195. designHelper.API_WorkCore(apiVo);//afterDesign
  7196. CeErpMethod methodSql = new CeErpMethod();
  7197. methodSql.con = entity.AfterSaleMethod;
  7198. methodSql.addTime = DateTime.Now;
  7199. methodSql.Create();
  7200. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7201. CeErpMethod.ExecuteNonQuery(delsql);
  7202. if (isCompale)
  7203. {
  7204. aftersale_data_change(entity.ctid);
  7205. }
  7206. returnSuccessMsg("操作成功!");
  7207. return;
  7208. }
  7209. returnErrorMsg("找不到订单记录");
  7210. }
  7211. }
  7212. public void ins_erp_toresponsible()
  7213. {
  7214. if (UrlPostParmsCheck("ctid"))
  7215. {
  7216. string eid = GetPostString("ctid");
  7217. CeErpTradeCell entity = null;
  7218. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7219. if (entity != null)
  7220. {
  7221. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7222. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7223. {
  7224. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7225. return;
  7226. }
  7227. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7228. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7229. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7230. if (entity.AfterSalePreTime == null)
  7231. {
  7232. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7233. {
  7234. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7235. }
  7236. }
  7237. entity.AfterSalePreTime = DateTime.Now;
  7238. //预完成给售后主管审核客户问题直接完成
  7239. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7240. {
  7241. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7242. {
  7243. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7244. }
  7245. }
  7246. ceErpTradeAfterSaleExtend.DisagreeTime = null;
  7247. ceErpTradeAfterSaleExtend.Update();
  7248. entity.AfterSaleState = 2;
  7249. entity.UpdateTime = DateTime.Now;
  7250. entity.Update();
  7251. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7252. aftersale_data_change(entity.ctid);
  7253. returnSuccessMsg("操作成功!");
  7254. return;
  7255. }
  7256. returnErrorMsg("找不到订单记录");
  7257. }
  7258. }
  7259. public void cancel_erp_aftersaleanddelnew()
  7260. {
  7261. if (UrlPostParmsCheck("ctid"))
  7262. {
  7263. string eid = GetPostString("ctid");
  7264. CeErpTradeCell entity = null;
  7265. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7266. if (entity != null)
  7267. {
  7268. entity.AfterSaleState = 0;
  7269. entity.AfterSaleReason = "";
  7270. entity.AfterSaleMethod = "";
  7271. entity.AfterSaleMemo = "";
  7272. entity.AfterSaleResponsible = "";
  7273. entity.ResponsibleUserId = "";
  7274. entity.DeductFee = 0;
  7275. entity.RefundFee = 0;
  7276. entity.IsArbitrate = 0;
  7277. CeErpTradeResponsible.DelByTid(eid, -1);
  7278. entity.Update();
  7279. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7280. if (after != null)
  7281. {
  7282. if (after.OrderState < 5)
  7283. CeErpTradeCell.DelByCtid("S_" + eid);
  7284. }
  7285. returnSuccessMsg("操作成功!");
  7286. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7287. return;
  7288. }
  7289. returnErrorMsg("找不到订单记录");
  7290. }
  7291. }
  7292. public void get_erp_aftersale_pregather()
  7293. {
  7294. List<string> lw = new List<string>();
  7295. int st = GetInt("st");
  7296. string tid = GetPostString("ctid");
  7297. if (tid.Length > 0)
  7298. {
  7299. string select_tid = getTidByCtid(tid);
  7300. lw.Add(string.Format("tid='{0}'", select_tid));
  7301. }
  7302. string shopname = GetPostString("shopname");
  7303. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7304. string buyernick = GetPostString("buyer_nick");
  7305. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7306. string sellermemo = GetPostString("seller_memo");
  7307. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7308. string orderState = GetPostString("orderState");
  7309. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7310. string reason = GetPostString("reason");
  7311. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7312. string method = GetPostString("method");
  7313. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7314. string handler = GetPostString("handler");
  7315. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7316. string handledate1 = GetPostString("handledate1");
  7317. string handledate2 = GetPostString("handledate2");
  7318. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7319. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7320. string supplier = GetPostString("supplier");
  7321. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7322. string responsible = GetPostString("responsibleman");
  7323. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7324. string customer = GetPostString("customer");
  7325. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7326. string design = GetPostString("design");
  7327. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7328. string afterMemoType = GetPostString("aftermemotype");
  7329. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7330. string afterSaleMemo = GetPostString("afterSaleMemo");
  7331. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7332. string afterresult = GetPostString("afterresult");
  7333. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7334. string poscode = CurrentUser.UserPost.Post.Code;
  7335. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7336. {
  7337. string shopid = CurrentUser.User.pemShop;
  7338. lw.Add(string.Format("shopId in ({0})", shopid));
  7339. }
  7340. var mainwhere = string.Join(" and ", lw.ToArray());
  7341. string ro_json = "";
  7342. string type = GetPostString("gather_type");
  7343. int number = 0;
  7344. if (poscode == "AfterSale")
  7345. {
  7346. //处理中
  7347. if (type == "Handling")
  7348. {
  7349. 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) : ""));
  7350. DataTable dt = null;
  7351. try
  7352. {
  7353. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7354. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7355. }
  7356. catch (Exception e)
  7357. {
  7358. dt = new DataTable();
  7359. }
  7360. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7361. return;
  7362. }
  7363. if (type == "Wait")
  7364. {
  7365. //待处理
  7366. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7367. DataTable dt1 = null;
  7368. try
  7369. {
  7370. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7371. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7372. }
  7373. catch (Exception e)
  7374. {
  7375. dt1 = new DataTable();
  7376. }
  7377. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7378. return;
  7379. }
  7380. if (type == "back")
  7381. {
  7382. //打回
  7383. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7384. DataTable dt2 = null;
  7385. try
  7386. {
  7387. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7388. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7389. }
  7390. catch (Exception e)
  7391. {
  7392. dt2 = new DataTable();
  7393. }
  7394. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7395. return;
  7396. }
  7397. if (type == "preCompletion")
  7398. {
  7399. //预完成
  7400. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7401. DataTable dt3 = null;
  7402. try
  7403. {
  7404. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7405. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7406. }
  7407. catch (Exception e)
  7408. {
  7409. dt3 = new DataTable();
  7410. }
  7411. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7412. return;
  7413. }
  7414. if (type == "documentary")
  7415. {
  7416. //跟单中
  7417. 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) : ""));
  7418. DataTable dt4 = null;
  7419. try
  7420. {
  7421. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7422. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7423. }
  7424. catch (Exception e)
  7425. {
  7426. dt4 = new DataTable();
  7427. }
  7428. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7429. return;
  7430. }
  7431. if (type == "reBack")
  7432. {
  7433. //被打回
  7434. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7435. DataTable dt1 = null;
  7436. try
  7437. {
  7438. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7439. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7440. }
  7441. catch (Exception e)
  7442. {
  7443. dt1 = new DataTable();
  7444. }
  7445. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7446. return;
  7447. }
  7448. }
  7449. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7450. {
  7451. if (type == "puBack")
  7452. {
  7453. //退回
  7454. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7455. DataTable dt = null;
  7456. try
  7457. {
  7458. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7459. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7460. }
  7461. catch (Exception e)
  7462. {
  7463. dt = new DataTable();
  7464. }
  7465. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7466. return;
  7467. }
  7468. if (type == "reBack")
  7469. {
  7470. //打回
  7471. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7472. DataTable dt1 = null;
  7473. try
  7474. {
  7475. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7476. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7477. }
  7478. catch (Exception e)
  7479. {
  7480. dt1 = new DataTable();
  7481. }
  7482. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7483. return;
  7484. }
  7485. if (type == "examEd")
  7486. {
  7487. //已审核
  7488. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7489. DataTable dt2 = null;
  7490. try
  7491. {
  7492. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7493. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7494. }
  7495. catch (Exception e)
  7496. {
  7497. dt2 = new DataTable();
  7498. }
  7499. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7500. return;
  7501. }
  7502. if (type == "waitExam")
  7503. {
  7504. //待审核
  7505. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7506. DataTable dt3 = null;
  7507. try
  7508. {
  7509. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7510. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7511. }
  7512. catch (Exception e)
  7513. {
  7514. dt3 = new DataTable();
  7515. }
  7516. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7517. return;
  7518. }
  7519. if (type == "Handling")
  7520. {
  7521. //处理中
  7522. 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) : ""));
  7523. DataTable dt4 = null;
  7524. try
  7525. {
  7526. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7527. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7528. }
  7529. catch (Exception e)
  7530. {
  7531. dt4 = new DataTable();
  7532. }
  7533. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7534. return;
  7535. }
  7536. if (type == "Wait")
  7537. {
  7538. //待处理
  7539. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7540. DataTable dt5 = null;
  7541. try
  7542. {
  7543. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7544. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7545. }
  7546. catch (Exception e)
  7547. {
  7548. dt5 = new DataTable();
  7549. }
  7550. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7551. return;
  7552. }
  7553. if (type == "documentary")
  7554. {
  7555. //跟单中
  7556. 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) : ""));
  7557. DataTable dt6 = null;
  7558. try
  7559. {
  7560. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7561. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7562. }
  7563. catch (Exception e)
  7564. {
  7565. dt6 = new DataTable();
  7566. }
  7567. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7568. return;
  7569. }
  7570. }
  7571. returnSuccess(ro_json);
  7572. }
  7573. public void end_erp_aftersale()
  7574. {
  7575. if (UrlPostParmsCheck("ctid"))
  7576. {
  7577. string eid = GetPostString("ctid");
  7578. CeErpTradeCell entity = null;
  7579. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7580. if (entity != null)
  7581. {
  7582. string stype = GetPostString("stype");
  7583. string typeStr = stype;
  7584. entity.AfterSaleState = 4;
  7585. entity.FinishAfterSaleTime = DateTime.Now;
  7586. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7587. entity.Update();
  7588. ApiVo apiVo = new ApiVo();
  7589. apiVo.orderNumber = entity.ctid;
  7590. apiVo.actionName = "afterOver";
  7591. designHelper.API_WorkCore(apiVo); //afterOver
  7592. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7593. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7594. CeErpSukuraData.createInfo(entity.ctid, 8);
  7595. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7596. returnSuccessMsg("操作成功!");
  7597. return;
  7598. }
  7599. returnErrorMsg("找不到订单记录");
  7600. }
  7601. }
  7602. public void ins_erp_finishaftersale()
  7603. {
  7604. if (UrlPostParmsCheck("id"))
  7605. {
  7606. string eid = GetPostString("id");
  7607. CeErpTradeResponsible entity = null;
  7608. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7609. if (entity != null)
  7610. {
  7611. entity.VerifyState = 1;
  7612. entity.VerifyTime = DateTime.Now;
  7613. entity.Update();
  7614. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7615. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7616. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7617. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7618. if (dt.Rows.Count <= 0)
  7619. {
  7620. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7621. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7622. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7623. CeErpSukuraData.createInfo(entity.tid, 8);
  7624. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7625. {
  7626. CeErpDesignerBill.Del(entity.tid);
  7627. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7628. }
  7629. }
  7630. returnSuccessMsg("操作成功!");
  7631. return;
  7632. }
  7633. returnErrorMsg("找不到订单记录");
  7634. }
  7635. }
  7636. public void upd_erp_arbitrateaftersale()
  7637. {
  7638. if (UrlPostParmsCheck("id"))
  7639. {
  7640. string eid = GetPostString("id");
  7641. CeErpTradeResponsible entity = null;
  7642. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7643. if (entity != null)
  7644. {
  7645. entity.IsArbitrate = 1;
  7646. entity.ArbitradeMemo = GetPostString("reason");
  7647. entity.VerifyState = 2;
  7648. entity.Update();
  7649. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7650. if (tradecell != null)
  7651. {
  7652. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7653. tradecell.IsArbitrate = 1;
  7654. tradecell.Update();
  7655. }
  7656. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7657. returnSuccessMsg("操作成功!");
  7658. return;
  7659. }
  7660. returnErrorMsg("找不到订单记录");
  7661. }
  7662. }
  7663. public void upd_erp_backaftersale()
  7664. {
  7665. if (UrlPostParmsCheck("tid"))
  7666. {
  7667. string eid = GetPostString("tid");
  7668. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7669. int backNum = 0;
  7670. if (number != null)
  7671. {
  7672. backNum = number.BackNum;
  7673. }
  7674. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7675. CeErpTradeCell entity = null;
  7676. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7677. if (entity != null)
  7678. {
  7679. entity.AfterSaleBackReason = GetPostString("backreason");
  7680. entity.AfterSaleState = 1;
  7681. entity.AfterSaleSupplierState = 0;
  7682. entity.UpdateTime = DateTime.Now;
  7683. entity.Update();
  7684. returnSuccessMsg("操作成功!");
  7685. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7686. return;
  7687. }
  7688. returnErrorMsg("找不到订单记录");
  7689. }
  7690. }
  7691. public void get_erp_supplieraftersalelist()
  7692. {
  7693. DataStruct dStruct = GetPostStruct();
  7694. List<string> lw = new List<string>();
  7695. string tid = GetPostString("ctid");
  7696. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7697. string shopname = GetPostString("shopname");
  7698. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7699. string buyernick = GetPostString("buyer_nick");
  7700. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7701. string sellermemo = GetPostString("seller_memo");
  7702. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7703. string orderState = GetPostString("orderState");
  7704. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7705. string afterState = GetPostString("afterstate");
  7706. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7707. string date1 = GetPostString("date1");
  7708. string date2 = GetPostString("date2");
  7709. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7710. if (dw.Length > 0) lw.Add(dw);
  7711. string price1 = GetPostString("price1");
  7712. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7713. string price2 = GetPostString("price2");
  7714. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7715. string reason = GetPostString("reason");
  7716. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7717. string method = GetPostString("method");
  7718. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7719. string handledate1 = GetPostString("handledate1");
  7720. string handledate2 = GetPostString("handledate2");
  7721. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7722. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7723. string handler = GetPostString("handler");
  7724. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7725. string afterdate1 = GetPostString("afterdate1");
  7726. string afterdate2 = GetPostString("afterdate2");
  7727. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7728. if (afterDate.Length > 0) lw.Add(afterDate);
  7729. string customer = GetPostString("customer");
  7730. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7731. string design = GetPostString("design");
  7732. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7733. string afterMemoType = GetPostString("aftermemotype");
  7734. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7735. string vstate = GetPostString("vstate");
  7736. if (vstate.Length > 0)
  7737. {
  7738. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7739. }
  7740. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7741. string supplier = GetPostString("supplier");
  7742. int supid = commonHelper.getSupplierIDByName(supplier);
  7743. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7744. string posCode = CurrentUser.UserPost.Post.Code;
  7745. if (posCode == "Supplier")
  7746. {
  7747. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7748. }
  7749. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7750. {
  7751. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7752. }
  7753. else
  7754. {
  7755. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7756. }
  7757. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7758. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7759. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7760. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7761. writeGridDataTableJson(dStruct.TotalCount, dt);
  7762. }
  7763. public void upd_erp_supverifyaftersale()
  7764. {
  7765. if (UrlPostParmsCheck("id"))
  7766. {
  7767. string id = GetPostString("id");
  7768. int st = GetPostInt("afterstate");
  7769. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7770. CeErpTradeCell entity = null;
  7771. if (ceErpTradeResponsible != null)
  7772. {
  7773. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7774. }
  7775. string afmemo = GetPostString("supmemo");
  7776. string image = GetPostString("image");
  7777. if (entity != null)
  7778. {
  7779. entity.AfterSaleSupplierState = st;
  7780. entity.AfterSaleSupplierMemo = afmemo;
  7781. if (st == 1)
  7782. {
  7783. ceErpTradeResponsible.VerifyState = 1;
  7784. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7785. ceErpTradeResponsible.Update();
  7786. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7787. if (isAll)
  7788. {
  7789. entity.AfterSaleState = 4;
  7790. entity.FinishAfterSaleTime = DateTime.Now;
  7791. }
  7792. }
  7793. else
  7794. {
  7795. CeErpTradeResponsible.dateByTid(entity.ctid);
  7796. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7797. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7798. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7799. if (num <= 1)
  7800. {
  7801. entity.AfterSaleState = 1;
  7802. }
  7803. else
  7804. {
  7805. entity.AfterSaleState = 5;
  7806. }
  7807. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7808. if (ceErpTradeAfterSaleExtend != null)
  7809. {
  7810. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7811. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7812. ceErpTradeAfterSaleExtend.Update();
  7813. }
  7814. else
  7815. {
  7816. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7817. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7818. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7819. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7820. ceErpTradeAfterSaleExtend.Create();
  7821. }
  7822. }
  7823. if (entity.AfterSaleState == 4)
  7824. {
  7825. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7826. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7827. {
  7828. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7829. }
  7830. ApiVo apiVo = new ApiVo();
  7831. apiVo.orderNumber = entity.ctid;
  7832. apiVo.actionName = "afterOver";
  7833. designHelper.API_WorkCore(apiVo); //afterOver
  7834. }
  7835. entity.UpdateTime = DateTime.Now;
  7836. entity.Update();
  7837. returnSuccessMsg("操作成功!");
  7838. CeErpSukuraData.createInfo(entity.ctid, 8);
  7839. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7840. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7841. return;
  7842. }
  7843. returnErrorMsg("找不到订单记录");
  7844. }
  7845. }
  7846. public void upd_erp_masteraftersale()
  7847. {
  7848. if (UrlPostParmsCheck("id"))
  7849. {
  7850. string id = GetPostString("id");
  7851. int st = GetPostInt("afterstate");
  7852. string afmemo = GetPostString("supmemo");
  7853. string image = GetPostString("image");
  7854. string textResult = GetPostString("textResult");
  7855. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7856. if (ceErpTradeResponsible != null)
  7857. {
  7858. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7859. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7860. ceErpTradeResponsible.Update();
  7861. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7862. if (entity != null)
  7863. {
  7864. entity.AfterSaleSupplierState = st;
  7865. entity.AfterSaleSupplierMemo = afmemo;
  7866. if (st == 1)
  7867. {
  7868. }
  7869. else
  7870. {
  7871. CeErpTradeResponsible.dateByTid(entity.ctid);
  7872. //退回到售后
  7873. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7874. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7875. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7876. if (num <= 1)
  7877. {
  7878. entity.AfterSaleState = 1;
  7879. }
  7880. else
  7881. {
  7882. entity.AfterSaleState = 5;
  7883. }
  7884. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7885. if (ceErpTradeAfterSaleExtend != null)
  7886. {
  7887. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7888. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7889. ceErpTradeAfterSaleExtend.Update();
  7890. }
  7891. else
  7892. {
  7893. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7894. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7895. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7896. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7897. ceErpTradeAfterSaleExtend.Create();
  7898. }
  7899. }
  7900. entity.UpdateTime = DateTime.Now;
  7901. entity.Update();
  7902. returnSuccessMsg("操作成功!");
  7903. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7904. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7905. return;
  7906. }
  7907. }
  7908. returnErrorMsg("找不到订单记录");
  7909. }
  7910. }
  7911. public void upd_erp_personaftersale()
  7912. {
  7913. if (UrlPostParmsCheck("id"))
  7914. {
  7915. //林小连
  7916. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7917. {
  7918. upd_erp_masteraftersale();
  7919. return;
  7920. }
  7921. string id = GetPostString("id");
  7922. int st = GetPostInt("afterstate");
  7923. string afmemo = GetPostString("supmemo");
  7924. string image = GetPostString("image");
  7925. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7926. if (ceErpTradeResponsible != null)
  7927. {
  7928. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7929. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7930. ceErpTradeResponsible.Update();
  7931. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7932. if (entity != null)
  7933. {
  7934. entity.AfterSaleSupplierMemo = afmemo;
  7935. entity.AfterSaleSupplierState = st;
  7936. if (st == 1)
  7937. {
  7938. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7939. if (isAll)
  7940. {
  7941. entity.AfterSaleState = 4;
  7942. entity.FinishAfterSaleTime = DateTime.Now;
  7943. }
  7944. }
  7945. else
  7946. {
  7947. CeErpTradeResponsible.dateByTid(entity.ctid);
  7948. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7949. if (ceErpTradeAfterSaleExtend != null)
  7950. {
  7951. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7952. ceErpTradeAfterSaleExtend.Update();
  7953. }
  7954. else
  7955. {
  7956. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7957. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7958. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7959. ceErpTradeAfterSaleExtend.Create();
  7960. }
  7961. //退回到主管
  7962. //entity.AfterSaleState = 2;
  7963. }
  7964. if (entity.AfterSaleState == 4)
  7965. {
  7966. ApiVo apiVo = new ApiVo();
  7967. apiVo.orderNumber = entity.ctid;
  7968. apiVo.actionName = "afterOver";
  7969. designHelper.API_WorkCore(apiVo); //afterOver
  7970. }
  7971. entity.UpdateTime = DateTime.Now;
  7972. entity.Update();
  7973. returnSuccessMsg("操作成功!");
  7974. CeErpSukuraData.createInfo(entity.ctid, 8);
  7975. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7976. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7977. return;
  7978. }
  7979. }
  7980. returnErrorMsg("找不到订单记录");
  7981. }
  7982. }
  7983. public void set_erp_supplierrefundtag()
  7984. {
  7985. if (UrlPostParmsCheck("ctid"))
  7986. {
  7987. string eid = GetPostString("ctid");
  7988. CeErpTradeCell entity = null;
  7989. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7990. if (entity != null)
  7991. {
  7992. entity.IsSupplierRefund = GetPostInt("tag");
  7993. entity.Update();
  7994. returnSuccessMsg("操作成功!");
  7995. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7996. return;
  7997. }
  7998. returnErrorMsg("找不到订单记录");
  7999. }
  8000. }
  8001. public void get_erp_refundlist()
  8002. {
  8003. DataStruct dStruct = GetPostStruct();
  8004. List<string> lw = new List<string>();
  8005. string tid = GetPostString("tid");
  8006. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8007. //string rid = GetPostString("refund_id");
  8008. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  8009. string shopname = GetPostString("shopname");
  8010. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8011. string buyernick = GetPostString("buyer_nick");
  8012. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8013. string customer = GetPostString("customer");
  8014. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8015. string design = GetPostString("design");
  8016. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8017. string sellermemo = GetPostString("seller_memo");
  8018. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8019. //string date1 = GetPostString("date1");
  8020. //string date2 = GetPostString("date2");
  8021. //string dateType = GetPostString("dateType");
  8022. //if (dateType.Length > 0)
  8023. //{
  8024. // if (dateType == "1001") dateType = "0";
  8025. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  8026. // if (searchDT.Count == 2)
  8027. // {
  8028. // date1 = searchDT[0].ToString();
  8029. // date2 = searchDT[1].ToString();
  8030. // }
  8031. //}
  8032. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8033. //if (dw.Length > 0) lw.Add(dw);
  8034. string redate1 = GetPostString("refunddate1");
  8035. string redate2 = GetPostString("refunddate2");
  8036. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8037. if (dwdate.Length > 0) lw.Add(dwdate);
  8038. string price1 = GetPostString("price1");
  8039. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8040. string price2 = GetPostString("price2");
  8041. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8042. string ispartrefund = GetPostString("ispartrefund");
  8043. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8044. string refundState = GetPostString("refundvstate");
  8045. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  8046. int st = GetInt("st");
  8047. if (st == 2) //待确认列表中,把state=3已确认的也显示
  8048. {
  8049. string responsible = GetPostString("responsibleman");
  8050. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8051. lw.Add(string.Format("RefundState>={0}", st));
  8052. string code = CurrentUser.UserPost.Post.Code;
  8053. if (code == "CustomerService")
  8054. {
  8055. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  8056. }
  8057. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  8058. {
  8059. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  8060. }
  8061. else if (code == "Place" || code == "PlaceMr")
  8062. {
  8063. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  8064. }
  8065. dStruct.Order = "RefundState asc,created desc";
  8066. }
  8067. else if (st == 10)
  8068. {
  8069. string responsible = GetPostString("responsibleman");
  8070. if (responsible == "空白")
  8071. {
  8072. lw.Add(string.Format("ResponsibleUserName = ''"));
  8073. }
  8074. else if (responsible.Length > 0)
  8075. {
  8076. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8077. }
  8078. lw.Add(string.Format("RefundState>=0"));
  8079. dStruct.Order = "created desc";
  8080. }
  8081. else
  8082. {
  8083. string responsible = GetPostString("responsibleman");
  8084. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8085. lw.Add(string.Format("RefundState={0}", st));
  8086. dStruct.Order = "created desc";
  8087. }
  8088. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8089. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  8090. dt.Columns.Add("refund_fees");
  8091. foreach (DataRow dr in dt.Rows)
  8092. {
  8093. String status = dr["status"].ToString();
  8094. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8095. {
  8096. dr["refund_fees"] = dr["refund_fee"];
  8097. }
  8098. else
  8099. {
  8100. dr["refund_fees"] = "0.0";
  8101. }
  8102. }
  8103. writeGridDataTableJson(dStruct.TotalCount, dt);
  8104. }
  8105. public void get_erp_refunddesignlist()
  8106. {
  8107. DataStruct dStruct = GetPostStruct();
  8108. List<string> lw = new List<string>();
  8109. string tid = GetPostString("tid");
  8110. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8111. string shopname = GetPostString("shopname");
  8112. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8113. string buyernick = GetPostString("buyer_nick");
  8114. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8115. string customer = GetPostString("customer");
  8116. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8117. string design = GetPostString("design");
  8118. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8119. string sellermemo = GetPostString("seller_memo");
  8120. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8121. string redate1 = GetPostString("refunddate1");
  8122. string redate2 = GetPostString("refunddate2");
  8123. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8124. if (dwdate.Length > 0) lw.Add(dwdate);
  8125. string price1 = GetPostString("price1");
  8126. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8127. string price2 = GetPostString("price2");
  8128. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8129. string ispartrefund = GetPostString("ispartrefund");
  8130. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8131. string designerorg = GetPostString("designerorg");
  8132. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  8133. string refundState = GetPostString("refundState");
  8134. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  8135. int myOrgid = CurrentUser.UserPost.OrgID;
  8136. string myOrgCode = CurrentUser.UserPost.Post.Code;
  8137. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8138. {
  8139. if (CurrentUser.User.TeamIds.Length > 0)
  8140. {
  8141. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8142. }
  8143. else
  8144. {
  8145. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8146. }
  8147. }
  8148. else if ("SysAdmin".Equals(myOrgCode))
  8149. {
  8150. }
  8151. else
  8152. {
  8153. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8154. {
  8155. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8156. }
  8157. else
  8158. {
  8159. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8160. }
  8161. }
  8162. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8163. dStruct.Order = "created desc";
  8164. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8165. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8166. dt.Columns.Add("refund_fees");
  8167. foreach (DataRow dr in dt.Rows)
  8168. {
  8169. String status = dr["status"].ToString();
  8170. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8171. {
  8172. dr["refund_fees"] = dr["refund_fee"];
  8173. }
  8174. else
  8175. {
  8176. dr["refund_fees"] = "0.0";
  8177. }
  8178. }
  8179. writeGridDataTableJson(dStruct.TotalCount, dt);
  8180. }
  8181. public void handle_erp_refundtag()
  8182. {
  8183. if (UrlPostParmsCheck("refund_id"))
  8184. {
  8185. string eid = GetPostString("refund_id");
  8186. string respMan = GetPostString("ResponsibleName");
  8187. if (respMan.Length <= 0)
  8188. {
  8189. returnErrorMsg("责任人不能为空");
  8190. return;
  8191. }
  8192. CeErpTradeRefund entity = null;
  8193. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8194. if (entity != null)
  8195. {
  8196. entity.ResponsibleUserName = respMan;
  8197. string userid = GetPostString("ResponsibleUserId");
  8198. if (userid.Length > 0)
  8199. {
  8200. entity.ResponsibleUserId = userid;
  8201. }
  8202. entity.Memo = GetPostString("Memo");
  8203. if (respMan.IndexOf("客服") != -1 ||
  8204. respMan.IndexOf("设计师") != -1 ||
  8205. respMan.IndexOf("下单员") != -1)
  8206. {
  8207. entity.RefundState = 2;
  8208. }
  8209. else
  8210. {
  8211. entity.RefundState = 3;
  8212. }
  8213. entity.modified = DateTime.Now;
  8214. entity.Update();
  8215. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8216. returnSuccessMsg("操作成功!");
  8217. return;
  8218. }
  8219. returnErrorMsg("找不到订单记录");
  8220. }
  8221. }
  8222. public void handle_erp_designrefundtag()
  8223. {
  8224. if (UrlPostParmsCheck("refund_id"))
  8225. {
  8226. string eid = GetPostString("refund_id");
  8227. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8228. if (ceErpTradeCellExtend == null)
  8229. {
  8230. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8231. ceErpTradeCellExtend.ctid = eid;
  8232. }
  8233. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8234. if (ceErpTradeCellExtend.ID > 0)
  8235. {
  8236. ceErpTradeCellExtend.Update();
  8237. }
  8238. else
  8239. {
  8240. ceErpTradeCellExtend.Create();
  8241. }
  8242. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8243. returnSuccessMsg("操作成功!");
  8244. return;
  8245. }
  8246. returnErrorMsg("找不到订单记录");
  8247. }
  8248. public void upd_erp_refundverify()
  8249. {
  8250. if (UrlPostParmsCheck("refund_id"))
  8251. {
  8252. string eid = GetPostString("refund_id");
  8253. CeErpTradeRefund entity = null;
  8254. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8255. if (entity != null)
  8256. {
  8257. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8258. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8259. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8260. {
  8261. entity.RefundState = 2;
  8262. }
  8263. else
  8264. {
  8265. entity.RefundState = 3;
  8266. }
  8267. entity.Update();
  8268. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8269. returnSuccessMsg("操作成功!");
  8270. return;
  8271. }
  8272. returnErrorMsg("找不到订单记录");
  8273. }
  8274. }
  8275. public void upd_erp_refundapprove()
  8276. {
  8277. if (UrlPostParmsCheck("refund_id"))
  8278. {
  8279. string eid = GetPostString("refund_id");
  8280. CeErpTradeRefund entity = null;
  8281. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8282. if (entity != null)
  8283. {
  8284. int apr = GetPostInt("approve");
  8285. if (apr == 0)
  8286. {
  8287. entity.RefundState = 1;
  8288. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8289. }
  8290. else if (apr == 1)
  8291. {
  8292. entity.RefundState = 3;
  8293. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8294. }
  8295. entity.modified = DateTime.Now;
  8296. entity.Update();
  8297. returnSuccessMsg("操作成功!");
  8298. return;
  8299. }
  8300. returnErrorMsg("找不到订单记录");
  8301. }
  8302. }
  8303. public void get_erp_billlist()
  8304. {
  8305. DataStruct dStruct = GetPostStruct();
  8306. List<string> lw = new List<string>();
  8307. string title = GetPostString("title");
  8308. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8309. string tid = GetPostString("tid");
  8310. string tids = GetPostString("tids");
  8311. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8312. if (tids.Length > 0)
  8313. {
  8314. tids = "'" + tids + "'";
  8315. tids = tids.Replace(",", "','");
  8316. lw.Add(string.Format("tid in ({0})", tids));
  8317. }
  8318. string shopname = GetPostString("shopname");
  8319. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8320. string buyernick = GetPostString("buyer_nick");
  8321. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8322. string customer = GetPostString("customer");
  8323. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8324. string date1 = GetPostString("date1");
  8325. string date2 = GetPostString("date2");
  8326. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8327. if (dw.Length > 0) lw.Add(dw);
  8328. string price1 = GetPostString("price1");
  8329. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8330. string price2 = GetPostString("price2");
  8331. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8332. string returndate1 = GetPostString("returndate1");
  8333. string returndate2 = GetPostString("returndate2");
  8334. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8335. if (dw1.Length > 0) lw.Add(dw1);
  8336. string billtype = GetPostString("billtype");
  8337. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8338. string billstate = GetPostString("billstate");
  8339. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8340. string usershop = CurrentUser.User.pemShop;
  8341. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8342. dStruct.Order = "createTime desc";
  8343. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8344. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8345. //foreach (DataRow dr in dt.Rows)
  8346. //{
  8347. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8348. //}
  8349. writeGridDataTableJson(dStruct.TotalCount, dt);
  8350. }
  8351. public void modify_erp_billinfo()
  8352. {
  8353. if (UrlPostParmsCheck("ID"))
  8354. {
  8355. string eid = GetPostString("ID");
  8356. CeErpBill bill_entity = null;
  8357. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8358. if (bill_entity != null)
  8359. {
  8360. bill_entity.tid = GetPostString("tid");
  8361. bill_entity.title = GetPostString("title");
  8362. bill_entity.tax = GetPostString("tax");
  8363. bill_entity.bank = GetPostString("bank");
  8364. bill_entity.bankac = GetPostString("bankac");
  8365. bill_entity.address = GetPostString("address");
  8366. bill_entity.phone = GetPostString("phone");
  8367. bill_entity.price = GetPostString("price");
  8368. bill_entity.productId = GetPostInt("ProductName");
  8369. bill_entity.num = GetPostInt("num");
  8370. bill_entity.unit = GetPostString("unit");
  8371. bill_entity.type = GetPostString("type");
  8372. bill_entity.sendType = GetPostString("SendType");
  8373. bill_entity.email = GetPostString("email");
  8374. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8375. bill_entity.shopName = GetPostString("ShopName");
  8376. bill_entity.applymemo = GetPostString("applymemo");
  8377. bill_entity.modifyTime = DateTime.Now;
  8378. bill_entity.createTime = DateTime.Now;
  8379. bill_entity.state = 0;
  8380. bill_entity.Update();
  8381. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8382. returnSuccessMsg("发票修改成功!");
  8383. return;
  8384. }
  8385. returnErrorMsg("找不到对应记录");
  8386. }
  8387. }
  8388. public void set_erp_invoicing()
  8389. {
  8390. if (UrlPostParmsCheck("id"))
  8391. {
  8392. try
  8393. {
  8394. string eid = GetPostString("id");
  8395. CeErpBill bill_entity = null;
  8396. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8397. if (bill_entity != null)
  8398. {
  8399. int ComId = GetPostInt("ComId");
  8400. //string memo = GetPostString("Memo");
  8401. int allInfo = GetPostInt("allinfo");
  8402. string clert = CurrentUser.User.Name;
  8403. //string detailValue = GetPostString("detailvalue");
  8404. string billId = bill_entity.billOrderId;
  8405. string[] billIdList = billId.Split(',');
  8406. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8407. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8408. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8409. {
  8410. billCount += 1;
  8411. }
  8412. if (billId.Length <= 0 || billIdList.Length != billCount)
  8413. {
  8414. bill_entity.billOrderId = "";
  8415. string prebill = "ltb";
  8416. for (int idx = 1; idx <= billCount; idx++)
  8417. {
  8418. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8419. string billoid = prebill + idx + dtstr;
  8420. bill_entity.billOrderId += billoid;
  8421. if (idx < billCount)
  8422. {
  8423. bill_entity.billOrderId += ",";
  8424. }
  8425. }
  8426. }
  8427. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8428. if (bill_entity.state == 5)
  8429. {
  8430. string errMsg = bill_entity.failerror;
  8431. string[] errlist = errMsg.Split('|');
  8432. string[] errTags = new string[errlist.Length];
  8433. for (int itag = 0; itag < errlist.Length; itag++)
  8434. {
  8435. if (errlist[itag].Length <= 0) continue;
  8436. errTags[itag] = errlist[itag].Split('&')[0];
  8437. }
  8438. for (int iii = 0; iii < errTags.Length; iii++)
  8439. {
  8440. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8441. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8442. if (billOrderList.Length >= erroBillOrderTag)
  8443. {
  8444. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8445. if (needModifyBillId.Length <= 19)
  8446. {
  8447. needModifyBillId = needModifyBillId + "1";
  8448. }
  8449. else
  8450. {
  8451. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8452. last = last + 1;
  8453. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8454. }
  8455. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8456. }
  8457. }
  8458. }
  8459. bool isHaveBillSucces = false;
  8460. string totalRes = "";
  8461. bill_entity.failerror = "";
  8462. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8463. {
  8464. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8465. totalRes += res;
  8466. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8467. {
  8468. isHaveBillSucces = true;
  8469. bill_entity.comId = ComId;
  8470. bill_entity.state = 1;
  8471. bill_entity.executeTime = DateTime.Now;
  8472. bill_entity.executeUser = clert;
  8473. }
  8474. else
  8475. {
  8476. bill_entity.state = 5;
  8477. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8478. }
  8479. }
  8480. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8481. bill_entity.Update();
  8482. if (isHaveBillSucces)
  8483. {
  8484. StringBuilder sql = new StringBuilder();
  8485. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8486. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8487. }
  8488. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8489. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8490. {
  8491. returnErrorMsg("开票失败");
  8492. }
  8493. else
  8494. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8495. return;
  8496. }
  8497. returnErrorMsg("找不到对应记录");
  8498. }
  8499. catch (Exception ex)
  8500. {
  8501. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8502. returnErrorMsg("操作失败");
  8503. }
  8504. }
  8505. }
  8506. public void get_erp_invoicing_back()
  8507. {
  8508. if (UrlPostParmsCheck("id"))
  8509. {
  8510. try
  8511. {
  8512. string id = GetPostString("id");
  8513. CeErpBill entiy = CeErpBill.Get(id);
  8514. if (entiy != null)
  8515. {
  8516. if (entiy.state == 0)
  8517. {
  8518. returnErrorMsg("发票还未开具");
  8519. return;
  8520. }
  8521. string[] billOrderList = entiy.billOrderId.Split(',');
  8522. int iTag = 0;
  8523. entiy.fplsh = "";
  8524. entiy.fpdm = "";
  8525. entiy.fphm = "";
  8526. foreach (string billOrderId in billOrderList)
  8527. {
  8528. iTag++;
  8529. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8530. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8531. {
  8532. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8533. try
  8534. {
  8535. Invoicing_get_response_Obj iObj = null;
  8536. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8537. if (iObj != null)
  8538. {
  8539. entiy.state = 2;
  8540. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8541. entiy.fpdm += iObj.list[0].c_fpdm;
  8542. entiy.fphm += iObj.list[0].c_fphm;
  8543. if (iTag < billOrderList.Length)
  8544. {
  8545. entiy.fplsh += ",";
  8546. entiy.fpdm += ",";
  8547. entiy.fphm += ",";
  8548. }
  8549. entiy.Update();
  8550. }
  8551. StringBuilder sql = new StringBuilder();
  8552. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8553. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8554. returnSuccessMsg("开票成功");
  8555. }
  8556. catch (Exception ex)
  8557. {
  8558. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8559. }
  8560. return;
  8561. }
  8562. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8563. {
  8564. var res_obj = new
  8565. {
  8566. data = "开票中"
  8567. };
  8568. string ro_json = JsonConvert.SerializeObject(res_obj);
  8569. returnSuccess(ro_json);
  8570. return;
  8571. }
  8572. else
  8573. {
  8574. int eidx = res.IndexOf("c_resultmsg");
  8575. int lidx = res.IndexOf("c_status");
  8576. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8577. entiy.state = 5;
  8578. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8579. entiy.Update();
  8580. returnErrorMsg("开票失败");
  8581. return;
  8582. }
  8583. }
  8584. }
  8585. }
  8586. catch (Exception ex)
  8587. {
  8588. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8589. }
  8590. return;
  8591. }
  8592. }
  8593. public void get_erp_invoicing()
  8594. {
  8595. if (UrlPostParmsCheck("id"))
  8596. {
  8597. try
  8598. {
  8599. string id = GetPostString("id");
  8600. CeErpBill entiy = CeErpBill.Get(id);
  8601. if (entiy != null)
  8602. {
  8603. if (entiy.state == 0)
  8604. {
  8605. returnErrorMsg("发票还未开具");
  8606. return;
  8607. }
  8608. if (entiy.sendType == "纸质发票")
  8609. {
  8610. if (entiy.img.Length <= 0)
  8611. {
  8612. returnErrorMsg("查无纸质发票");
  8613. return;
  8614. }
  8615. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8616. returnSuccess(returnres);
  8617. return;
  8618. }
  8619. string[] billOrderList = entiy.billOrderId.Split(',');
  8620. int iTag = 0;
  8621. string fpUrl = "";
  8622. entiy.fplsh = "";
  8623. entiy.fpdm = "";
  8624. entiy.fphm = "";
  8625. foreach (string billOrderId in billOrderList)
  8626. {
  8627. iTag++;
  8628. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8629. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8630. {
  8631. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8632. Invoicing_get_response_Obj iObj = null;
  8633. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8634. if (iObj != null)
  8635. {
  8636. //entiy.state = 2;
  8637. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8638. entiy.fpdm += iObj.list[0].c_fpdm;
  8639. entiy.fphm += iObj.list[0].c_fphm;
  8640. if (iTag < billOrderList.Length)
  8641. {
  8642. entiy.fplsh += ",";
  8643. entiy.fpdm += ",";
  8644. entiy.fphm += ",";
  8645. }
  8646. entiy.Update();
  8647. fpUrl += iObj.list[0].c_url + ",";
  8648. }
  8649. //returnSuccess(res);
  8650. StringBuilder sql = new StringBuilder();
  8651. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8652. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8653. }
  8654. else
  8655. {
  8656. int eidx = res.IndexOf("c_resultmsg");
  8657. //int lidx = res.IndexOf("c_status");
  8658. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8659. //开票失败
  8660. entiy.state = 5;
  8661. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8662. entiy.Update();
  8663. returnErrorMsg("开票失败");
  8664. return;
  8665. }
  8666. }
  8667. var returnObj = new
  8668. {
  8669. data = fpUrl
  8670. };
  8671. string ro_json = JsonConvert.SerializeObject(returnObj);
  8672. returnSuccess(ro_json);
  8673. }
  8674. }
  8675. catch (Exception ex)
  8676. {
  8677. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8678. }
  8679. return;
  8680. }
  8681. }
  8682. public void save_erp_billimg()
  8683. {
  8684. if (UrlPostParmsCheck("id"))
  8685. {
  8686. string eid = GetPostString("id");
  8687. CeErpBill bill_entity = null;
  8688. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8689. if (bill_entity != null)
  8690. {
  8691. bill_entity.img = GetPostString("img");
  8692. bill_entity.executeTime = DateTime.Now;
  8693. bill_entity.state = 2;
  8694. bill_entity.Update();
  8695. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8696. returnSuccessMsg("保存成功");
  8697. }
  8698. return;
  8699. }
  8700. }
  8701. public void upd_erp_billreturnback()
  8702. {
  8703. if (UrlPostParmsCheck("id"))
  8704. {
  8705. int eid = GetPostInt("id");
  8706. CeErpBill bill_entity = null;
  8707. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8708. if (bill_entity != null)
  8709. {
  8710. bill_entity.state = 3;
  8711. bill_entity.returnReason = GetPostString("reason");
  8712. bill_entity.Update();
  8713. returnSuccessMsg("驳回成功!");
  8714. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8715. }
  8716. return;
  8717. }
  8718. }
  8719. public void cancel_erp_bill()
  8720. {
  8721. if (UrlPostParmsCheck("id"))
  8722. {
  8723. int eid = GetPostInt("id");
  8724. int detailValue = GetPostInt("detailvalue");
  8725. CeErpBill bill_entity = null;
  8726. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8727. string cres = "";
  8728. string gres = "";
  8729. if (bill_entity != null)
  8730. {
  8731. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8732. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8733. {
  8734. int iTag = 0;
  8735. bill_entity.fplsh = "";
  8736. bill_entity.fpdm = "";
  8737. bill_entity.fphm = "";
  8738. foreach (string billOrderId in billOrderList)
  8739. {
  8740. iTag++;
  8741. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8742. if (gres.IndexOf("success") != -1)
  8743. {
  8744. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8745. Invoicing_get_response_Obj iObj = null;
  8746. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8747. if (iObj != null)
  8748. {
  8749. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8750. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8751. bill_entity.fphm += iObj.list[0].c_fphm;
  8752. if (iTag < billOrderList.Length)
  8753. {
  8754. bill_entity.fplsh += ",";
  8755. bill_entity.fpdm += ",";
  8756. bill_entity.fphm += ",";
  8757. }
  8758. bill_entity.Update();
  8759. }
  8760. }
  8761. else
  8762. {
  8763. returnErrorMsg(gres);
  8764. return;
  8765. }
  8766. }
  8767. }
  8768. if (bill_entity.sendType == "纸质发票")
  8769. {
  8770. //作废
  8771. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8772. //if (DateTime.Now.Month == extime.Month)
  8773. //{
  8774. //cres = taobaoHelper.cancel_invoicing(eid);
  8775. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8776. //{
  8777. bill_entity.state = 4;//已作废
  8778. bill_entity.Update();
  8779. returnSuccessMsg("发票已作废");
  8780. return;
  8781. //}
  8782. //else
  8783. //{
  8784. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8785. // bill_entity.Update();
  8786. // returnErrorMsg(cres);
  8787. // return;
  8788. //}
  8789. //}
  8790. //else
  8791. //{
  8792. // returnErrorMsg("纸质发票只能作废本月的发票");
  8793. // return;
  8794. //}
  8795. }
  8796. //红冲
  8797. int redTag = 0;
  8798. string[] fpdmList = bill_entity.fpdm.Split(',');
  8799. string[] fphmList = bill_entity.fphm.Split(',');
  8800. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8801. {
  8802. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8803. return;
  8804. }
  8805. foreach (string billOrderId in billOrderList)
  8806. {
  8807. redTag++;
  8808. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8809. cres += onecres;
  8810. cres += ",";
  8811. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8812. {
  8813. bill_entity.state = 4;//已作废
  8814. //bill_entity.Update();
  8815. //returnSuccessMsg("发票已红冲");
  8816. }
  8817. else if (onecres.IndexOf("重复冲红") != -1)
  8818. {
  8819. bill_entity.state = 4;//已作废
  8820. //bill_entity.Update();
  8821. //returnSuccessMsg("发票已红冲");
  8822. }
  8823. else
  8824. {
  8825. string errmsg = commonHelper.KeepChinese(onecres);
  8826. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8827. }
  8828. }
  8829. bill_entity.Update();
  8830. if (cres.IndexOf("失败") != -1)
  8831. returnErrorMsg("红冲失败");
  8832. else
  8833. returnSuccessMsg("发票已红冲");
  8834. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8835. return;
  8836. }
  8837. return;
  8838. }
  8839. }
  8840. public void del_erp_billorder()
  8841. {
  8842. if (UrlPostParmsCheck("id"))
  8843. {
  8844. string eid = GetPostString("id");
  8845. CeErpBill.Del(eid);
  8846. CeErpBill bill = CeErpBill.Get(eid);
  8847. if (bill != null)
  8848. {
  8849. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8850. }
  8851. returnSuccessMsg("删除成功");
  8852. }
  8853. }
  8854. public void finish_erp_bill()
  8855. {
  8856. if (UrlPostParmsCheck("ids"))
  8857. {
  8858. string eids = GetPostString("ids");
  8859. string[] list = eids.Split(',');
  8860. foreach (string eid in list)
  8861. {
  8862. CeErpBill bill = CeErpBill.Get(eid);
  8863. if (bill != null)
  8864. {
  8865. bill.state = 2;
  8866. bill.Update();
  8867. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8868. }
  8869. }
  8870. returnSuccessMsg("操作成功");
  8871. }
  8872. }
  8873. public void get_erp_returncash()
  8874. {
  8875. DataStruct dStruct = GetPostStruct();
  8876. List<string> lw = new List<string>();
  8877. string tid = GetPostString("tid");
  8878. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8879. string shopname = GetPostString("shopname");
  8880. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8881. string buyernick = GetPostString("buyer_nick");
  8882. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8883. string customer = GetPostString("customer");
  8884. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8885. string returndate1 = GetPostString("returndate1");
  8886. string returndate2 = GetPostString("returndate2");
  8887. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8888. if (dw.Length > 0) lw.Add(dw);
  8889. string finishDate1 = GetPostString("finishdate1");
  8890. string finishDate2 = GetPostString("finishdate2");
  8891. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8892. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8893. string returntype = GetPostString("returntype");
  8894. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8895. string returnvstate = GetPostString("returnvstate");
  8896. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8897. dStruct.Order = "created desc";
  8898. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8899. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8900. writeGridDataTableJson(dStruct.TotalCount, dt);
  8901. }
  8902. public void get_erp_staygoods()
  8903. {
  8904. DataStruct dStruct = GetPostStruct();
  8905. List<string> lw = new List<string>();
  8906. string tid = GetPostString("tid");
  8907. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8908. string shopname = GetPostString("shopname");
  8909. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8910. string wangwang = GetPostString("wangwang");
  8911. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8912. string customer = GetPostString("customer");
  8913. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8914. string returndate1 = GetPostString("returndate1");
  8915. string returndate2 = GetPostString("returndate2");
  8916. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8917. if (dw.Length > 0) lw.Add(dw);
  8918. string finishDate1 = GetPostString("finishdate1");
  8919. string finishDate2 = GetPostString("finishdate2");
  8920. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8921. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8922. string returnvstate = GetPostString("returnvstate");
  8923. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8924. string persuadetype = GetPostString("persuadetype");
  8925. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8926. string customerOrg = GetPostString("customerOrg");
  8927. if (customerOrg.Length > 0)
  8928. {
  8929. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8930. }
  8931. string designerorg = GetPostString("designerorg");
  8932. if (designerorg.Length > 0)
  8933. {
  8934. lw.Add(string.Format("OrgID = {0}", designerorg));
  8935. }
  8936. dStruct.Order = "creata_time desc";
  8937. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8938. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8939. writeGridDataTableJson(dStruct.TotalCount, dt);
  8940. }
  8941. public void upd_erp_staygoods()
  8942. {
  8943. if (UrlPostParmsCheck("id"))
  8944. {
  8945. int eid = GetPostInt("id");
  8946. CeErpStayGoods entity = null;
  8947. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8948. if (entity != null)
  8949. {
  8950. entity.audit_type = 1;
  8951. entity.audit_time = DateTime.Now;
  8952. entity.audit_u_id = CurrentUser.UserID;
  8953. entity.audit_u_name = CurrentUser.UserName;
  8954. entity.Update();
  8955. returnSuccessMsg("审核成功!");
  8956. return;
  8957. }
  8958. returnErrorMsg("找不到订单记录");
  8959. }
  8960. }
  8961. public void upd_erp_stayGoodsback()
  8962. {
  8963. if (UrlPostParmsCheck("id"))
  8964. {
  8965. int eid = GetPostInt("id");
  8966. CeErpStayGoods entity = null;
  8967. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8968. if (entity != null)
  8969. {
  8970. entity.audit_text = GetPostString("reason");
  8971. entity.audit_type = 2;
  8972. entity.audit_time = DateTime.Now;
  8973. entity.audit_u_id = CurrentUser.UserID;
  8974. entity.audit_u_name = CurrentUser.UserName;
  8975. entity.Update();
  8976. returnSuccessMsg("退回成功!");
  8977. return;
  8978. }
  8979. returnErrorMsg("找不到订单记录");
  8980. }
  8981. }
  8982. public void upd_erp_returncashverify()
  8983. {
  8984. if (UrlPostParmsCheck("ID"))
  8985. {
  8986. int eid = GetPostInt("ID");
  8987. CeErpReturnCash entity = null;
  8988. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8989. if (entity != null)
  8990. {
  8991. entity.cashstate = 1;
  8992. entity.verifytime = DateTime.Now;
  8993. entity.verifyuserid = CurrentUser.UserID;
  8994. entity.Update();
  8995. returnSuccessMsg("审核成功!");
  8996. return;
  8997. }
  8998. returnErrorMsg("找不到订单记录");
  8999. }
  9000. }
  9001. public void upd_all_erp_returncashverify()
  9002. {
  9003. if (UrlPostParmsCheck("ID"))
  9004. {
  9005. String[] list = GetPostString("ID").Split(',');
  9006. CeErpReturnCash entity = null;
  9007. for (int i = 0; i < list.Length; i++)
  9008. {
  9009. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  9010. if (entity != null)
  9011. {
  9012. if (entity.cashstate == 1)
  9013. {
  9014. returnErrorMsg("已审核过的订单不需要在审核!");
  9015. return;
  9016. }
  9017. entity.cashstate = 1;
  9018. entity.verifytime = DateTime.Now;
  9019. entity.verifyuserid = CurrentUser.UserID;
  9020. entity.Update();
  9021. }
  9022. }
  9023. returnSuccessMsg("审核成功!");
  9024. return;
  9025. }
  9026. }
  9027. public void upd_erp_returncashback()
  9028. {
  9029. if (UrlPostParmsCheck("ID"))
  9030. {
  9031. int eid = GetPostInt("ID");
  9032. CeErpReturnCash entity = null;
  9033. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9034. if (entity != null)
  9035. {
  9036. entity.backreason = GetPostString("reason");
  9037. entity.cashstate = 2;
  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_erp_returnprice()
  9048. {
  9049. if (UrlPostParmsCheck("ID"))
  9050. {
  9051. int eid = GetPostInt("ID");
  9052. CeErpReturnCash entity = null;
  9053. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9054. if (entity != null)
  9055. {
  9056. if (entity.cashstate == 1)
  9057. {
  9058. returnErrorMsg("审核通过了不能改");
  9059. return;
  9060. }
  9061. entity.returnprice = GetPostDouble("returnprice");
  9062. entity.Update();
  9063. returnSuccessMsg("修改成功!");
  9064. return;
  9065. }
  9066. returnErrorMsg("找不到订单记录");
  9067. }
  9068. }
  9069. public void del_erp_returncash()
  9070. {
  9071. if (UrlPostParmsCheck("ID"))
  9072. {
  9073. int eid = GetPostInt("ID");
  9074. CeErpReturnCash.Del(eid);
  9075. returnSuccessMsg("操作成功");
  9076. return;
  9077. }
  9078. }
  9079. public void test_for_do_sql()
  9080. {
  9081. string sql = GetPostString("sqlstr");
  9082. if (sql.Length > 0)
  9083. {
  9084. try
  9085. {
  9086. DbHelper.DbConn.ExecuteNonQuery(sql);
  9087. var res_obj = new
  9088. {
  9089. data = "成功",
  9090. };
  9091. string ro_json = JsonConvert.SerializeObject(res_obj);
  9092. returnSuccess(ro_json);
  9093. }
  9094. catch (Exception ex)
  9095. {
  9096. var res_obj = new
  9097. {
  9098. data = ex.Message,
  9099. };
  9100. string ro_json = JsonConvert.SerializeObject(res_obj);
  9101. returnSuccess(ro_json);
  9102. }
  9103. }
  9104. }
  9105. public void get_user_info()
  9106. {
  9107. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  9108. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  9109. }
  9110. public void get_total_data()
  9111. {
  9112. int userId = CurrentUser.UserID;
  9113. string sql = "";
  9114. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9115. {
  9116. 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);
  9117. }
  9118. else
  9119. {
  9120. 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 " +
  9121. "(select ID from CE_ErpUser where ID = {0}) d " +
  9122. "left join " +
  9123. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  9124. ") a on d.ID = a.id left join " +
  9125. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  9126. ") b on a.id = b.id1 left join" +
  9127. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  9128. ") c on a.id = c.id2;", userId);
  9129. }
  9130. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9131. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9132. }
  9133. public void get_date_area_total_data2()
  9134. {
  9135. int userId = CurrentUser.UserID;
  9136. string date_type = GetPostString("timetype");
  9137. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9138. string sql = "";
  9139. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9140. {
  9141. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  9142. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9143. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9144. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9145. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9146. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9147. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9148. ") a on e.ID = a.id left join " +
  9149. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9150. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9151. ") b on a.id = b.id1 " +
  9152. "left join " +
  9153. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9154. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9155. ") c on a.id = c.id2 " +
  9156. "left join " +
  9157. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9158. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9159. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9160. }
  9161. else
  9162. {
  9163. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9164. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9165. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9166. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9167. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9168. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9169. ") a on e.ID = a.id left join " +
  9170. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9171. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9172. ") c on a.id = c.id2 " +
  9173. "left join " +
  9174. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9175. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9176. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9177. }
  9178. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9179. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9180. }
  9181. public void get_date_area_total_data()
  9182. {
  9183. int userId = CurrentUser.UserID;
  9184. string date_type = GetPostString("timetype");
  9185. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9186. string date1 = searchDT[0].ToString();
  9187. string date2 = searchDT[1].ToString();
  9188. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9189. {
  9190. SqlParameter[] sqlParameter ={
  9191. new SqlParameter("@userId", SqlDbType.Int,4),
  9192. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9193. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9194. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9195. };
  9196. sqlParameter[0].Value = userId;
  9197. sqlParameter[1].Value = date1;
  9198. sqlParameter[2].Value = date2;
  9199. sqlParameter[3].Direction = ParameterDirection.Output;
  9200. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9201. string res = sqlParameter[3].Value.ToString();
  9202. var res_obj = new
  9203. {
  9204. data = res
  9205. };
  9206. string ro_json = JsonConvert.SerializeObject(res_obj);
  9207. returnSuccess(ro_json);
  9208. }
  9209. else
  9210. {
  9211. SqlParameter[] sqlParameter ={
  9212. new SqlParameter("@userId", SqlDbType.Int,4),
  9213. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9214. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9215. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9216. };
  9217. sqlParameter[0].Value = userId;
  9218. sqlParameter[1].Value = date1;
  9219. sqlParameter[2].Value = date2;
  9220. sqlParameter[3].Direction = ParameterDirection.Output;
  9221. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9222. string res = sqlParameter[3].Value.ToString();
  9223. var res_obj = new
  9224. {
  9225. data = res
  9226. };
  9227. string ro_json = JsonConvert.SerializeObject(res_obj);
  9228. returnSuccess(ro_json);
  9229. }
  9230. //writeGridDataViewJson(dt.Rows.Count, dv);
  9231. }
  9232. public void get_order_list()
  9233. {
  9234. string strFields = GetPostString("paraFields");
  9235. string strOrder = GetPostString("paraOrder");
  9236. string strWhere = GetPostString("paraWhere");
  9237. string strPageSize = GetPostString("paraPageSize");
  9238. DataStruct dStruct = GetPostStruct();
  9239. dStruct.PageSize = int.Parse(strPageSize);
  9240. dStruct.Fileds = strFields;
  9241. dStruct.Order = strOrder;
  9242. dStruct.MainWhere = strWhere;
  9243. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9244. writeGridDataTableJson(dStruct.TotalCount, dt);
  9245. }
  9246. ////获取待开始订单列表
  9247. //public void get_wait_design_order_list()
  9248. //{
  9249. // string date_type = GetPostString("date_type");
  9250. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9251. // DataStruct dStruct = GetPostStruct();
  9252. // dStruct.PageSize = 1000;
  9253. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9254. // List<string> lw = new List<string>();
  9255. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9256. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9257. // dStruct.Order = "WaitDesignTime asc";
  9258. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9259. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9260. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9261. //}
  9262. //获取完成单量排名
  9263. public void get_finish_order_count_ranking()
  9264. {
  9265. /* string date_type = GetPostString("date_type");
  9266. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9267. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9268. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9269. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9270. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9271. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9272. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9273. writeGridDataTableJson(0, new DataTable());
  9274. }
  9275. public void get_finish_order_amount_ranking()
  9276. {
  9277. /*string date_type = GetPostString("date_type");
  9278. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9279. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9280. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9281. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9282. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9283. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9284. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9285. writeGridDataTableJson(0, new DataTable());
  9286. }
  9287. public void get_finish_refund_count_ranking()
  9288. {
  9289. string date_type = GetPostString("date_type");
  9290. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9291. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9292. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9293. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9294. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9295. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9296. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9297. writeGridDataTableJson(dt.Rows.Count, dt);
  9298. }
  9299. public void get_finish_refund_amount_ranking()
  9300. {
  9301. string date_type = GetPostString("date_type");
  9302. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9303. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9304. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9305. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9306. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9307. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9308. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9309. writeGridDataTableJson(dt.Rows.Count, dt);
  9310. }
  9311. public void set_erp_finishorder_director()
  9312. {
  9313. if (UrlPostParmsCheck("ctid"))
  9314. {
  9315. string eid = GetPostString("ctid");
  9316. CeErpTradeCell entity = null;
  9317. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9318. if (entity != null)
  9319. {
  9320. entity.OrderState = 8;
  9321. entity.Update();
  9322. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9323. returnSuccessMsg("操作成功!");
  9324. return;
  9325. }
  9326. returnErrorMsg("找不到记录");
  9327. }
  9328. }
  9329. public void get_erp_placeregistlist()
  9330. {
  9331. DataStruct dStruct = GetPostStruct();
  9332. List<string> lw = new List<string>();
  9333. string outsid = GetPostString("outsid");
  9334. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9335. string memo = GetPostString("memo");
  9336. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9337. string filename = GetPostString("filename");
  9338. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9339. string islate = GetPostString("islate");
  9340. if (islate.Length > 0)
  9341. {
  9342. if (islate == "1")
  9343. lw.Add(string.Format("OutLate>0"));
  9344. else
  9345. lw.Add(string.Format("OutLate=0"));
  9346. }
  9347. string placedate1 = GetPostString("placedate1");
  9348. string placedate2 = GetPostString("placedate2");
  9349. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9350. if (dw.Length > 0) lw.Add(dw);
  9351. string deliveryDate1 = GetPostString("deliverydate1");
  9352. string deliveryDate2 = GetPostString("deliverydate2");
  9353. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9354. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9355. dStruct.Order = "ID desc";
  9356. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9357. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9358. writeGridDataTableJson(dStruct.TotalCount, dt);
  9359. }
  9360. public void ins_erp_placeregist()
  9361. {
  9362. if (UrlPostParmsCheck("id"))
  9363. {
  9364. string eid = GetPostString("id");
  9365. CeErpPlaceRegister entity = null;
  9366. if (eid == "0")//新增
  9367. {
  9368. entity = new CeErpPlaceRegister();
  9369. string xdTime = GetPostString("placeTime");
  9370. if (xdTime.Length > 0)
  9371. {
  9372. entity.PlactTime = Convert.ToDateTime(xdTime);
  9373. }
  9374. string fhTime = GetPostString("deliveryTime");
  9375. if (fhTime.Length > 0)
  9376. {
  9377. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9378. }
  9379. string preTime = GetPostString("preOutTime");
  9380. if (preTime.Length > 0)
  9381. {
  9382. entity.PreOutTime = Convert.ToDateTime(preTime);
  9383. }
  9384. entity.DeliveryCount = GetPostInt("deliveryCount");
  9385. entity.ReceiveCount = GetPostInt("receiveCount");
  9386. entity.OutSid = GetPostString("outSid");
  9387. entity.FileName = GetPostString("fileName");
  9388. entity.Memo = GetPostString("memo");
  9389. entity.AddUserId = CurrentUser.UserID;
  9390. entity.CreateTime = DateTime.Now;
  9391. entity.Img = GetPostString("img");
  9392. entity.Supplier = GetPostInt("supplier");
  9393. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9394. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9395. {
  9396. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9397. DateTime dt2 = (DateTime)entity.PreOutTime;
  9398. TimeSpan span = dt1.Subtract(dt2);
  9399. if (span.Days > 0)
  9400. {
  9401. entity.OutLate = span.Days;
  9402. }
  9403. }
  9404. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9405. entity.Create();
  9406. returnSuccessMsg("添加成功!");
  9407. return;
  9408. }
  9409. else //修改
  9410. {
  9411. entity = CeErpPlaceRegister.Get(eid);
  9412. if (entity != null)
  9413. {
  9414. string xdTime = GetPostString("placeTime");
  9415. if (xdTime.Length > 0)
  9416. {
  9417. entity.PlactTime = Convert.ToDateTime(xdTime);
  9418. }
  9419. string fhTime = GetPostString("deliveryTime");
  9420. if (fhTime.Length > 0)
  9421. {
  9422. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9423. }
  9424. string preTime = GetPostString("preOutTime");
  9425. if (preTime.Length > 0)
  9426. {
  9427. entity.PreOutTime = Convert.ToDateTime(preTime);
  9428. }
  9429. entity.DeliveryCount = GetPostInt("deliveryCount");
  9430. entity.ReceiveCount = GetPostInt("receiveCount");
  9431. if (entity.DeliveryCount == entity.ReceiveCount)
  9432. {
  9433. entity.CurState = "已完成";
  9434. }
  9435. else
  9436. {
  9437. entity.CurState = "未完成";
  9438. }
  9439. entity.OutSid = GetPostString("outSid");
  9440. entity.FileName = GetPostString("fileName");
  9441. entity.Memo = GetPostString("memo");
  9442. entity.Img = GetPostString("img");
  9443. entity.Supplier = GetPostInt("supplier");
  9444. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9445. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9446. {
  9447. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9448. DateTime dt2 = (DateTime)entity.PreOutTime;
  9449. TimeSpan span = dt1.Subtract(dt2);
  9450. if (span.Days > 0)
  9451. {
  9452. entity.OutLate = span.Days;
  9453. }
  9454. }
  9455. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9456. entity.Update();
  9457. returnSuccessMsg("修改成功");
  9458. return;
  9459. }
  9460. returnErrorMsg("找不到对应的记录");
  9461. return;
  9462. }
  9463. }
  9464. returnErrorMsg("缺少必要参数");
  9465. }
  9466. public void del_erp_placeregist()
  9467. {
  9468. string eid = GetPostString("id");
  9469. CeErpPlaceRegister.Del(eid);
  9470. returnSuccessMsg("删除成功!");
  9471. return;
  9472. }
  9473. public void ins_erp_placeregistbyorder()
  9474. {
  9475. string ctid = GetPostString("ctid");
  9476. if (ctid.Length > 0)
  9477. {
  9478. StringBuilder sql = new StringBuilder();
  9479. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9480. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9481. if (dt.Rows.Count > 0)
  9482. {
  9483. foreach (DataRow dr in dt.Rows)
  9484. {
  9485. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9486. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9487. entity.AddUserId = CurrentUser.UserID;
  9488. entity.tid = dr["tid"].ToString();
  9489. entity.Did = Convert.ToString(dr["ctid"]);
  9490. entity.splitTag = dr["SplitTag"].ToString();
  9491. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9492. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9493. if (pre_ctid.Length > 0)
  9494. {
  9495. sellmemo = sellmemo.Replace(pre_ctid, "");
  9496. }
  9497. sellmemo = sellmemo.Replace("[", "");
  9498. sellmemo = sellmemo.Replace("]", "");
  9499. entity.FileName = sellmemo;
  9500. string count = dr["ProductCount"].ToString();
  9501. int usecount = commonHelper.getIntCountFromString(count);
  9502. entity.DeliveryCount = usecount;
  9503. entity.CurState = "未完成";
  9504. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9505. {
  9506. entity.Supplier = 24;//dl手提袋定制
  9507. }
  9508. else
  9509. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9510. entity.CreateTime = DateTime.Now;
  9511. entity.Create();
  9512. }
  9513. returnSuccessMsg("操作成功");
  9514. return;
  9515. }
  9516. returnErrorMsg("没有找到对应订单");
  9517. return;
  9518. }
  9519. returnErrorMsg("缺少订单编号");
  9520. return;
  9521. }
  9522. public void get_erp_persuadelist()
  9523. {
  9524. DataStruct dStruct = GetPostStruct();
  9525. List<string> lw = new List<string>();
  9526. string ctid = GetPostString("ctid");
  9527. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9528. string shopname = GetPostString("shopname");
  9529. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9530. string buyernick = GetPostString("buyer_nick");
  9531. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9532. string customer = GetPostString("customer");
  9533. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9534. string returndate1 = GetPostString("returndate1");
  9535. string returndate2 = GetPostString("returndate2");
  9536. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9537. if (dw.Length > 0) lw.Add(dw);
  9538. string finishDate1 = GetPostString("finishdate1");
  9539. string finishDate2 = GetPostString("finishdate2");
  9540. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9541. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9542. string persuadetype = GetPostString("persuadetype");
  9543. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9544. string returnvstate = GetPostString("returnvstate");
  9545. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9546. dStruct.Order = "created desc";
  9547. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9548. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9549. writeGridDataTableJson(dStruct.TotalCount, dt);
  9550. }
  9551. public void upd_erp_returnpersuadeback()
  9552. {
  9553. if (UrlPostParmsCheck("ID"))
  9554. {
  9555. int eid = GetPostInt("ID");
  9556. CeErpPersuade entity = null;
  9557. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9558. if (entity != null)
  9559. {
  9560. entity.backreason = GetPostString("reason");
  9561. entity.pstate = 2;
  9562. entity.verifytime = DateTime.Now;
  9563. entity.verifyuserid = CurrentUser.UserID;
  9564. entity.Update();
  9565. returnSuccessMsg("退回成功!");
  9566. return;
  9567. }
  9568. returnErrorMsg("找不到订单记录");
  9569. }
  9570. }
  9571. public void upd_erp_returnpersuadeverify()
  9572. {
  9573. if (UrlPostParmsCheck("ID"))
  9574. {
  9575. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9576. {
  9577. returnErrorMsg("暂无权限审核");
  9578. return;
  9579. }
  9580. int eid = GetPostInt("ID");
  9581. CeErpPersuade entity = null;
  9582. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9583. if (entity != null)
  9584. {
  9585. entity.pstate = 1;
  9586. entity.verifytime = DateTime.Now;
  9587. entity.verifyuserid = CurrentUser.UserID;
  9588. entity.Update();
  9589. returnSuccessMsg("审核成功!");
  9590. return;
  9591. }
  9592. returnErrorMsg("找不到订单记录");
  9593. }
  9594. }
  9595. public void del_erp_persuade()
  9596. {
  9597. if (UrlPostParmsCheck("ID"))
  9598. {
  9599. int eid = GetPostInt("ID");
  9600. CeErpPersuade.Del(eid);
  9601. returnSuccessMsg("操作成功");
  9602. return;
  9603. }
  9604. }
  9605. public void get_erp_oldcustoupload()
  9606. {
  9607. DataStruct dStruct = GetPostStruct();
  9608. List<string> lw = new List<string>();
  9609. string buyernick = GetPostString("buyer_nick");
  9610. if (buyernick.Length > 0)
  9611. {
  9612. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9613. }
  9614. else
  9615. return;
  9616. dStruct.Order = "pay_time desc";
  9617. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9618. DataTable dt = null;
  9619. dt = WebCache.GetData("view_erptradecell", dStruct);
  9620. writeGridDataTableJson(dStruct.TotalCount, dt);
  9621. }
  9622. public void get_erp_checkorderlist()
  9623. {
  9624. DataStruct dStruct = GetPostStruct();
  9625. List<string> lw = new List<string>();
  9626. string tid = GetPostString("ctid");
  9627. if (tid.Length > 0)
  9628. {
  9629. string select_tid = getTidByCtid(tid);
  9630. lw.Add(string.Format("tid='{0}'", select_tid));
  9631. }
  9632. string shopname = GetPostString("shopname");
  9633. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9634. string buyernick = GetPostString("buyer_nick");
  9635. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9636. string customer = GetPostString("customer");
  9637. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9638. string design = GetPostString("design");
  9639. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9640. string orderState = GetPostString("orderState");
  9641. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9642. string address = GetPostString("address");
  9643. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9644. string sellermemo = GetPostString("seller_memo");
  9645. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9646. string supplier = GetPostString("supplier");
  9647. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9648. {
  9649. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9650. }
  9651. else
  9652. {
  9653. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9654. }
  9655. string date1 = GetPostString("date1");
  9656. string date2 = GetPostString("date2");
  9657. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9658. if (dw.Length > 0) lw.Add(dw);
  9659. string placedate1 = GetPostString("placedate1");
  9660. string placedate2 = GetPostString("placedate2");
  9661. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9662. if (fdw.Length > 0) lw.Add(fdw);
  9663. string price1 = GetPostString("price1");
  9664. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9665. string price2 = GetPostString("price2");
  9666. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9667. string checkst = GetPostString("checkstate");
  9668. if (checkst.Length > 0 && "10".Equals(checkst))
  9669. {
  9670. lw.Add(string.Format("CheckOut>0"));
  9671. }
  9672. else
  9673. {
  9674. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9675. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9676. }
  9677. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9678. {
  9679. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9680. }
  9681. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9682. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9683. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9684. writeGridDataTableJson(dStruct.TotalCount, dt);
  9685. }
  9686. public void ins_erp_startCheck()
  9687. {
  9688. if (UrlPostParmsCheck("ctid"))
  9689. {
  9690. string eid = GetPostString("ctid");
  9691. CeErpTradeCell entity = null;
  9692. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9693. if (entity != null)
  9694. {
  9695. entity.MemoOpt = 4;
  9696. entity.UpdateTime = DateTime.Now;
  9697. entity.Update();
  9698. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9699. CeErpSukuraData.createInfo(entity.ctid, 6);
  9700. returnSuccessMsg("操作成功!");
  9701. return;
  9702. }
  9703. returnErrorMsg("找不到记录");
  9704. }
  9705. }
  9706. public void upd_erp_sendXlw()
  9707. {
  9708. if (UrlPostParmsCheck("ctid"))
  9709. {
  9710. string eid = GetPostString("ctid");
  9711. CeErpTradeCell entity = null;
  9712. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9713. if (entity != null)
  9714. {
  9715. if (entity.IsSendGift == 1)
  9716. {
  9717. returnErrorMsg("请勿重复标记");
  9718. return;
  9719. }
  9720. entity.IsSendGift = 1;
  9721. entity.Update();
  9722. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9723. returnSuccessMsg("操作成功!");
  9724. return;
  9725. }
  9726. returnErrorMsg("找不到记录");
  9727. }
  9728. }
  9729. public void cancel_sendXlw()
  9730. {
  9731. if (UrlPostParmsCheck("ctid"))
  9732. {
  9733. string eid = GetPostString("ctid");
  9734. CeErpTradeCell entity = null;
  9735. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9736. if (entity != null)
  9737. {
  9738. if (entity.IsSendGift == 0)
  9739. {
  9740. returnErrorMsg("未标记小礼物");
  9741. return;
  9742. }
  9743. entity.IsSendGift = 0;
  9744. entity.Update();
  9745. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9746. returnSuccessMsg("操作成功!");
  9747. return;
  9748. }
  9749. returnErrorMsg("找不到记录");
  9750. }
  9751. }
  9752. public void get_erp_designbill()
  9753. {
  9754. DataStruct dStruct = GetPostStruct();
  9755. List<string> lw = new List<string>();
  9756. int isMy = GetInt("my");
  9757. if (isMy == 1)
  9758. {
  9759. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9760. }
  9761. string tid = GetPostString("tid");
  9762. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9763. string userName = GetPostString("design");
  9764. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9765. string price1 = GetPostString("price1");
  9766. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9767. string price2 = GetPostString("price2");
  9768. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9769. string rePrice1 = GetPostString("rePrice1");
  9770. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9771. string rePrice2 = GetPostString("rePrice2");
  9772. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9773. string designerType = GetPostString("designerType");
  9774. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9775. string orderState = GetPostString("orderState");
  9776. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9777. string endTime1 = GetPostString("endTime1");
  9778. string endTime2 = GetPostString("endTime2");
  9779. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9780. if (dw.Length > 0) lw.Add(dw);
  9781. string isDk = GetPostString("isDk");
  9782. if (isDk == "1")
  9783. {
  9784. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9785. }
  9786. else if (isDk == "0")
  9787. {
  9788. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9789. }
  9790. dStruct.Order = "oid, create_time desc";
  9791. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9792. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9793. writeGridDataTableJson(dStruct.TotalCount, dt);
  9794. }
  9795. public void upd_erp_designerbill()
  9796. {
  9797. if (UrlPostParmsCheck("ID"))
  9798. {
  9799. string eid = GetPostString("ID");
  9800. CeErpDesignerBill entity = null;
  9801. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9802. if (entity != null)
  9803. {
  9804. if (GetPostDouble("designerpirce") > 0)
  9805. {
  9806. entity.realPrice = GetPostDouble("designerpirce");
  9807. entity.update_time = DateTime.Now;
  9808. entity.update_u_id = CurrentUser.UserID;
  9809. entity.update_u_name = CurrentUser.UserName;
  9810. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9811. entity.Update();
  9812. returnSuccessMsg("操作成功!");
  9813. return;
  9814. }
  9815. else
  9816. {
  9817. entity.price = GetPostDouble("price");
  9818. entity.update_time = DateTime.Now;
  9819. entity.update_u_id = CurrentUser.UserID;
  9820. entity.update_u_name = CurrentUser.UserName;
  9821. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9822. entity.Update();
  9823. returnSuccessMsg("操作成功!");
  9824. return;
  9825. }
  9826. }
  9827. returnErrorMsg("找不到记录");
  9828. }
  9829. }
  9830. public void audit_erp_designerbill()
  9831. {
  9832. if (UrlPostParmsCheck("ID"))
  9833. {
  9834. string eid = GetPostString("ID");
  9835. CeErpDesignerBill entity = null;
  9836. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9837. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9838. if (entity != null)
  9839. {
  9840. entity.realPrice = GetPostDouble("designerpirce");
  9841. entity.update_time = DateTime.Now;
  9842. entity.update_u_id = CurrentUser.UserID;
  9843. entity.update_u_name = CurrentUser.UserName;
  9844. entity.isAudit = 1;
  9845. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9846. entity.Update();
  9847. if (orderEntity != null)
  9848. {
  9849. orderEntity.IsReadTag = 3;
  9850. orderEntity.Update();
  9851. }
  9852. returnSuccessMsg("操作成功!");
  9853. return;
  9854. }
  9855. returnErrorMsg("找不到记录");
  9856. }
  9857. }
  9858. public void all_audit_erp_designerbill()
  9859. {
  9860. if (UrlPostParmsCheck("idList"))
  9861. {
  9862. string[] list = GetPostString("idList").Split(',');
  9863. CeErpDesignerBill entity = null;
  9864. for (int i = 0; i < list.Length; i++)
  9865. {
  9866. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9867. if (entity == null) return;
  9868. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9869. if (orderEntity == null) return;
  9870. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9871. entity.update_time = DateTime.Now;
  9872. entity.update_u_id = CurrentUser.UserID;
  9873. entity.update_u_name = CurrentUser.UserName;
  9874. entity.isAudit = 1;
  9875. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9876. entity.Update();
  9877. orderEntity.IsReadTag = 3;
  9878. orderEntity.Update();
  9879. }
  9880. returnSuccessMsg("操作成功!");
  9881. return;
  9882. }
  9883. }
  9884. public void get_erp_sameorders()
  9885. {
  9886. if (UrlPostParmsCheck("ctid"))
  9887. {
  9888. string eid = GetPostString("ctid");
  9889. CeErpTradeCell entity = null;
  9890. entity = CeErpTradeCell.GetByCtid(eid);
  9891. if (entity != null)
  9892. {
  9893. StringBuilder sql = new StringBuilder();
  9894. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9895. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9896. var res = new
  9897. {
  9898. data = dt.Rows.Count
  9899. };
  9900. string ro_jsond = JsonConvert.SerializeObject(res);
  9901. returnSuccess(ro_jsond);
  9902. return;
  9903. }
  9904. returnErrorMsg("未找到订单");
  9905. return;
  9906. }
  9907. returnErrorMsg("缺少必要的参数");
  9908. }
  9909. public void get_erp_islasthavesameorder()
  9910. {
  9911. if (UrlPostParmsCheck("ctid"))
  9912. {
  9913. string eid = GetPostString("ctid");
  9914. string[] ctidList = eid.Split(',');
  9915. StringBuilder sql = new StringBuilder();
  9916. string tisCtid = "";
  9917. foreach (string ctid in ctidList)
  9918. {
  9919. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9920. if (entity != null)
  9921. {
  9922. sql = new StringBuilder();
  9923. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9924. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9925. if (dth.Rows.Count > 0)
  9926. {
  9927. tisCtid += entity.ctid;
  9928. tisCtid += ",";
  9929. }
  9930. }
  9931. }
  9932. if (tisCtid.Length > 0)
  9933. {
  9934. var res = new
  9935. {
  9936. data = tisCtid
  9937. };
  9938. string ro_jsond = JsonConvert.SerializeObject(res);
  9939. returnSuccess(ro_jsond);
  9940. }
  9941. else
  9942. {
  9943. var res = new
  9944. {
  9945. data = ""
  9946. };
  9947. string ro_jsond = JsonConvert.SerializeObject(res);
  9948. returnSuccess(ro_jsond);
  9949. }
  9950. return;
  9951. }
  9952. returnErrorMsg("缺少必要的参数");
  9953. }
  9954. public void file_client_down_url()
  9955. {
  9956. if (!UrlPostParmsCheck("userId"))
  9957. {
  9958. returnErrorMsg("缺少必要的参数");
  9959. }
  9960. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9961. }
  9962. public void checkout_form_data()
  9963. {
  9964. if (!UrlPostParmsCheck("tid"))
  9965. {
  9966. returnErrorMsg("缺少必要的参数");
  9967. }
  9968. string tid = GetPostString("tid");
  9969. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9970. if (ceErpOrderFormData != null)
  9971. {
  9972. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9973. returnSuccess(ro_jsond);
  9974. return;
  9975. }
  9976. returnErrorMsg("尚未有文件!");
  9977. }
  9978. public void back_supplier_audit()
  9979. {
  9980. int userId = CurrentUser.UserID;
  9981. StringBuilder sql = new StringBuilder();
  9982. 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);
  9983. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9984. if (dt.Rows.Count > 0)
  9985. {
  9986. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9987. }
  9988. else
  9989. {
  9990. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9991. }
  9992. }
  9993. public void back_supplier_query()
  9994. {
  9995. string eid = GetPostString("ctid");
  9996. if (eid != "")
  9997. {
  9998. StringBuilder sql = new StringBuilder();
  9999. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  10000. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10001. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10002. }
  10003. else
  10004. {
  10005. returnErrorMsg("找不到订单记录");
  10006. return;
  10007. }
  10008. }
  10009. public void verified_to_order()
  10010. {
  10011. int userId = CurrentUser.UserID;
  10012. StringBuilder sql = new StringBuilder();
  10013. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  10014. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10015. if (dt.Rows.Count > 0)
  10016. {
  10017. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10018. }
  10019. else
  10020. {
  10021. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10022. }
  10023. }
  10024. public void upd_supplier_audit()
  10025. {
  10026. if (UrlPostParmsCheck("ctid"))
  10027. {
  10028. string eid = GetPostString("ctid");
  10029. string reason = GetPostString("returnreason");
  10030. CeErpTradeCell entity = null;
  10031. CeWithdraw withdraw = null;
  10032. withdraw = CeWithdraw.GetByTid(eid);
  10033. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  10034. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  10035. {
  10036. if (withdraw != null)
  10037. {
  10038. if (!withdraw.userid.Equals(CurrentUser.UserID))
  10039. {
  10040. returnSuccessMsg("您没有权限操作!");
  10041. return;
  10042. }
  10043. else
  10044. {
  10045. if (reason.Equals("1"))
  10046. {
  10047. if (entity.OrderState == -1)
  10048. {
  10049. if (entity.FinishPlaceTime == null)
  10050. {
  10051. entity.OrderState = 2;
  10052. }
  10053. else
  10054. {
  10055. entity.OrderState = 6;
  10056. }
  10057. }
  10058. entity.Update();
  10059. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10060. if (withdraw != null)
  10061. {
  10062. withdraw.status = int.Parse(reason);
  10063. withdraw.Update();
  10064. }
  10065. returnSuccessMsg("操作成功!");
  10066. return;
  10067. }
  10068. else
  10069. {
  10070. withdraw.status = int.Parse(reason);
  10071. withdraw.acknowledgingtime = DateTime.Now;
  10072. withdraw.Update();
  10073. returnSuccessMsg("查看详细请点击线下订单查询");
  10074. return;
  10075. }
  10076. }
  10077. }
  10078. // 第一个字符是 'N'
  10079. }
  10080. if (eid[0] != 'N')
  10081. {
  10082. }
  10083. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  10084. {
  10085. entity.IsVerifyToSupplier = false;
  10086. entity.IsReturn = 1;
  10087. entity.ReturnTime = DateTime.Now;
  10088. entity.ReturnReason = reason;
  10089. if (entity.OrderState == 6)
  10090. {
  10091. entity.OrderState = 5;
  10092. }
  10093. entity.Update();
  10094. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  10095. if (withdraw != null)
  10096. {
  10097. withdraw.status = int.Parse(reason);
  10098. withdraw.Update();
  10099. }
  10100. returnSuccessMsg("操作成功!");
  10101. return;
  10102. }
  10103. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  10104. {
  10105. ;
  10106. if (withdraw != null)
  10107. {
  10108. withdraw.status = int.Parse(reason);
  10109. withdraw.acknowledgingtime = DateTime.Now;
  10110. withdraw.Update();
  10111. returnSuccessMsg("供应商取消撤回!");
  10112. return;
  10113. }
  10114. }
  10115. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  10116. {
  10117. if (entity.OrderState == -1)
  10118. {
  10119. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  10120. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10121. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  10122. {
  10123. returnErrorMsg("台湾客户需填写身份证!");
  10124. return;
  10125. }
  10126. if (commonHelper.isFarAddress(ceErpTrade.receiver_state) && ceErpTrade.delivery_paymant == 0 && entity.IsSF != 2)
  10127. {
  10128. returnErrorMsg("偏远地区需要填写物流费!");
  10129. return;
  10130. }
  10131. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  10132. {
  10133. returnErrorMsg("订单spu没有确认无法通过审核!");
  10134. return;
  10135. }
  10136. if (entity.FinishPlaceTime == null)
  10137. {
  10138. entity.OrderState = 2;
  10139. }
  10140. else
  10141. {
  10142. entity.OrderState = 3;
  10143. }
  10144. commonHelper.getCytPrice(entity);
  10145. if ((entity.OtherMemo.Contains("老客户") || entity.OtherMemo.Contains("老顾客")) && entity.OtherMemo.Contains("改稿"))
  10146. {
  10147. tmcHelper.dealOldCustomerEntityTag(ref entity, ceErpTrade);
  10148. }
  10149. if (entity.IsSample > 1 || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物"))
  10150. {
  10151. entity.OrderState = 6;
  10152. }
  10153. }
  10154. entity.Update();
  10155. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10156. if (withdraw != null)
  10157. {
  10158. withdraw.status = int.Parse(reason);
  10159. withdraw.Update();
  10160. }
  10161. returnSuccessMsg("操作成功!");
  10162. return;
  10163. }
  10164. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10165. {
  10166. if (withdraw == null)
  10167. {
  10168. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10169. return;
  10170. }
  10171. }
  10172. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10173. {
  10174. if (withdraw != null)
  10175. {
  10176. withdraw.status = int.Parse(reason);
  10177. withdraw.acknowledgingtime = DateTime.Now;
  10178. withdraw.Update();
  10179. returnSuccessMsg("查看详细请点击线下订单查询");
  10180. return;
  10181. }
  10182. }
  10183. return;
  10184. }
  10185. }
  10186. //校验报价
  10187. public void refund_order_tip()
  10188. {
  10189. int userid = CurrentUser.UserID;
  10190. int sectionId = CurrentUser.UserPost.OrgID;
  10191. StringBuilder sql = new StringBuilder();
  10192. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10193. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10194. List<string> ids = new List<string>();
  10195. if (dth.Rows.Count > 0)
  10196. {
  10197. foreach (DataRow dr in dth.Rows)
  10198. {
  10199. ids.Add(dr["ID"].ToString());
  10200. }
  10201. try
  10202. {
  10203. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10204. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10205. }
  10206. catch (Exception ex)
  10207. {
  10208. }
  10209. }
  10210. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10211. }
  10212. public void refund_order_Design()
  10213. {
  10214. int userid = CurrentUser.UserID;
  10215. int sectionId = CurrentUser.UserPost.OrgID;
  10216. StringBuilder sql = new StringBuilder();
  10217. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10218. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10219. List<string> ids = new List<string>();
  10220. if (dth.Rows.Count > 0)
  10221. {
  10222. foreach (DataRow dr in dth.Rows)
  10223. {
  10224. ids.Add(dr["ID"].ToString());
  10225. }
  10226. try
  10227. {
  10228. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10229. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10230. }
  10231. catch (Exception ex)
  10232. {
  10233. }
  10234. }
  10235. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10236. }
  10237. public void change_order_info()
  10238. {
  10239. int userid = CurrentUser.UserID;
  10240. StringBuilder sql = new StringBuilder();
  10241. 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);
  10242. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10243. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10244. }
  10245. public void change_win_mome()
  10246. {
  10247. if (UrlPostParmsCheck("id,ctid"))
  10248. {
  10249. string id = GetPostString("id");
  10250. string ctid = GetPostString("ctid");
  10251. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10252. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10253. if (ce == null || ceErpMessageTip == null)
  10254. {
  10255. returnSuccessMsg("未找到对应的订单!");
  10256. return;
  10257. }
  10258. if (ce.OrderState >= 5)
  10259. {
  10260. ceErpMessageTip.isVisit = true;
  10261. ceErpMessageTip.Update();
  10262. returnSuccessMsg("已上传文件无法修改!");
  10263. return;
  10264. }
  10265. int type = GetPostInt("type");
  10266. string content = GetPostString("content");
  10267. if (type == 0)
  10268. {
  10269. content = content.Replace("(", "(");
  10270. content = content.Replace(")", ")");
  10271. string check = MidStrEx(content, "(", ")").Trim();
  10272. if (string.IsNullOrEmpty(check))
  10273. {
  10274. returnSuccessMsg("文件名格式不正确");
  10275. return;
  10276. }
  10277. }
  10278. ce.seller_memo = content;
  10279. ce.Update();
  10280. ceErpMessageTip.isVisit = true;
  10281. ceErpMessageTip.Update();
  10282. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10283. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10284. ApiVo apiVo = new ApiVo();
  10285. apiVo.orderNumber = ce.ctid;
  10286. apiVo.actionName = "demandDesign";
  10287. apiVo.orderRemarks = content;
  10288. apiVo.demandExamine = type + 1;
  10289. designHelper.API_WorkCore(apiVo);//demandDesign
  10290. returnSuccessMsg("修改成功!");
  10291. }
  10292. }
  10293. public static string MidStrEx(string sourse, string startstr, string endstr)
  10294. {
  10295. string result = string.Empty;
  10296. int startindex, endindex;
  10297. try
  10298. {
  10299. startindex = sourse.IndexOf(startstr);
  10300. if (startindex == -1)
  10301. return result;
  10302. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10303. endindex = tmpstr.IndexOf(endstr);
  10304. if (endindex == -1)
  10305. return result;
  10306. result = tmpstr.Remove(endindex);
  10307. }
  10308. catch (Exception ex)
  10309. {
  10310. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10311. }
  10312. return result;
  10313. }
  10314. public void refund_order_list()
  10315. {
  10316. int userid = CurrentUser.UserID;
  10317. int sectionId = CurrentUser.UserPost.OrgID;
  10318. StringBuilder sql = new StringBuilder();
  10319. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10320. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10321. DataStruct dStruct = GetPostStruct();
  10322. DataTable dt = null;
  10323. List<string> ids = new List<string>();
  10324. List<string> tids = new List<string>();
  10325. if (dth.Rows.Count > 0)
  10326. {
  10327. foreach (DataRow dr in dth.Rows)
  10328. {
  10329. tids.Add("'" + dr["tid"].ToString() + "'");
  10330. ids.Add(dr["id"].ToString());
  10331. }
  10332. try
  10333. {
  10334. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10335. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10336. List<string> lw = new List<string>();
  10337. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10338. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10339. dt = WebCache.GetData("view_orderlist", dStruct);
  10340. }
  10341. catch (Exception ex)
  10342. {
  10343. }
  10344. }
  10345. writeGridDataTableJson(dStruct.TotalCount, dt);
  10346. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10347. }
  10348. //新增
  10349. public void order_batch_downloads()
  10350. {
  10351. string ceid = GetPostString("tid");
  10352. String[] tid = ceid.Split(',');
  10353. order_batch_caiyingtong(tid);
  10354. /* (string success, string errors) = UploadFiles(tid);
  10355. returnSuccessMsg(success + errors);*/
  10356. return;
  10357. }
  10358. //报价接口
  10359. public void Get_To_Quote()
  10360. {
  10361. string ceid = GetPostString("ctid");
  10362. if (ceid != null)
  10363. {
  10364. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10365. if (entity != null)
  10366. {
  10367. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10368. {
  10369. return;
  10370. }
  10371. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10372. double price = 0;
  10373. if (cp == null)
  10374. {
  10375. JObject jsonObject12 = new JObject
  10376. {
  10377. { "UserId", "77886" },
  10378. { "Pwd", "lt666888" },
  10379. { "Filename", entity.seller_memo }
  10380. };
  10381. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10382. JObject jsonObjects1 = JObject.Parse(response1);
  10383. string ms1g = (string)jsonObjects1["msg"];
  10384. if (ms1g == "报价成功")
  10385. {
  10386. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10387. string data = (string)jsonObject1["price"];
  10388. 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 + "');";
  10389. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10390. returnSuccessMsg("获取报价成功:" + data);
  10391. price = Convert.ToDouble(data);
  10392. }
  10393. else
  10394. {
  10395. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10396. return;
  10397. }
  10398. }
  10399. String[] beizhu = entity.seller_memo.Split('-');
  10400. String chanp = "";
  10401. if (beizhu.Length > 0)
  10402. {
  10403. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10404. }
  10405. else
  10406. {
  10407. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10408. }
  10409. JObject jsonObject = new JObject
  10410. {
  10411. { "UserId", "77886" },
  10412. { "Pwd", "lt666888" },
  10413. { "Filename", chanp }
  10414. };
  10415. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10416. JObject jsonObjects = JObject.Parse(response);
  10417. string msg = (string)jsonObjects["msg"];
  10418. if (msg == "报价成功")
  10419. {
  10420. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10421. string data = (string)jsonObject1["price"];
  10422. 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 + "');";
  10423. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10424. returnSuccessMsg("获取报价成功:" + data);
  10425. price = Convert.ToDouble(data);
  10426. }
  10427. else
  10428. {
  10429. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10430. return;
  10431. }
  10432. if (price > 0)
  10433. {
  10434. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10435. if (ceErpTradeCellExtend == null)
  10436. {
  10437. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10438. ceErpTradeCellExtend.ctid = entity.ctid;
  10439. ceErpTradeCellExtend.payment_cyt = price;
  10440. ceErpTradeCellExtend.Create();
  10441. }
  10442. else
  10443. {
  10444. ceErpTradeCellExtend.payment_cyt = price;
  10445. ceErpTradeCellExtend.Update();
  10446. }
  10447. }
  10448. return;
  10449. }
  10450. }
  10451. else
  10452. {
  10453. returnErrorMsg("请至少选择一条数据");
  10454. return;
  10455. }
  10456. }
  10457. //新增
  10458. public void order_To_Supplier()
  10459. {
  10460. string ceid = GetPostString("tid");
  10461. String[] tid = ceid.Split(',');
  10462. if (tid.Length > 0)
  10463. {
  10464. try
  10465. {
  10466. for (int i = 0; i < tid.Length; i++)
  10467. {
  10468. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10469. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10470. entity.SupplierId = suid;
  10471. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10472. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10473. entity.Update();
  10474. }
  10475. }
  10476. catch (Exception ex)
  10477. {
  10478. returnErrorMsg("自动匹配供应商失败");
  10479. return;
  10480. }
  10481. }
  10482. else
  10483. {
  10484. returnErrorMsg("请至少选择一条数据");
  10485. return;
  10486. }
  10487. returnSuccessMsg("自动匹配供应商成功");
  10488. return;
  10489. }
  10490. public (string, string) UploadFiles(string[] urls)
  10491. {
  10492. string success = "";
  10493. string errors = "";
  10494. int userid = CurrentUser.UserID;
  10495. foreach (string url in urls)
  10496. {
  10497. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10498. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10499. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10500. {
  10501. JObject jsonObject = new JObject
  10502. {
  10503. { "Userid", "77886" },
  10504. { "pwd", "cyt86435015" },
  10505. { "content", base64FileContent },
  10506. { "ext", Path.GetExtension(fileName) }
  10507. };
  10508. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10509. JObject jsonObjects = JObject.Parse(response);
  10510. string msg = (string)jsonObjects["msg"];
  10511. if (msg.Equals("上传成功"))
  10512. {
  10513. success += url + " 上传成功";
  10514. }
  10515. else
  10516. {
  10517. errors += url + " 上传失败";
  10518. }
  10519. }
  10520. else
  10521. {
  10522. errors += url + " 格式出现问题";
  10523. }
  10524. }
  10525. if (urls.Length == 0)
  10526. {
  10527. return (success, errors);
  10528. }
  10529. return (success, errors);
  10530. }
  10531. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10532. {
  10533. return true; //总是接受
  10534. }
  10535. public static string HttpPost(string url, string param = null)
  10536. {
  10537. HttpWebRequest request;
  10538. //如果是发送HTTPS请求
  10539. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10540. {
  10541. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10542. request = WebRequest.Create(url) as HttpWebRequest;
  10543. request.ProtocolVersion = HttpVersion.Version10;
  10544. }
  10545. else
  10546. {
  10547. request = WebRequest.Create(url) as HttpWebRequest;
  10548. }
  10549. request.Method = "POST";
  10550. request.ContentType = "application/json";
  10551. request.Accept = "*/*";
  10552. request.Timeout = 120000;
  10553. request.AllowAutoRedirect = false;
  10554. StreamWriter requestStream = null;
  10555. WebResponse response = null;
  10556. string responseStr = null;
  10557. try
  10558. {
  10559. requestStream = new StreamWriter(request.GetRequestStream());
  10560. requestStream.Write(param);
  10561. requestStream.Close();
  10562. response = request.GetResponse();
  10563. if (response != null)
  10564. {
  10565. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10566. responseStr = reader.ReadToEnd();
  10567. reader.Close();
  10568. }
  10569. }
  10570. catch (Exception ex)
  10571. {
  10572. return ex.Message;
  10573. }
  10574. finally
  10575. {
  10576. request = null;
  10577. requestStream = null;
  10578. response = null;
  10579. }
  10580. return responseStr;
  10581. }
  10582. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10583. {
  10584. string base64FileContent;
  10585. string fileName;
  10586. using (WebClient webClient = new WebClient())
  10587. {
  10588. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10589. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10590. {
  10591. using (Stream stream = response.GetResponseStream())
  10592. {
  10593. using (MemoryStream memoryStream = new MemoryStream())
  10594. {
  10595. stream.CopyTo(memoryStream);
  10596. byte[] fileBytes = memoryStream.ToArray();
  10597. base64FileContent = Convert.ToBase64String(fileBytes);
  10598. fileName = response.Headers["Content-Disposition"];
  10599. if (!string.IsNullOrEmpty(fileName))
  10600. {
  10601. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10602. if (index >= 0)
  10603. {
  10604. fileName = fileName.Substring(index + 9).Trim('\"');
  10605. }
  10606. }
  10607. else
  10608. {
  10609. fileName = Path.GetFileName(downloadUrl);
  10610. }
  10611. }
  10612. }
  10613. }
  10614. }
  10615. return (fileName, base64FileContent);
  10616. }
  10617. //新增
  10618. public void order_batch_caiyingtong(string[] downloadUrls)
  10619. {
  10620. try
  10621. {
  10622. //遍历文件
  10623. DataStruct dStruct = GetPostStruct();
  10624. DataTable dt = null;
  10625. int userid = CurrentUser.UserID;
  10626. List<string> ids = new List<string>();//失败组
  10627. List<string> tids = new List<string>();
  10628. using (WebClient webClient = new WebClient())
  10629. {
  10630. foreach (var url in downloadUrls)
  10631. {
  10632. try
  10633. {
  10634. tids.Add("'" + url + "'");
  10635. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10636. if (entity != null)
  10637. {
  10638. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10639. if (cp == null)
  10640. {
  10641. JObject jsonObject = new JObject
  10642. {
  10643. { "Userid", "77886" },
  10644. { "pwd", "lt666888" },
  10645. { "Filename",entity.seller_memo }
  10646. };
  10647. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10648. JObject jsonObjects = JObject.Parse(response);
  10649. string msg = (string)jsonObjects["msg"];
  10650. if (msg == "报价成功")
  10651. {
  10652. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10653. DownloadAndConvertToBase64(url1);
  10654. }
  10655. else
  10656. {
  10657. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10658. }
  10659. }
  10660. else
  10661. {
  10662. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10663. JObject jsonObject = new JObject
  10664. {
  10665. { "Userid", "77886" },
  10666. { "pwd", "lt666888" },
  10667. { "Filename",chanp }
  10668. };
  10669. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10670. JObject jsonObjects = JObject.Parse(response);
  10671. string msg = (string)jsonObjects["msg"];
  10672. if (msg == "报价成功")
  10673. {
  10674. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10675. DownloadAndConvertToBase64(url1);
  10676. }
  10677. else
  10678. {
  10679. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10680. }
  10681. }
  10682. }
  10683. // 上传文件到FTP
  10684. }
  10685. catch (Exception ex)
  10686. {
  10687. Console.WriteLine($"An error occurred: {ex.Message}");
  10688. }
  10689. }
  10690. List<string> lw = new List<string>();
  10691. lw.Add(string.Format("( OrderState < 6 )"));
  10692. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10693. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10694. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10695. if (dt.Rows.Count > 0)
  10696. {
  10697. foreach (DataRow dr in dt.Rows)
  10698. {
  10699. ids.Add(dr["ctid"].ToString());
  10700. }
  10701. }
  10702. String ErrorMsgs = "";
  10703. foreach (String id in ids)
  10704. {
  10705. ErrorMsgs += id + ",";
  10706. }
  10707. if (ErrorMsgs.Length > 1)
  10708. {
  10709. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10710. }
  10711. if (ErrorMsgs.Length < 1)
  10712. {
  10713. ErrorMsgs = "上传成功";
  10714. returnSuccessMsg(ErrorMsgs);
  10715. }
  10716. else
  10717. {
  10718. returnErrorMsg("以下订单" + ErrorMsgs);
  10719. }
  10720. }
  10721. // 删除文件夹及其内容
  10722. /* Directory.Delete(localDirectory, true);*/
  10723. }
  10724. catch { }
  10725. }
  10726. public void get_center_data()
  10727. {
  10728. int userId = CurrentUser.UserID;
  10729. string postCode = CurrentUser.UserPost.Post.Code;
  10730. List<string> lw = new List<string>();
  10731. List<string> ww = new List<string>();
  10732. DateTime currentTime = DateTime.Now;
  10733. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10734. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10735. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10736. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10737. string sql = " SELECT ";
  10738. string startTime = "2023-10-01 11:22:31";
  10739. //设计
  10740. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10741. {
  10742. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10743. 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));
  10744. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10745. 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));
  10746. }
  10747. //客服
  10748. else if (postCode == "CustomerService" || postCode == "Director")
  10749. {
  10750. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10751. 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));
  10752. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10753. 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));
  10754. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10755. 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));
  10756. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10757. 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));
  10758. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10759. 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));
  10760. }
  10761. //售后
  10762. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10763. {
  10764. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10765. 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));
  10766. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10767. 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));
  10768. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10769. 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));
  10770. }
  10771. //下单部
  10772. else if (postCode == "Place" || postCode == "PlaceMr")
  10773. {
  10774. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10775. 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));
  10776. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10777. 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));
  10778. }
  10779. //车间
  10780. else if (postCode == "Supplier")
  10781. {
  10782. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10783. 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));
  10784. }
  10785. DataTable dt = new DataTable();
  10786. if (lw.Count > 0)
  10787. {
  10788. sql += string.Join(" , ", lw);
  10789. sql += " FROM ";
  10790. sql += string.Join(" , ", ww);
  10791. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10792. }
  10793. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10794. }
  10795. public void get_center_data_list()
  10796. {
  10797. int userId = CurrentUser.UserID;
  10798. string postCode = CurrentUser.UserPost.Post.Code;
  10799. string shopIds = CurrentUser.User.pemShop;
  10800. DataStruct dStruct = GetPostStruct();
  10801. List<string> lw = new List<string>();
  10802. DateTime currentTime = DateTime.Now;
  10803. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10804. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10805. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10806. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10807. string startTime = "2023-10-01 11:22:31";
  10808. int order_type = GetPostInt("order_type");
  10809. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10810. {
  10811. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10812. if (order_type == 0)
  10813. {
  10814. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10815. }
  10816. else if (order_type == 3)
  10817. {
  10818. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10819. }
  10820. else
  10821. {
  10822. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10823. }
  10824. }
  10825. //客服
  10826. if (postCode == "CustomerService" || postCode == "Director")
  10827. {
  10828. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10829. if (order_type == 0)
  10830. {
  10831. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10832. }
  10833. else if (order_type == 1)
  10834. {
  10835. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10836. }
  10837. else if (order_type == 2)
  10838. {
  10839. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10840. }
  10841. else if (order_type == 3)
  10842. {
  10843. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10844. }
  10845. else if (order_type == 4)
  10846. {
  10847. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10848. }
  10849. else
  10850. {
  10851. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10852. }
  10853. }
  10854. //售后
  10855. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10856. {
  10857. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10858. if (shopIds != "")
  10859. {
  10860. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10861. }
  10862. if (order_type == 2)
  10863. {
  10864. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10865. }
  10866. else if (order_type == 4)
  10867. {
  10868. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10869. }
  10870. else if (order_type == 5)
  10871. {
  10872. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10873. }
  10874. else
  10875. {
  10876. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10877. }
  10878. }
  10879. //下单部
  10880. if (postCode == "Place" || postCode == "PlaceMr")
  10881. {
  10882. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10883. if (shopIds != "")
  10884. {
  10885. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10886. }
  10887. else if (order_type == 1)
  10888. {
  10889. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10890. }
  10891. else if (order_type == 2)
  10892. {
  10893. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10894. }
  10895. else
  10896. {
  10897. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10898. }
  10899. }
  10900. //车间
  10901. if (postCode == "Supplier")
  10902. {
  10903. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10904. if (order_type == 5)
  10905. {
  10906. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10907. }
  10908. else
  10909. {
  10910. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10911. }
  10912. }
  10913. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10914. dStruct.Fileds = "tid,ctid";
  10915. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10916. writeGridDataTableJson(dStruct.TotalCount, dt);
  10917. }
  10918. public void aftersale_audit_master()
  10919. {
  10920. if (UrlPostParmsCheck("ctid"))
  10921. {
  10922. string ctid = GetPostString("ctid");
  10923. if (ctid.Length > 0)
  10924. {
  10925. bool result = aftersale_data_change(ctid);
  10926. if (result)
  10927. {
  10928. returnSuccessMsg("修改成功!");
  10929. return;
  10930. }
  10931. }
  10932. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10933. }
  10934. }
  10935. public void aftersale_batch_audit_master()
  10936. {
  10937. if (UrlPostParmsCheck("ctids"))
  10938. {
  10939. string ctids = GetPostString("ctids");
  10940. if (ctids.Length > 0)
  10941. {
  10942. List<string> list = new List<string>();
  10943. string[] ctid_list = ctids.Split(',');
  10944. foreach (var item in ctid_list)
  10945. {
  10946. bool result = aftersale_data_change(item);
  10947. if (!result)
  10948. {
  10949. list.Add(item);
  10950. }
  10951. }
  10952. if (list.Count > 0)
  10953. {
  10954. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10955. return;
  10956. }
  10957. returnSuccessMsg("修改成功!");
  10958. return;
  10959. }
  10960. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10961. }
  10962. }
  10963. public bool aftersale_data_change(string ctid)
  10964. {
  10965. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10966. if (ceErpTradeCell != null)
  10967. {
  10968. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10969. ceErpTradeCell.AfterSaleSupplierState = 0;
  10970. StringBuilder sql = new StringBuilder();
  10971. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10972. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10973. CeErpTradeResponsible.DelByTid(ctid, 0);
  10974. 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 == "不理赔")
  10975. {
  10976. CeErpTradeResponsible.DelByTid(ctid, 1);
  10977. ceErpTradeCell.AfterSaleSupplierState = 1;
  10978. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10979. ceErpTradeCell.AfterSaleState = 4;
  10980. }
  10981. else
  10982. {
  10983. ceErpTradeCell.AfterSaleState = 3;
  10984. }
  10985. bool needCyt = false;
  10986. if (dt != null)
  10987. {
  10988. if (dt.Rows.Count == 1)
  10989. {
  10990. bool isEnd = false;
  10991. foreach (DataRow dr in dt.Rows)
  10992. {
  10993. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10994. {
  10995. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10996. isEnd = true;
  10997. }
  10998. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10999. {
  11000. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11001. isEnd = true;
  11002. }
  11003. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11004. {
  11005. needCyt = true;
  11006. }
  11007. }
  11008. if (isEnd)
  11009. {
  11010. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11011. ceErpTradeCell.AfterSaleState = 4;
  11012. ceErpTradeCell.AfterSaleSupplierState = 1;
  11013. }
  11014. }
  11015. else
  11016. {
  11017. bool isAll = true;
  11018. foreach (DataRow dr in dt.Rows)
  11019. {
  11020. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11021. {
  11022. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11023. continue;
  11024. }
  11025. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  11026. {
  11027. string path = "";
  11028. int OrgID = 0;
  11029. if (!Convert.IsDBNull(dr["OrgPath"]))
  11030. {
  11031. path = dr["OrgPath"].ToString();
  11032. }
  11033. if (!Convert.IsDBNull(dr["OrgID"]))
  11034. {
  11035. OrgID = Convert.ToInt32(dr["OrgID"]);
  11036. }
  11037. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  11038. {
  11039. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11040. continue;
  11041. }
  11042. }
  11043. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11044. {
  11045. needCyt = true;
  11046. }
  11047. isAll = false;
  11048. }
  11049. if (isAll)
  11050. {
  11051. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11052. ceErpTradeCell.AfterSaleState = 4;
  11053. ceErpTradeCell.AfterSaleSupplierState = 1;
  11054. }
  11055. }
  11056. }
  11057. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  11058. {
  11059. commonHelper.sendCytAfterSale(ceErpTradeCell);
  11060. }
  11061. if (ceErpTradeCell.AfterSaleState == 4)
  11062. {
  11063. ApiVo apiVo = new ApiVo();
  11064. apiVo.orderNumber = ceErpTradeCell.ctid;
  11065. apiVo.actionName = "afterOver";
  11066. designHelper.API_WorkCore(apiVo); //afterOver
  11067. }
  11068. ceErpTradeCell.Update();
  11069. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  11070. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  11071. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  11072. return true;
  11073. }
  11074. return false;
  11075. }
  11076. public void get_erp_wechatorder()
  11077. {
  11078. DataStruct dStruct = GetPostStruct();
  11079. List<string> lw = new List<string>();
  11080. string tid = GetPostString("tid");
  11081. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11082. string shopname = GetPostString("shopname");
  11083. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11084. string buyernick = GetPostString("buyer_nick");
  11085. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11086. string customer = GetPostString("customer");
  11087. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11088. string returndate1 = GetPostString("returndate1");
  11089. string returndate2 = GetPostString("returndate2");
  11090. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11091. if (dw.Length > 0) lw.Add(dw);
  11092. string finishDate1 = GetPostString("finishdate1");
  11093. string finishDate2 = GetPostString("finishdate2");
  11094. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11095. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11096. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11097. dStruct.Order = "created desc";
  11098. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11099. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  11100. writeGridDataTableJson(dStruct.TotalCount, dt);
  11101. }
  11102. public void get_erp_wechatlist_sumprice()
  11103. {
  11104. DataStruct dStruct = GetPostStruct();
  11105. List<string> lw = new List<string>();
  11106. string tid = GetPostString("tid");
  11107. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11108. string shopname = GetPostString("shopname");
  11109. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11110. string buyernick = GetPostString("buyer_nick");
  11111. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11112. string customer = GetPostString("customer");
  11113. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11114. string returndate1 = GetPostString("returndate1");
  11115. string returndate2 = GetPostString("returndate2");
  11116. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11117. if (dw.Length > 0) lw.Add(dw);
  11118. string finishDate1 = GetPostString("finishdate1");
  11119. string finishDate2 = GetPostString("finishdate2");
  11120. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11121. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11122. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11123. string mainWhere = string.Join(" and ", lw.ToArray());
  11124. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  11125. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  11126. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  11127. decimal total = 0;
  11128. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  11129. {
  11130. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  11131. }
  11132. var res = new
  11133. {
  11134. data = total
  11135. };
  11136. string ro_jsond = JsonConvert.SerializeObject(res);
  11137. returnSuccess(ro_jsond);
  11138. return;
  11139. }
  11140. public void get_erp_qr_waitdeliverylist()
  11141. {
  11142. DataStruct dStruct = GetPostStruct();
  11143. List<string> lw = new List<string>();
  11144. string tid = GetPostString("ctid");
  11145. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  11146. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11147. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  11148. var res_objz = new
  11149. {
  11150. restype = 1,
  11151. data = dt
  11152. };
  11153. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  11154. returnSuccess(ro_jsonz);
  11155. }
  11156. public void get_erp_yield_list()
  11157. {
  11158. DataStruct dStruct = GetPostStruct();
  11159. List<string> lw = new List<string>();
  11160. string tid = GetPostString("ctid");
  11161. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11162. string shopname = GetPostString("shopname");
  11163. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11164. string buyernick = GetPostString("buyer_nick");
  11165. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11166. //if (tid.Length == 0 && buyernick.Length == 0)
  11167. //{
  11168. // lw.Add(string.Format("IsRefund<={0}", 1));
  11169. //}
  11170. string customer = GetPostString("customer");
  11171. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11172. string design = GetPostString("design");
  11173. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11174. string orderState = GetPostString("orderState");
  11175. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11176. string address = GetPostString("address");
  11177. 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));
  11178. string sellermemo = GetPostString("seller_memo");
  11179. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11180. string supplier = GetPostString("supplier");
  11181. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11182. string OrderArea = GetPostString("order_area");
  11183. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11184. string placedate1 = GetPostString("placedate1");
  11185. string placedate2 = GetPostString("placedate2");
  11186. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11187. if (fdw.Length > 0) lw.Add(fdw);
  11188. string price1 = GetPostString("price1");
  11189. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11190. string price2 = GetPostString("price2");
  11191. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11192. string unusualCon = GetPostString("unusualcon");
  11193. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11194. string posTag = CurrentUser.UserPost.Post.Code;
  11195. if (posTag == "Supplier")
  11196. {
  11197. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11198. }
  11199. lw.Add(string.Format("OrderState = 6 "));
  11200. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11201. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11202. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11203. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11204. writeGridDataTableJson(dStruct.TotalCount, dt);
  11205. }
  11206. public void change_erp_sup_state()
  11207. {
  11208. if (UrlPostParmsCheck("ctid"))
  11209. {
  11210. string ctid = GetPostString("ctid");
  11211. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11212. if (ceErpTradeCell != null)
  11213. {
  11214. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11215. if (ceErpTradeCellExtend == null)
  11216. {
  11217. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11218. ceErpTradeCellExtend.ctid = ctid;
  11219. ceErpTradeCellExtend.SupState = 1;
  11220. ceErpTradeCellExtend.Create();
  11221. }
  11222. else
  11223. {
  11224. ceErpTradeCellExtend.SupState = 1;
  11225. ceErpTradeCellExtend.Update();
  11226. }
  11227. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11228. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11229. return;
  11230. }
  11231. returnErrorMsg("找不到订单");
  11232. }
  11233. }
  11234. public void supplier_all_downs()
  11235. {
  11236. if (UrlPostParmsCheck("tids"))
  11237. {
  11238. string tids = GetPostString("tids");
  11239. if (tids != null && tids.Length > 0)
  11240. {
  11241. StringBuilder sql = new StringBuilder();
  11242. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11243. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11244. sql = new StringBuilder();
  11245. 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, "下载设计文件");
  11246. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11247. string[] list = tids.Split(',');
  11248. foreach (string ctid in list)
  11249. {
  11250. CeErpSukuraData.createInfo(ctid, 3);
  11251. }
  11252. designHelper.api_approveDesign(tids); //approveDesign
  11253. returnSuccessMsg("下载成功!");
  11254. return;
  11255. }
  11256. returnErrorMsg("下载订单更新失败");
  11257. }
  11258. }
  11259. public void uploaderFileSuccess()
  11260. {
  11261. if (UrlPostParmsCheck("fileName"))
  11262. {
  11263. string fileName = GetPostString("fileName");
  11264. ApiVo apiVo = new ApiVo();
  11265. apiVo.orderNumber = fileName;
  11266. apiVo.actionName = "finishDesign";
  11267. designHelper.API_WorkCore(apiVo);//finishDesign
  11268. returnSuccessMsg("");
  11269. }
  11270. }
  11271. public void get_sample2_order()
  11272. {
  11273. if (UrlPostParmsCheck("ctid"))
  11274. {
  11275. string ctid = GetPostString("ctid");
  11276. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11277. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11278. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11279. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11280. double total = 0.0;
  11281. double order_price = 0.0;
  11282. if (dt_bu.Rows.Count > 0)
  11283. {
  11284. foreach (DataRow dr in dt_bu.Rows)
  11285. {
  11286. total += Convert.ToDouble(dr["payment"]);
  11287. }
  11288. }
  11289. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11290. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11291. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11292. string tid = ctid.Replace("S_", "");
  11293. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11294. double paymant = 0.0;
  11295. if (entity != null)
  11296. {
  11297. paymant = entity.payment;
  11298. }
  11299. string return_reason = "";
  11300. if (dt_after != null && dt_after.Rows.Count > 0)
  11301. {
  11302. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11303. }
  11304. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11305. }
  11306. }
  11307. public void get_erp_design_status()
  11308. {
  11309. string designName = GetPostString("designName");
  11310. DataStruct dStruct = GetPostStruct();
  11311. if (designName.Length > 0)
  11312. {
  11313. 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";
  11314. sql_user += " and Name like '%" + designName + "%'";
  11315. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11316. List<string> ids_list = new List<string>();
  11317. if (user_table.Rows.Count > 0)
  11318. {
  11319. foreach (DataRow item in user_table.Rows)
  11320. {
  11321. ids_list.Add(item["id"].ToString());
  11322. string ids_s = item["TeamIds"].ToString();
  11323. if (ids_s.Length > 0)
  11324. {
  11325. ids_list.AddRange(ids_s.Split(','));
  11326. }
  11327. }
  11328. }
  11329. HashSet<string> set = new HashSet<string>(ids_list);
  11330. ids_list = set.ToList();
  11331. if (ids_list.Count > 0)
  11332. {
  11333. 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));
  11334. dStruct.MainWhere = sql;
  11335. DataTable dt = null;
  11336. dt = WebCache.GetData("view_ErpUser", dStruct);
  11337. writeGridDataTableJson(dStruct.TotalCount, dt);
  11338. }
  11339. }
  11340. }
  11341. public void change_erp_order_price()
  11342. {
  11343. string ctid = GetPostString("ctid");
  11344. double price = GetPostDouble("price");
  11345. if (ctid.Length > 0)
  11346. {
  11347. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11348. if (ceErpTradeCellExtend == null)
  11349. {
  11350. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11351. ceErpTradeCellExtend.ctid = ctid;
  11352. ceErpTradeCellExtend.payment_cyt = price;
  11353. ceErpTradeCellExtend.Create();
  11354. }
  11355. else
  11356. {
  11357. ceErpTradeCellExtend.payment_cyt = price;
  11358. ceErpTradeCellExtend.Update();
  11359. }
  11360. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11361. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11362. {
  11363. ceErpDataSendOrderInfo.isSync = false;
  11364. ceErpDataSendOrderInfo.Update();
  11365. }
  11366. if (ceErpDataSendOrderInfo == null)
  11367. {
  11368. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11369. ceErpDataSendOrderInfo.isSync = false;
  11370. ceErpDataSendOrderInfo.ctid = ctid;
  11371. ceErpDataSendOrderInfo.Create();
  11372. }
  11373. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11374. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11375. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11376. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11377. {
  11378. dataSendOrderBean dataSendOrderBean = null;
  11379. foreach (DataRow item in dth.Rows)
  11380. {
  11381. try
  11382. {
  11383. dataSendOrderBean = new dataSendOrderBean();
  11384. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11385. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11386. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11387. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11388. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11389. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11390. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11391. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11392. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11393. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11394. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11395. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11396. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11397. if (result != null)
  11398. {
  11399. if ("0".Equals(result.errcode))
  11400. {
  11401. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11402. }
  11403. else
  11404. {
  11405. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11406. }
  11407. }
  11408. }
  11409. catch (Exception ex)
  11410. {
  11411. }
  11412. }
  11413. }
  11414. returnSuccessMsg("修改成功!");
  11415. return;
  11416. }
  11417. returnErrorMsg("找不到订单");
  11418. }
  11419. public void find_he_together()
  11420. {
  11421. string ctid = GetPostString("ctid");
  11422. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11423. List<string> list = new List<string>();
  11424. if (ceErpTradeCell != null)
  11425. {
  11426. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11427. {
  11428. 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);
  11429. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11430. if (table != null && table.Rows.Count > 0)
  11431. {
  11432. foreach (TableRow row in table.Rows)
  11433. {
  11434. }
  11435. }
  11436. }
  11437. }
  11438. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11439. }
  11440. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11441. {
  11442. //chy----19
  11443. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11444. //GD-CYT-----64
  11445. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11446. //ZHX----3
  11447. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11448. //JK----97
  11449. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11450. //ZT----70
  11451. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11452. //GD-CYTUV---126
  11453. {126, new Dictionary<string, string> {{"uv", "uv"}}},
  11454. //LHCY-----98
  11455. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11456. //XD-----90
  11457. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11458. //CYCY-----14
  11459. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}},
  11460. //THLZY----122
  11461. {122, new Dictionary<string, string> {{ "烫画", "烫画" }, { "冷转印", "冷转印" }}}
  11462. };
  11463. //其他改名
  11464. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11465. {
  11466. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11467. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11468. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11469. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11470. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11471. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11472. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11473. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11474. };
  11475. //不统计
  11476. List<int> no_suppliers = new List<int>()
  11477. {
  11478. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11479. };
  11480. //配件单
  11481. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11482. {
  11483. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11484. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11485. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11486. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11487. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11488. {"旗杆",new List<string>(){ "班旗" } },
  11489. {"牙签",new List<string>(){ "不干胶" } }
  11490. };
  11491. public void get_place_order_data()
  11492. {
  11493. string date1 = GetPostString("date1");
  11494. string date2 = GetPostString("date2");
  11495. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11496. DateTime start = DateTime.Parse(starttime);
  11497. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11498. DateTime end = DateTime.Parse(endtime);
  11499. if (date1 != null && date1.Length > 0)
  11500. {
  11501. DateTime dateTime = DateTime.Parse(date1);
  11502. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11503. start = DateTime.Parse(starttime);
  11504. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11505. end = DateTime.Parse(endtime);
  11506. }
  11507. if (date2 != null && date2.Length > 0)
  11508. {
  11509. DateTime dateTime = DateTime.Parse(date2);
  11510. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11511. end = DateTime.Parse(endtime);
  11512. }
  11513. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,UnusualTime,FinishPlaceTime,OrderState,FinishDeliveryTime from view_ErpTradeCell where ( ( FinishPlaceTime BETWEEN '{0}' AND '{1}' ) OR ( OrderState = 6 AND UnusualTag = 5 AND IsRefund <= 1 ) ) AND IsSample = 0 and SupplierName is not null ", starttime, endtime);
  11514. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11515. //不干胶-----1,卡片-----29
  11516. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11517. foreach (DataRow row in data.Rows)
  11518. {
  11519. int productId = Convert.ToInt32(row["ProductId"]);
  11520. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11521. if (no_suppliers.Contains(supplierId))
  11522. {
  11523. continue;
  11524. }
  11525. string seller_memo = row["seller_memo"].ToString();
  11526. bool ispj = false;//是否配件单
  11527. bool isfirst = true;//第一个配
  11528. maps.Keys.ForEach(key =>
  11529. {
  11530. //备注包含配件
  11531. if (seller_memo.Contains(key) && isfirst)
  11532. {
  11533. List<string> list = maps[key];
  11534. ispj = true;
  11535. isfirst = false;
  11536. for (int i = 0; i < list.Count; i++)
  11537. {
  11538. if (seller_memo.Contains(list[i]))
  11539. {
  11540. ispj = false;
  11541. break;
  11542. }
  11543. }
  11544. }
  11545. });
  11546. if (ispj)
  11547. {
  11548. continue;
  11549. }
  11550. seller_memo = seller_memo.Replace("UV", "uv");
  11551. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11552. //吊牌归到卡片
  11553. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11554. seller_memo = seller_memo.Replace("卡套", "卡片");
  11555. seller_memo = seller_memo.Replace("封套", "卡片");
  11556. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11557. seller_memo = seller_memo.Replace("腰封", "卡片");
  11558. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11559. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11560. seller_memo = seller_memo.Replace("横幅", "条幅");
  11561. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11562. string map_key = "";
  11563. string type = "";
  11564. if (supplierMap.ContainsKey(supplierId))
  11565. {
  11566. foreach (var kvp in supplierMap[supplierId])
  11567. {
  11568. if (seller_memo.Contains(kvp.Key))
  11569. {
  11570. map_key = kvp.Value;
  11571. type = kvp.Value;
  11572. break;
  11573. }
  11574. }
  11575. }
  11576. if (map_key == "")
  11577. {
  11578. type = "其他";
  11579. map_key = "其他";
  11580. }
  11581. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11582. {
  11583. map_key = suppliers[supplierId];
  11584. }
  11585. if (supplierId == 70)
  11586. {
  11587. supplierId = 70;
  11588. }
  11589. map_key += "_" + row["SupplierName"].ToString();
  11590. Dictionary<string, int> map = null;
  11591. if (other_map.ContainsKey(map_key))
  11592. {
  11593. other_map.TryGetValue(map_key, out map);
  11594. }
  11595. else
  11596. {
  11597. map = new Dictionary<string, int>();
  11598. map.Add("dayDev", 0);//当天出货
  11599. map.Add("dayTotal", 0);//下单总数
  11600. map.Add("payTotal", 0);//500以上
  11601. map.Add("today", 0);//当天出货数量
  11602. map.Add("unusua", 0);//异常数
  11603. other_map.Add(map_key, map);
  11604. other_map.TryGetValue(map_key, out map);
  11605. }
  11606. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11607. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11608. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11609. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11610. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11611. {
  11612. map["dayTotal"]++;
  11613. if (supplierId == 97)
  11614. {
  11615. supplierId = 97;
  11616. }
  11617. }
  11618. if (Convert.ToDecimal(row["payment"]) >= 500)
  11619. {
  11620. map["payTotal"]++;
  11621. }
  11622. bool istoday = false;
  11623. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11624. {
  11625. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11626. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11627. {
  11628. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11629. {
  11630. map["today"]++;
  11631. }
  11632. }
  11633. else
  11634. {
  11635. if (supplierId == 80)
  11636. {
  11637. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11638. {
  11639. map["today"]++;
  11640. }
  11641. }
  11642. else if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11643. {
  11644. map["today"]++;
  11645. istoday = true;
  11646. }
  11647. }
  11648. }
  11649. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11650. {
  11651. map["unusua"]++;
  11652. }
  11653. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11654. //GD-CYT-----64
  11655. DateTime two = palceTimeStart.AddHours(14);
  11656. DateTime three = palceTimeStart.AddHours(15);
  11657. DateTime four = palceTimeStart.AddHours(16);
  11658. DateTime six = palceTimeStart.AddHours(18);
  11659. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11660. {
  11661. //下午四点前 500-1000
  11662. string count = row["ProductCount"].ToString();
  11663. if (count != null && count.Length > 0)
  11664. {
  11665. int productCount = commonHelper.getPlaceProductCount(count);
  11666. if (productCount >= 500 && productCount <= 1000)
  11667. {
  11668. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11669. {
  11670. map["dayDev"]++;
  11671. }
  11672. }
  11673. }
  11674. }
  11675. //UV
  11676. else if ("uv".Equals(type))
  11677. {
  11678. //ZT----70
  11679. //ZHX----3
  11680. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11681. {
  11682. map["dayDev"]++;
  11683. }
  11684. //JK----97
  11685. //HZX----105
  11686. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11687. {
  11688. map["dayDev"]++;
  11689. }
  11690. if (DateTime.Compare(FinishPlaceTime, six) < 0 && (supplierId == 126))
  11691. {
  11692. map["dayDev"]++;
  11693. }
  11694. }
  11695. //帆布---52|条幅---27
  11696. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11697. {
  11698. //LHCY-----98
  11699. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11700. {
  11701. map["dayDev"]++;
  11702. }
  11703. }
  11704. //条幅
  11705. else if ("条幅".Equals(type))
  11706. {
  11707. //XD-----90
  11708. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11709. {
  11710. map["dayDev"]++;
  11711. }
  11712. }
  11713. //桌布
  11714. else if ("桌布".Equals(type))
  11715. {
  11716. //XD-----90
  11717. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11718. {
  11719. map["dayDev"]++;
  11720. }
  11721. }
  11722. //DL---10
  11723. //AYTW---119
  11724. //FS-CYT-DY ----80
  11725. //JK----97
  11726. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11727. {
  11728. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11729. {
  11730. map["dayDev"]++;
  11731. if (supplierId == 80 && istoday)
  11732. {
  11733. Debug.WriteLine(seller_memo);
  11734. }
  11735. }
  11736. }
  11737. // QC---121
  11738. else if (supplierId == 121)
  11739. {
  11740. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11741. {
  11742. map["dayDev"]++;
  11743. }
  11744. }
  11745. }
  11746. DataTable dt = new DataTable();
  11747. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11748. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11749. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11750. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11751. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11752. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11753. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11754. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11755. other_map.Keys.ForEach(key =>
  11756. {
  11757. DataRow dr = dt.NewRow();
  11758. Dictionary<string, int> map = other_map[key];
  11759. string[] key_list = key.Split('_');
  11760. dr[0] = key_list[0];
  11761. dr[1] = key_list[1];
  11762. if (key_list.Length > 2)
  11763. {
  11764. dr[1] += "(" + key_list[2] + ")";
  11765. }
  11766. dr[2] = map["dayTotal"];
  11767. dr[3] = map["payTotal"];
  11768. dr[4] = map["today"];
  11769. dr[5] = map["unusua"];
  11770. dr[6] = map["dayDev"];
  11771. double rate = 0.00;
  11772. if (map["dayDev"] > 0)
  11773. {
  11774. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11775. }
  11776. dr[7] = rate.ToString();
  11777. dt.Rows.Add(dr);
  11778. });
  11779. DataView dv = new DataView(dt);
  11780. dv.Sort = "SupplierName";
  11781. //dv.Sort = "AllOrder desc";
  11782. DataTable dtNew = dv.ToTable();
  11783. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11784. }
  11785. public void check_order_desing_info()
  11786. {
  11787. string ctid = GetPostString("ctid");
  11788. if (!string.IsNullOrEmpty(ctid))
  11789. {
  11790. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11791. if (ceErpTradeCell != null)
  11792. {
  11793. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11794. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11795. return;
  11796. }
  11797. returnErrorMsg("找不到订单");
  11798. return;
  11799. }
  11800. returnErrorMsg("找不到订单");
  11801. }
  11802. public void get_timeout_detail()
  11803. {
  11804. string poscode = CurrentUser.UserPost.Post.Code;
  11805. DataStruct dStruct = GetPostStruct();
  11806. List<string> lw = new List<string>();
  11807. string id = GetPostString("id");
  11808. string pay_date1 = GetPostString("pay_date1");
  11809. string pay_date2 = GetPostString("pay_date2");
  11810. int type = GetPostInt("type");
  11811. if (type == 0)
  11812. {
  11813. if (pay_date1.Length > 0)
  11814. {
  11815. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11816. }
  11817. if (pay_date2.Length > 0)
  11818. {
  11819. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11820. }
  11821. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11822. }
  11823. if (type == 1)
  11824. {
  11825. if (pay_date1.Length > 0)
  11826. {
  11827. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11828. }
  11829. if (pay_date2.Length > 0)
  11830. {
  11831. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11832. }
  11833. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11834. }
  11835. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11836. DataTable dt = null;
  11837. dt = WebCache.GetData("view_orderlist", dStruct);
  11838. writeGridDataTableJson(dStruct.TotalCount, dt);
  11839. }
  11840. public void saveUrgentChargePrice()
  11841. {
  11842. string ctid = GetPostString("ctid");
  11843. if (!string.IsNullOrEmpty(ctid))
  11844. {
  11845. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11846. if (ceErpTradeCell != null)
  11847. {
  11848. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11849. if (prices <= 100)
  11850. {
  11851. returnErrorMsg("此订单金额不足100元,无法加急。");
  11852. return;
  11853. }
  11854. double price = GetPostDouble("price");
  11855. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11856. if (ceErpTradeCellExtend == null)
  11857. {
  11858. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11859. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11860. }
  11861. ceErpTradeCellExtend.urgentCharge = price;
  11862. if (ceErpTradeCellExtend.ID > 0)
  11863. {
  11864. ceErpTradeCellExtend.Update();
  11865. }
  11866. else
  11867. {
  11868. ceErpTradeCellExtend.Save();
  11869. }
  11870. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11871. returnSuccessMsg("修改成功!");
  11872. return;
  11873. }
  11874. returnErrorMsg("找不到订单");
  11875. return;
  11876. }
  11877. returnErrorMsg("找不到订单");
  11878. }
  11879. public void finish_erp_order()
  11880. {
  11881. string ctid = GetPostString("ctid");
  11882. if (!string.IsNullOrEmpty(ctid))
  11883. {
  11884. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11885. {
  11886. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11887. if (ceErpTradeCell != null)
  11888. {
  11889. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11890. ceErpTradeCell.Update();
  11891. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11892. returnSuccessMsg("修改成功!");
  11893. return;
  11894. }
  11895. }
  11896. }
  11897. returnErrorMsg("找不到订单");
  11898. }
  11899. public void get_trade_order_list()
  11900. {
  11901. string tid = GetPostString("tid");
  11902. if (!string.IsNullOrEmpty(tid))
  11903. {
  11904. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11905. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11906. writeGridDataTableJson(data.Rows.Count, data);
  11907. return;
  11908. }
  11909. returnErrorMsg("找不到订单");
  11910. }
  11911. public void save_cell_spu()
  11912. {
  11913. string ctid = GetPostString("ctid");
  11914. string spu_id = GetPostString("spu_id");
  11915. if (!string.IsNullOrEmpty(ctid))
  11916. {
  11917. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11918. if (ceErpTradeCellExtend == null)
  11919. {
  11920. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11921. ceErpTradeCellExtend.ctid = ctid;
  11922. }
  11923. ceErpTradeCellExtend.spu_id = spu_id;
  11924. if (!string.IsNullOrEmpty(spu_id))
  11925. {
  11926. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11927. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  11928. }
  11929. if (ceErpTradeCellExtend.ID == 0)
  11930. {
  11931. ceErpTradeCellExtend.Create();
  11932. }
  11933. else
  11934. {
  11935. ceErpTradeCellExtend.Update();
  11936. }
  11937. returnSuccessMsg("修改成功!");
  11938. return;
  11939. }
  11940. returnErrorMsg("找不到订单");
  11941. }
  11942. public void change_express_info()
  11943. {
  11944. string ctid = GetPostString("ctid");
  11945. string transNo = GetPostString("transNo");
  11946. string transCom = GetPostString("transCom");
  11947. if (!string.IsNullOrEmpty(ctid))
  11948. {
  11949. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11950. if (ceErpTradeCellExtend == null)
  11951. {
  11952. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11953. ceErpTradeCellExtend.ctid = ctid;
  11954. }
  11955. ceErpTradeCellExtend.modExpressNo = transNo;
  11956. ceErpTradeCellExtend.modExpressCom = transCom;
  11957. ceErpTradeCellExtend.readMod = 2;
  11958. if (ceErpTradeCellExtend.ID == 0)
  11959. {
  11960. ceErpTradeCellExtend.Create();
  11961. }
  11962. else
  11963. {
  11964. ceErpTradeCellExtend.Update();
  11965. }
  11966. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11967. returnSuccessMsg("修改成功!");
  11968. return;
  11969. }
  11970. returnErrorMsg("找不到订单");
  11971. }
  11972. public void get_change_express_list()
  11973. {
  11974. DataStruct dStruct = GetPostStruct();
  11975. List<string> lw = new List<string>();
  11976. int st = 2;
  11977. string tid = GetPostString("ctid");
  11978. if (tid.Length > 0)
  11979. {
  11980. string select_tid = getTidByCtid(tid);
  11981. lw.Add(string.Format("tid='{0}'", select_tid));
  11982. }
  11983. string shopname = GetPostString("shopname");
  11984. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11985. string buyernick = GetPostString("buyer_nick");
  11986. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11987. string sellermemo = GetPostString("seller_memo");
  11988. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11989. string supplier = GetPostString("supplier");
  11990. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11991. string customer = GetPostString("customer");
  11992. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11993. string design = GetPostString("design");
  11994. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11995. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11996. string poscode = CurrentUser.UserPost.Post.Code;
  11997. if (poscode != "SysAdmin")
  11998. {
  11999. string shopid = CurrentUser.User.pemShop;
  12000. lw.Add(string.Format("shopId in ({0})", shopid));
  12001. }
  12002. lw.Add("readMod = 2");
  12003. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12004. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  12005. writeGridDataTableJson(dStruct.TotalCount, dt);
  12006. }
  12007. public void deal_express_complete()
  12008. {
  12009. string ctid = GetPostString("ctid");
  12010. if (!string.IsNullOrEmpty(ctid))
  12011. {
  12012. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12013. if (ceErpTradeCellExtend == null)
  12014. {
  12015. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12016. ceErpTradeCellExtend.ctid = ctid;
  12017. }
  12018. ceErpTradeCellExtend.readMod = 1;
  12019. if (ceErpTradeCellExtend.ID == 0)
  12020. {
  12021. ceErpTradeCellExtend.Create();
  12022. }
  12023. else
  12024. {
  12025. ceErpTradeCellExtend.Update();
  12026. }
  12027. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  12028. returnSuccessMsg("修改成功!");
  12029. return;
  12030. }
  12031. returnErrorMsg("找不到订单");
  12032. }
  12033. public void aftersale_return_visit()
  12034. {
  12035. string ctid = GetPostString("ctid");
  12036. if (!string.IsNullOrEmpty(ctid))
  12037. {
  12038. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12039. if (ceErpTradeCellExtend == null)
  12040. {
  12041. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12042. ceErpTradeCellExtend.ctid = ctid;
  12043. }
  12044. ceErpTradeCellExtend.returnVisit = 1;
  12045. if (ceErpTradeCellExtend.ID == 0)
  12046. {
  12047. ceErpTradeCellExtend.Create();
  12048. }
  12049. else
  12050. {
  12051. ceErpTradeCellExtend.Update();
  12052. }
  12053. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12054. if (ceErpTradeAfterSaleExtend != null)
  12055. {
  12056. ceErpTradeAfterSaleExtend.TextResult = "";
  12057. ceErpTradeAfterSaleExtend.Update();
  12058. }
  12059. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  12060. returnSuccessMsg("修改成功!");
  12061. return;
  12062. }
  12063. returnErrorMsg("找不到订单");
  12064. }
  12065. public void orderPlaceInfo()
  12066. {
  12067. string ctids = GetPostString("ctids");
  12068. string[] list = ctids.Split(',');
  12069. foreach (string ctid in list)
  12070. {
  12071. CeErpSukuraData.createInfo(ctid, 3);
  12072. }
  12073. StringBuilder sql = new StringBuilder();
  12074. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  12075. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  12076. designHelper.api_approveDesign(ctids); //approveDesign
  12077. returnSuccessMsg("");
  12078. }
  12079. public void get_issue_list()
  12080. {
  12081. DataStruct dStruct = GetPostStruct();
  12082. List<string> lw = new List<string>();
  12083. int st = 2;
  12084. string tid = GetPostString("ctid");
  12085. if (tid.Length > 0)
  12086. {
  12087. string select_tid = getTidByCtid(tid);
  12088. lw.Add(string.Format("tid='{0}'", select_tid));
  12089. }
  12090. string shopname = GetPostString("shopname");
  12091. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12092. string buyernick = GetPostString("buyer_nick");
  12093. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12094. string sellermemo = GetPostString("seller_memo");
  12095. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12096. string supplier = GetPostString("supplier");
  12097. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12098. string customer = GetPostString("customer");
  12099. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12100. string design = GetPostString("design");
  12101. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12102. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12103. string poscode = CurrentUser.UserPost.Post.Code;
  12104. if (poscode != "SysAdmin")
  12105. {
  12106. string shopid = CurrentUser.User.pemShop;
  12107. lw.Add(string.Format("shopId in ({0})", shopid));
  12108. }
  12109. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  12110. {
  12111. lw.Add("IssueState = 1");
  12112. }
  12113. else
  12114. {
  12115. string iisstate = GetPostString("iisstate");
  12116. if ("1".Equals(iisstate))
  12117. {
  12118. lw.Add("IssueState =1");
  12119. }
  12120. else if ("2".Equals(iisstate))
  12121. {
  12122. lw.Add("IssueState = 2");
  12123. }
  12124. else
  12125. {
  12126. lw.Add("IssueState > 0");
  12127. }
  12128. }
  12129. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12130. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  12131. writeGridDataTableJson(dStruct.TotalCount, dt);
  12132. }
  12133. public void saveIssueContent()
  12134. {
  12135. string ctid = GetPostString("ctid");
  12136. if (!string.IsNullOrEmpty(ctid))
  12137. {
  12138. string content = GetPostString("content");
  12139. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12140. if (ceErpTradeAfterSaleExtend == null)
  12141. {
  12142. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  12143. ceErpTradeAfterSaleExtend.tid = ctid;
  12144. }
  12145. ceErpTradeAfterSaleExtend.IssueContent = content;
  12146. ceErpTradeAfterSaleExtend.IssueState = 1;
  12147. if (ceErpTradeAfterSaleExtend.ID > 0)
  12148. {
  12149. ceErpTradeAfterSaleExtend.Update();
  12150. }
  12151. else
  12152. {
  12153. ceErpTradeAfterSaleExtend.Create();
  12154. }
  12155. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  12156. returnSuccessMsg("添加成功!");
  12157. return;
  12158. }
  12159. returnErrorMsg("找不到订单");
  12160. }
  12161. public void dealIssueContent()
  12162. {
  12163. string ctid = GetPostString("ctid");
  12164. if (!string.IsNullOrEmpty(ctid))
  12165. {
  12166. string content = GetPostString("content");
  12167. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12168. if (ceErpTradeAfterSaleExtend != null)
  12169. {
  12170. ceErpTradeAfterSaleExtend.IssueState = 2;
  12171. ceErpTradeAfterSaleExtend.Update();
  12172. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  12173. returnSuccessMsg("修改完成!");
  12174. return;
  12175. }
  12176. }
  12177. returnErrorMsg("找不到订单");
  12178. }
  12179. public void set_tid_attachments()
  12180. {
  12181. string tid = GetPostString("tid");
  12182. string atta = GetPostString("atta");
  12183. if (!string.IsNullOrEmpty(tid))
  12184. {
  12185. if (string.IsNullOrEmpty(atta))
  12186. {
  12187. returnErrorMsg("文件地址为空");
  12188. return;
  12189. }
  12190. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12191. if (ceErpTradeCell != null)
  12192. {
  12193. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12194. if (ceErpTrade == null)
  12195. {
  12196. returnErrorMsg("找不到订单");
  12197. return;
  12198. }
  12199. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12200. bool isSend = false;
  12201. if (dt != null && dt.Rows.Count > 0)
  12202. {
  12203. foreach (DataRow row in dt.Rows)
  12204. {
  12205. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12206. {
  12207. isSend = true;
  12208. }
  12209. }
  12210. if (isSend)
  12211. {
  12212. returnErrorMsg("已发货无法修改");
  12213. return;
  12214. }
  12215. ceErpTrade.Attachments = atta;
  12216. ceErpTrade.Update();
  12217. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12218. returnSuccessMsg("上传成功!");
  12219. return;
  12220. }
  12221. }
  12222. }
  12223. returnErrorMsg("找不到订单");
  12224. }
  12225. public void get_tid_attachments()
  12226. {
  12227. string tid = GetPostString("tid");
  12228. if (!string.IsNullOrEmpty(tid))
  12229. {
  12230. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12231. if (ceErpTradeCell != null)
  12232. {
  12233. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12234. if (ceErpTrade == null)
  12235. {
  12236. returnErrorMsg("找不到订单");
  12237. return;
  12238. }
  12239. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12240. return;
  12241. }
  12242. }
  12243. returnErrorMsg("找不到订单");
  12244. }
  12245. public void check_erp_sameorders()
  12246. {
  12247. if (UrlPostParmsCheck("ctid"))
  12248. {
  12249. string eid = GetPostString("ctid");
  12250. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12251. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12252. if (entity != null && ceErpTrade != null)
  12253. {
  12254. if (entity.OrderState > 6)
  12255. {
  12256. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12257. return;
  12258. }
  12259. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12260. List<string> ids = new List<string>();
  12261. if (dt != null && dt.Rows.Count > 1)
  12262. {
  12263. bool needhe = true;
  12264. foreach (DataRow dr in dt.Rows)
  12265. {
  12266. ids.Add("'" + dr["ctid"] + "'");
  12267. /* //备注有合包
  12268. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12269. {
  12270. needhe = true;
  12271. }
  12272. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12273. {
  12274. needhe = true;
  12275. }
  12276. //顺丰快递
  12277. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12278. {
  12279. needhe = true;
  12280. }*/
  12281. }
  12282. if (!needhe)
  12283. {
  12284. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12285. return;
  12286. }
  12287. StringBuilder sql = new StringBuilder();
  12288. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12289. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12290. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12291. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12292. foreach (DataRow dr in dt.Rows)
  12293. {
  12294. dr["dstate"] = 0;
  12295. dr["dnumber"] = 0;
  12296. foreach (DataRow row in dt1.Rows)
  12297. {
  12298. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12299. {
  12300. dr["dstate"] = 2;
  12301. dr["default"] = 1;
  12302. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12303. }
  12304. }
  12305. if (eid.Equals(dr["ctid"].ToString()))
  12306. {
  12307. dr["dstate"] = 1;
  12308. dr["default"] = 1;
  12309. }
  12310. }
  12311. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12312. return;
  12313. }
  12314. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12315. return;
  12316. }
  12317. returnErrorMsg("未找到订单");
  12318. return;
  12319. }
  12320. returnErrorMsg("缺少必要的参数");
  12321. }
  12322. public void get_mark_number()
  12323. {
  12324. string eid = GetPostString("ctid");
  12325. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12326. if (entity != null)
  12327. {
  12328. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12329. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12330. int current = 1;
  12331. if (ceErpDeliverMark == null)
  12332. {
  12333. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12334. List<string> ids = new List<string>();
  12335. if (dt != null && dt.Rows.Count > 1)
  12336. {
  12337. foreach (DataRow dr in dt.Rows)
  12338. {
  12339. ids.Add("'" + dr["ctid"] + "'");
  12340. }
  12341. //查询已有的编号
  12342. StringBuilder sql = new StringBuilder();
  12343. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12344. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12345. if (dt1 == null || dt1.Rows.Count == 0)
  12346. {
  12347. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12348. List<int> list_number = new List<int>();
  12349. foreach (DataRow row in numbers.Rows)
  12350. {
  12351. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12352. }
  12353. //查询空余编号
  12354. for (int i = 0; i < list_number.Count + 2; i++)
  12355. {
  12356. if (!list_number.Contains(current))
  12357. {
  12358. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12359. //防止查询过程中有新数据生成
  12360. if (ceErpDeliverMark1 == null)
  12361. {
  12362. break;
  12363. }
  12364. }
  12365. current++;
  12366. }
  12367. }
  12368. else
  12369. {
  12370. foreach (DataRow row in dt1.Rows)
  12371. {
  12372. current = Convert.ToInt32(row["markNumber"]);
  12373. }
  12374. }
  12375. ceErpDeliverMark = new CeErpDeliverMark();
  12376. ceErpDeliverMark.ctid = eid;
  12377. ceErpDeliverMark.createtime = DateTime.Now;
  12378. if (ceErpTrade != null)
  12379. {
  12380. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12381. }
  12382. ceErpDeliverMark.markNumber = current;
  12383. ceErpDeliverMark.Create();
  12384. }
  12385. }
  12386. else
  12387. {
  12388. current = ceErpDeliverMark.markNumber;
  12389. }
  12390. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12391. return;
  12392. }
  12393. }
  12394. public void aftersaleCytSend()
  12395. {
  12396. string ctid = GetPostString("ctid");
  12397. if (!string.IsNullOrEmpty(ctid))
  12398. {
  12399. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12400. if (ceErpTradeCell != null)
  12401. {
  12402. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12403. }
  12404. returnSuccessMsg("推送成功");
  12405. return;
  12406. }
  12407. returnErrorMsg("缺少必要的参数");
  12408. }
  12409. public void packOrderInfo()
  12410. {
  12411. string ctids = GetPostString("ctids");
  12412. if (!string.IsNullOrEmpty(ctids))
  12413. {
  12414. string[] ctid_list = ctids.Split(',');
  12415. if (ctid_list.Length > 20)
  12416. {
  12417. returnErrorMsg("单次下载次数不能超过20个");
  12418. return;
  12419. }
  12420. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12421. StringBuilder sql = new StringBuilder();
  12422. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12423. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12424. int supplierId = 0;
  12425. StringBuilder insterSql = new StringBuilder();
  12426. for (int i = 0; i < dt.Rows.Count; i++)
  12427. {
  12428. DataRow row = dt.Rows[i];
  12429. if (i == 0)
  12430. {
  12431. supplierId = Convert.ToInt32(row["SupplierId"]);
  12432. }
  12433. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12434. {
  12435. returnErrorMsg("同车间的订单才能一起打包");
  12436. return;
  12437. }
  12438. int orderState = Convert.ToInt32(row["OrderState"]);
  12439. if (orderState != 5)
  12440. {
  12441. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12442. return;
  12443. }
  12444. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12445. }
  12446. CeErpPackData ceErpPackData = new CeErpPackData();
  12447. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  12448. ceErpPackData.supplierId = supplierId;
  12449. ceErpPackData.createtime = DateTime.Now;
  12450. ceErpPackData.createBy = CurrentUser.UserID;
  12451. ceErpPackData.createName = CurrentUser.UserName;
  12452. ceErpPackData.Create();
  12453. if (ceErpPackData.ID > 0)
  12454. {
  12455. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12456. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12457. }
  12458. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12459. returnSuccessMsg("打包成功");
  12460. return;
  12461. }
  12462. returnErrorMsg("缺少必要的参数");
  12463. }
  12464. public void rePackOrderInfo()
  12465. {
  12466. string id = GetPostString("id");
  12467. if (!string.IsNullOrEmpty(id))
  12468. {
  12469. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12470. if (ceErpPackData == null)
  12471. {
  12472. returnSuccessMsg("查无数据");
  12473. return;
  12474. }
  12475. ceErpPackData.upStatus = 0;
  12476. ceErpPackData.message = "";
  12477. ceErpPackData.Update();
  12478. returnSuccessMsg("打包成功");
  12479. return;
  12480. }
  12481. returnErrorMsg("缺少必要的参数");
  12482. }
  12483. public void backPackOrderInfo()
  12484. {
  12485. string id = GetPostString("id");
  12486. if (!string.IsNullOrEmpty(id))
  12487. {
  12488. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12489. if (ceErpPackData == null)
  12490. {
  12491. returnSuccessMsg("查无数据");
  12492. return;
  12493. }
  12494. ceErpPackData.upStatus = 4;
  12495. ceErpPackData.Update();
  12496. List<string> list = new List<string>();
  12497. StringBuilder sql = new StringBuilder();
  12498. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12499. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12500. for (int i = 0; i < dt.Rows.Count; i++)
  12501. {
  12502. DataRow row = dt.Rows[i];
  12503. list.Add("'" + row["ctid"].ToString() + "'");
  12504. }
  12505. string textCtids = string.Join(",", list);
  12506. 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));
  12507. 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, "无法打包退回"));
  12508. returnSuccessMsg("退回成功");
  12509. return;
  12510. }
  12511. returnErrorMsg("缺少必要的参数");
  12512. }
  12513. public void addPackDownNum()
  12514. {
  12515. string id = GetPostString("id");
  12516. if (!string.IsNullOrEmpty(id))
  12517. {
  12518. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12519. returnSuccessMsg("下载成功");
  12520. return;
  12521. }
  12522. returnErrorMsg("缺少必要的参数");
  12523. }
  12524. public void get_pack_list()
  12525. {
  12526. DataStruct dStruct = GetPostStruct();
  12527. List<string> lw = new List<string>();
  12528. string supplier = GetPostString("supplier");
  12529. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12530. string posTag = CurrentUser.UserPost.Post.Code;
  12531. if (posTag == "Supplier")
  12532. {
  12533. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12534. }
  12535. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12536. dStruct.Order = "createtime desc";
  12537. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12538. writeGridDataTableJson(dStruct.TotalCount, dt);
  12539. }
  12540. public void get_pack_order_list()
  12541. {
  12542. string packId = GetPostString("packId");
  12543. if (string.IsNullOrEmpty(packId))
  12544. {
  12545. returnErrorMsg("缺少必要的参数");
  12546. return;
  12547. }
  12548. StringBuilder sql = new StringBuilder();
  12549. 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);
  12550. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12551. if (dt == null || dt.Rows.Count == 0)
  12552. {
  12553. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12554. return;
  12555. }
  12556. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12557. return;
  12558. }
  12559. public void get_supplier_product_time_list()
  12560. {
  12561. DataStruct dStruct = GetPostStruct();
  12562. List<string> lw = new List<string>();
  12563. string supplier = GetPostString("supplier");
  12564. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12565. string posTag = CurrentUser.UserPost.Post.Code;
  12566. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12567. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12568. writeGridDataTableJson(dStruct.TotalCount, dt);
  12569. }
  12570. public void saveSupplierProductTime()
  12571. {
  12572. string productId = GetPostString("productId");
  12573. if (string.IsNullOrEmpty(productId))
  12574. {
  12575. returnErrorMsg("缺少必要的参数");
  12576. return;
  12577. }
  12578. string productName = GetPostString("productName");
  12579. int supplierId = GetPostInt("supplierId");
  12580. if (supplierId == 0)
  12581. {
  12582. returnErrorMsg("缺少必要的参数");
  12583. return;
  12584. }
  12585. int quantity = GetPostInt("quantity");
  12586. int sendDay = GetPostInt("sendTime");
  12587. string supplierName = GetPostString("supplierName");
  12588. string craft = GetPostString("craft");
  12589. string deadLine = GetPostString("deadLine");
  12590. string dayDeadLine = GetPostString("dayDeadLine");
  12591. try
  12592. {
  12593. int eid = GetPostInt("eid");
  12594. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12595. if (ceErpSupplierProductTime == null)
  12596. {
  12597. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12598. }
  12599. ceErpSupplierProductTime.productId = productId;
  12600. ceErpSupplierProductTime.productName = productName;
  12601. ceErpSupplierProductTime.supplierId = supplierId;
  12602. ceErpSupplierProductTime.supplierName = supplierName;
  12603. ceErpSupplierProductTime.craft = craft;
  12604. ceErpSupplierProductTime.sendDay = sendDay;
  12605. ceErpSupplierProductTime.quantity = quantity;
  12606. if (!string.IsNullOrEmpty(deadLine))
  12607. {
  12608. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12609. }
  12610. if (!string.IsNullOrEmpty(dayDeadLine))
  12611. {
  12612. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12613. }
  12614. if (ceErpSupplierProductTime.ID == 0)
  12615. {
  12616. ceErpSupplierProductTime.Save();
  12617. }
  12618. else
  12619. {
  12620. ceErpSupplierProductTime.Update();
  12621. }
  12622. }
  12623. catch (Exception e)
  12624. {
  12625. }
  12626. returnSuccessMsg("保存成功");
  12627. return;
  12628. }
  12629. public void delSupplierProductTime()
  12630. {
  12631. int eid = GetPostInt("eid");
  12632. if (eid > 0)
  12633. {
  12634. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12635. if (ceErpSupplierProductTime == null)
  12636. {
  12637. returnErrorMsg("查无数据");
  12638. return;
  12639. }
  12640. ceErpSupplierProductTime.Delete();
  12641. returnSuccessMsg("保存成功");
  12642. return;
  12643. }
  12644. returnErrorMsg("缺少必要的参数");
  12645. }
  12646. public void getExpressInfo()
  12647. {
  12648. string ctid = GetPostString("ctid");
  12649. if (!string.IsNullOrEmpty(ctid))
  12650. {
  12651. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12652. if (ceErpTradeCell != null)
  12653. {
  12654. string outSid = ceErpTradeCell.OutSid;
  12655. if (outSid.Length > 0)
  12656. {
  12657. 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);
  12658. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12659. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12660. return;
  12661. }
  12662. }
  12663. returnErrorMsg("查无记录");
  12664. return;
  12665. }
  12666. returnErrorMsg("缺少必要的参数");
  12667. }
  12668. public void getExpressPostData()
  12669. {
  12670. string express = GetPostString("express");
  12671. if (!string.IsNullOrEmpty(express))
  12672. {
  12673. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12674. if (ceErpExpressInfo != null)
  12675. {
  12676. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12677. return;
  12678. }
  12679. }
  12680. returnErrorMsg("缺少必要的参数");
  12681. }
  12682. public void checkSupplierOrder()
  12683. {
  12684. string ctids = GetPostString("ctids");
  12685. if (ctids != null)
  12686. {
  12687. List<string> list = new List<string>();
  12688. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  12689. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12690. for (int i = 0; i < dt.Rows.Count; i++)
  12691. {
  12692. DataRow row = dt.Rows[i];
  12693. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  12694. {
  12695. continue;
  12696. }
  12697. list.Add(row["seller_memo"].ToString());
  12698. }
  12699. if (list.Count > 0)
  12700. {
  12701. 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, "点击下载按钮"));
  12702. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  12703. return;
  12704. }
  12705. }
  12706. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  12707. return;
  12708. }
  12709. public void addPersonId()
  12710. {
  12711. string tid = GetPostString("tid");
  12712. string personId = GetPostString("personId");
  12713. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12714. if (ceErpTrade != null)
  12715. {
  12716. ceErpTrade.receiver_zip = personId;
  12717. ceErpTrade.Update();
  12718. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  12719. returnSuccessMsg("保存成功");
  12720. return;
  12721. }
  12722. returnErrorMsg("缺少必要的参数");
  12723. }
  12724. public void addDeliveryPaymant()
  12725. {
  12726. string tid = GetPostString("tid");
  12727. string paymant = GetPostString("paymant");
  12728. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12729. if (ceErpTrade != null)
  12730. {
  12731. if (!string.IsNullOrEmpty(paymant))
  12732. {
  12733. ceErpTrade.delivery_paymant = Convert.ToDouble(paymant);
  12734. }
  12735. ceErpTrade.Update();
  12736. LogHelper.addLog(tid, CurrentUser.UserID, "偏远物流费:" + paymant, 6);
  12737. returnSuccessMsg("保存成功");
  12738. return;
  12739. }
  12740. returnErrorMsg("缺少必要的参数");
  12741. }
  12742. public void saveCellFile()
  12743. {
  12744. string tid = GetPostString("tid");
  12745. string ctid = GetPostString("ctid");
  12746. string urls = GetPostString("urls");
  12747. string type = GetPostString("type");
  12748. string del = GetPostString("del");
  12749. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  12750. {
  12751. if ("1".Equals(del))
  12752. {
  12753. CeErpTradeCellFile.delByCtid(tid, ctid, tradeCellFile.ToString());
  12754. }
  12755. string[] list = urls.Split(',');
  12756. if (!string.IsNullOrEmpty(urls) && list.Length > 0)
  12757. {
  12758. foreach (string item in list)
  12759. {
  12760. CeErpTradeCellFile ceErpTradeCellFile = new CeErpTradeCellFile(tid, ctid, item, tradeCellFile.ToString());
  12761. ceErpTradeCellFile.Create();
  12762. LogHelper.addLog(ctid, CurrentUser.UserID, "上传客户文件:" + item, 6);
  12763. }
  12764. }
  12765. returnSuccessMsg("保存成功");
  12766. return;
  12767. }
  12768. returnErrorMsg("缺少必要的参数");
  12769. }
  12770. public void getCellFile()
  12771. {
  12772. string tid = GetPostString("tid");
  12773. string ctid = GetPostString("ctid");
  12774. string type = GetPostString("type");
  12775. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  12776. {
  12777. string sql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeCellFile] WHERE isDel=0 and tid='{0}' and ctid='{1}' and type='{2}';", tid, ctid, tradeCellFile);
  12778. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12779. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  12780. return;
  12781. }
  12782. returnErrorMsg("缺少必要的参数");
  12783. }
  12784. public void delCellFile()
  12785. {
  12786. string id = GetPostString("id");
  12787. if (string.IsNullOrEmpty(id))
  12788. {
  12789. returnErrorMsg("缺少必要的参数");
  12790. return;
  12791. }
  12792. CeErpTradeCellFile ceErpTradeCellFile = CeErpTradeCellFile.Get(id);
  12793. CeErpTradeCellFile.delByID(id);
  12794. LogHelper.addLog(ceErpTradeCellFile.ctid, CurrentUser.UserID, "删除客户文件", 6);
  12795. returnSuccessMsg("保存成功");
  12796. }
  12797. public void getInvoiceOrder()
  12798. {
  12799. string tid = GetPostString("tid");
  12800. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12801. List<string> tids = new List<string>();
  12802. if (!string.IsNullOrEmpty(ceErpTrade.buyer_nick) && !string.IsNullOrEmpty(ceErpTrade.buyer_id))
  12803. {
  12804. 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);
  12805. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12806. foreach (DataRow dr in dt.Rows)
  12807. {
  12808. tids.Add("'" + dr["tid"].ToString() + "'");
  12809. }
  12810. }
  12811. else
  12812. {
  12813. tids.Add("'" + ceErpTrade.tid + "'");
  12814. }
  12815. DataTable cell_dt = new DataTable();
  12816. if (tids.Count > 0)
  12817. {
  12818. cell_dt = DbHelper.DbConn.ExecuteDataset(string.Format("SELECT * FROM [dbo].[CE_ErpTradeCell] WHERE tid in ({0});", string.Join(",", tids))).Tables[0];
  12819. }
  12820. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(cell_dt));
  12821. return;
  12822. }
  12823. }
  12824. }