tmcHelper.cs 196 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927
  1. using BizCom;
  2. using Microsoft.SqlServer.Server;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using NHibernate.Mapping;
  6. using SiteCore;
  7. using SiteCore.Handler;
  8. using SiteCore.taobao;
  9. using SiteCore.taoObj;
  10. using SQLData;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Data;
  14. using System.Data.SqlClient;
  15. using System.Linq;
  16. using System.Text;
  17. using static SiteCore.taoObj.Api_tmc_trade_info_Obj;
  18. using static SiteCore.taoObj.Api_trade_fullinfo_get_response_Obj;
  19. using static SiteCore.taoObj.Api_trade_info;
  20. using static SiteCore.taoObj.dataShopResponseVo;
  21. using static SiteCore.taoObj.Refunds_receive_get_response_Obj;
  22. using static SiteCore.taoObj.Trade_fullinfo_get_response_Obj;
  23. using static SiteCore.taoObj.work_core_vo;
  24. //status可选值:
  25. //* TRADE_NO_CREATE_PAY(没有创建支付宝交易)
  26. //* WAIT_BUYER_PAY(等待买家付款)
  27. //* SELLER_CONSIGNED_PART(卖家部分发货)
  28. //* WAIT_SELLER_SEND_GOODS(等待卖家发货, 即:买家已付款)
  29. //* WAIT_BUYER_CONFIRM_GOODS(等待买家确认收货, 即:卖家已发货)
  30. //* TRADE_BUYER_SIGNED(买家已签收, 货到付款专用)
  31. //* TRADE_FINISHED(交易成功)
  32. //* TRADE_CLOSED(付款以后用户退款成功,交易自动关闭)
  33. //* TRADE_CLOSED_BY_TAOBAO(付款以前,卖家或买家主动关闭交易)
  34. //* PAY_PENDING(国际信用卡支付付款确认中)
  35. //* WAIT_PRE_AUTH_CONFIRM(0元购合约中)
  36. namespace SiteCore
  37. {
  38. /// <summary>
  39. /// 同步推送处理
  40. /// </summary>
  41. public class tmcHelper
  42. {
  43. public static int RemoveEmptyEntries { get; private set; }
  44. // case "taobao_trade_TradeCreate"://创建淘宝交易消息
  45. // {
  46. // break;
  47. // }
  48. // case "taobao_trade_TradeLogisticsAddressChanged"://卖家修改交易收货地址消息
  49. // case "taobao_trade_TradeMemoModified"://交易备注修改消息
  50. // case "taobao_trade_TradeRated"://交易评价变更消息
  51. // case "taobao_trade_TradeBuyerPay"://买家付完款,或万人团买家付完尾款
  52. // case "taobao_trade_TradeSuccess"://交易成功消息(确认收货)
  53. // case "taobao_trade_TradePartlyConfirmPay"://子订单打款成功消息
  54. // case "taobao_trade_TradePartlyRefund"://子订单退款成功消息
  55. // case "taobao_trade_TradeDelayConfirmPay"://延长收货时间消息
  56. // case "taobao_trade_TradeSellerShip"://卖家发货消息
  57. // case "taobao_trade_TradeClose"://关闭交易消息
  58. // case "taobao_trade_TradeCloseAndModifyDetailOrder"://关闭或修改子订单消息
  59. // case "taobao_trade_TradeModifyFee"://修改交易费用消息
  60. public static string GetUTF8String(byte[] buffer)
  61. {
  62. if (buffer == null)
  63. return null;
  64. if (buffer.Length <= 3)
  65. {
  66. return Encoding.UTF8.GetString(buffer);
  67. }
  68. byte[] bomBuffer = new byte[] { 0xef, 0xbb, 0xbf };
  69. if (buffer[0] == bomBuffer[0] && buffer[1] == bomBuffer[1] && buffer[2] == bomBuffer[2])
  70. {
  71. return new UTF8Encoding(false).GetString(buffer, 3, buffer.Length - 3);
  72. }
  73. return Encoding.UTF8.GetString(buffer);
  74. }
  75. /// <summary>
  76. /// 交易订单关闭
  77. /// </summary>
  78. /// <param name="content"></param>
  79. public static void erp_CloseTrade(string content)
  80. {
  81. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  82. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  83. if (status == "TRADE_CLOSED_BY_TAOBAO")
  84. {
  85. StringBuilder sql = new StringBuilder();
  86. sql.AppendFormat("update CE_ErpTradeCell set status='{0}' where tid='{1}';", status, dics["tid"]);
  87. sql.AppendFormat("update CE_ErpTradeCell set OrderState={1} where tid='{0}' ;", dics["tid"], OrderState.交易关闭);
  88. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", status, dics["tid"], dics["oid"]);
  89. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  90. //消息通知
  91. }
  92. }
  93. //接收到--新订单生成消息
  94. public static void erp_TradeBuyerPay(string content)
  95. {
  96. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  97. string tid = dics["tid"].ToString();
  98. string sellerNick = dics["seller_nick"].ToString();
  99. string sessionkey = taobaoHelper.ShopKeyDics[sellerNick];
  100. string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid); //taobaoHelper.test();
  101. createNewOrder(res);
  102. }
  103. //创建新订单
  104. public static void createNewOrder(string res)
  105. {
  106. Trade_fullinfo_get_response_Obj fullObj = null;
  107. if (res == "") return;
  108. try
  109. {
  110. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  111. //res = res.Replace(" ", "");
  112. fullObj = JsonConvert.DeserializeObject<Trade_fullinfo_get_response_Obj>(res);
  113. }
  114. catch (Exception ex)
  115. {
  116. }
  117. if (fullObj == null)
  118. {
  119. Console.WriteLine("Trade_fullinfo_get_response_Obj isNull");
  120. return;
  121. }
  122. Trade tObj = fullObj.trade_fullinfo_get_response.trade;
  123. Orders orderList = tObj.orders;
  124. StringBuilder sql = new StringBuilder();
  125. CeErpTrade td = CeErpTrade.Get(tObj.tid);
  126. if (td != null)
  127. {
  128. //已经存在了,就不要再继续创建了;
  129. return;
  130. }
  131. //原始单创建
  132. CeErpTrade trade = new CeErpTrade();
  133. trade.tid = tObj.tid;
  134. trade.num = tObj.num;
  135. trade.status = tObj.status;
  136. trade.type = tObj.type;
  137. trade.price = Convert.ToDouble(tObj.price);
  138. trade.discount_fee = Convert.ToDouble(tObj.discount_fee);
  139. trade.total_fee = Convert.ToDouble(tObj.total_fee);
  140. trade.created = tObj.created;
  141. if (tObj.pay_time.ToString() != "0001/1/1 0:00:00" && tObj.pay_time != null)
  142. {
  143. trade.pay_time = tObj.pay_time;
  144. }
  145. if (tObj.modified.ToString() != "0001/1/1 0:00:00" && tObj.modified != null)
  146. {
  147. trade.modified = tObj.modified;
  148. }
  149. if (tObj.end_time.ToString() != "0001/1/1 0:00:00" && tObj.end_time != null)
  150. {
  151. trade.end_time = tObj.end_time;
  152. }
  153. trade.buyer_nick = tObj.buyer_nick;
  154. trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  155. trade.seller_nick = tObj.seller_nick;
  156. trade.payment = Convert.ToDouble(tObj.payment);
  157. trade.receiver_name = tObj.receiver_name;
  158. trade.receiver_state = tObj.receiver_state;
  159. trade.receiver_city = tObj.receiver_city;
  160. trade.receiver_town = GetNoNullValue_string(tObj.receiver_town);
  161. trade.receiver_district = GetNoNullValue_string(tObj.receiver_district);
  162. trade.receiver_address = tObj.receiver_address;
  163. trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile);
  164. trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone);
  165. if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null)
  166. {
  167. trade.consign_time = tObj.consign_time;
  168. }
  169. if (tObj.delivery_time.ToString() != "0001/1/1 0:00:00" && tObj.delivery_time != null)
  170. {
  171. trade.delivery_time = tObj.delivery_time;
  172. }
  173. trade.buyer_message = GetNoNullValue_string(tObj.buyer_message);
  174. trade.buyer_memo = GetNoNullValue_string(tObj.buyer_memo);
  175. trade.seller_memo = GetNoNullValue_string(tObj.seller_memo);
  176. trade.Create();
  177. //查询是否有退款记录
  178. CeErpSpecialRefund ceErpSpecialRefund = new CeErpSpecialRefund();
  179. ceErpSpecialRefund = CeErpSpecialRefund.GetByTid(trade.tid);
  180. if (ceErpSpecialRefund != null)
  181. {
  182. refundTmcHelper.Api_TmcRefundMsg(ceErpSpecialRefund.refxml);
  183. ceErpSpecialRefund.whethernotify = 1;
  184. ceErpSpecialRefund.Update();
  185. }
  186. bool isXianhuo = false;//是否为现货单,现货单直接根据客户选的 选项生成Cell备注
  187. string xianhuoMemo = "(" + trade.tid + ")现货-";
  188. //order表创建
  189. foreach (Order item in orderList.order)
  190. {
  191. CeErpTradeOrder order = new CeErpTradeOrder();
  192. order.tid = trade.tid;
  193. order.oid = item.oid;
  194. order.buyer_nick = trade.buyer_nick;
  195. order.refund_status = item.refund_status;
  196. order.status = item.status;
  197. order.title = item.title;
  198. order.price = Convert.ToDouble(item.price);
  199. order.pic_path = item.pic_path;
  200. order.num = Convert.ToDouble(item.num.ToString());
  201. order.payment = Convert.ToDouble(item.payment);
  202. order.adjust_fee = Convert.ToDouble(item.adjust_fee);
  203. if (item.sku_id != null && item.sku_properties_name != null && item.sku_properties_name.IndexOf("现货") != -1)
  204. {
  205. order.sku_properties_name = item.sku_properties_name;
  206. order.sku_id = item.sku_id;
  207. isXianhuo = true;
  208. xianhuoMemo += order.sku_properties_name;
  209. }
  210. order.Create();
  211. }
  212. if (isXianhuo)
  213. {
  214. xianhuoMemo += "-";
  215. xianhuoMemo += trade.seller_nick;
  216. }
  217. //cell表创建
  218. CeErpTradeCell entity = null;
  219. entity = CeErpTradeCell.GetByCtid(tObj.tid);
  220. if (entity == null)
  221. {
  222. try
  223. {
  224. entity = new CeErpTradeCell();
  225. entity.ctid = tObj.tid;
  226. entity.tid = tObj.tid;
  227. entity.payment = Convert.ToDouble(tObj.payment);
  228. if (isXianhuo)
  229. {
  230. entity.OrderState = 5;
  231. entity.seller_memo = xianhuoMemo;
  232. }
  233. entity.Create();
  234. }
  235. catch (Exception ex)
  236. {
  237. XLog.SaveLog(0, ex.Message);
  238. }
  239. }
  240. //生成档案客户信息
  241. operateCustomer(tObj);
  242. }
  243. public static void operateCustomer(Trade Obj)
  244. {
  245. CeErpCustomer cus = null;
  246. cus = CeErpCustomer.GetByNick(Obj.buyer_nick);
  247. if (cus != null)
  248. {
  249. cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  250. cus.phone = Obj.receiver_mobile;
  251. TimeSpan tsday = Obj.pay_time.Subtract((DateTime)cus.lastbuy_time);
  252. cus.buy_day = tsday.Days;
  253. cus.total_fee = cus.total_fee + Convert.ToDouble(Obj.payment);
  254. cus.buy_count = cus.buy_count + 1;
  255. cus.lastbuy_time = Obj.pay_time;
  256. cus.Update();
  257. }
  258. else
  259. {
  260. try
  261. {
  262. cus = new CeErpCustomer();
  263. cus.buyer_nick = Obj.buyer_nick;
  264. cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  265. cus.phone = Obj.receiver_mobile;
  266. cus.buy_day = 0;
  267. cus.buy_count = 1;
  268. cus.lastbuy_time = Obj.pay_time;
  269. cus.total_fee = Convert.ToDouble(Obj.payment);
  270. cus.Create();
  271. }
  272. catch (Exception ex)
  273. {
  274. XLog.SaveLog(0, ex.Message);
  275. }
  276. }
  277. }
  278. public static string GetNoNullValue_string(string value)
  279. {
  280. value = value.Replace("\n", " ");
  281. value = value.Replace("\r", " ");
  282. value = value.Replace("*", "x");
  283. if (value == null)
  284. {
  285. return "";
  286. }
  287. return value;
  288. }
  289. public static string GetNull_tostring(object value)
  290. {
  291. if (value == null)
  292. {
  293. return "";
  294. }
  295. return value.ToString();
  296. }
  297. //接收到--卖家修改备注消息
  298. public static void erp_TradeMemoModified(string content)
  299. {
  300. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  301. if (!dics.ContainsKey("seller_memo"))
  302. {
  303. return;
  304. }
  305. string tid = dics["tid"].ToString();
  306. string smemo = dics["seller_memo"].ToString();//TRADE_CLOSED_BY_TAOBAO
  307. string buyer = dics["buyer_nick"].ToString();
  308. //原始表--没有这个单,不能拆分
  309. CeErpTrade mainEn = CeErpTrade.Get(tid);
  310. if (mainEn == null) return;
  311. createCellOrder(mainEn, tid, smemo, buyer);
  312. }
  313. //接收到--交易成功消息
  314. public static void erp_TradeSuccess(string content)
  315. {
  316. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  317. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  318. //if (status == "TRADE_FINISHED")
  319. //{
  320. StringBuilder sql = new StringBuilder();
  321. sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}';", "TRADE_FINISHED", dics["tid"]);
  322. sql.AppendFormat("update view_ErpTradeCell set OrderState={1} where tid='{0}';", dics["tid"], (int)OrderState.交易完成);
  323. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", "TRADE_FINISHED", dics["tid"], dics["oid"]);
  324. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  325. //}
  326. }
  327. //接收到--卖家发货消息
  328. public static void erp_TradeSellerShip(string content)
  329. {
  330. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  331. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  332. //if (status == "WAIT_BUYER_CONFIRM_GOODS")
  333. //{
  334. StringBuilder sql = new StringBuilder();
  335. //sql.AppendFormat("update view_ErpTradeCell set OrderState={2} where tid='{0}' and IsPreDelivery=0 ;", dics["tid"], (int)OrderState.已发货);//发货接口已经改变OrderState
  336. sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]);
  337. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]);
  338. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  339. //}
  340. }
  341. //接收到买家子订单退款 并卖家确认
  342. public static void erp_TradePartlyRefund(string content)
  343. {
  344. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  345. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  346. //if (status == "TRADE_CLOSED")
  347. //{
  348. StringBuilder sql = new StringBuilder();
  349. sql.AppendFormat("update CE_ErpTrade set status='{0}'where tid='{1}' ;", "TRADE_CLOSED", dics["tid"]);
  350. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}';", "TRADE_CLOSED", dics["tid"], dics["oid"]);
  351. sql.AppendFormat("update CE_ErpTradeCell set OrderState='{0}',IsRefund={1} where tid='{2}';", (int)OrderState.交易关闭, 1, dics["tid"]);
  352. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  353. LogHelper.addLog(dics["tid"].ToString(), 0, "客户申请退款,已确认", (int)OrderState.交易关闭);
  354. //}
  355. }
  356. public static void Api_TmcTradeMsg(string res)
  357. {
  358. Api_tmc_trade_info_Obj fullObj = null;
  359. if (res == "") return;
  360. try
  361. {
  362. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  363. //res = res.Replace(" ", "");
  364. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(res);
  365. }
  366. catch (Exception ex)
  367. {
  368. XLog.SaveLog(0, res + "|1|" + ex.Message);
  369. }
  370. if (fullObj == null)
  371. {
  372. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  373. XLog.SaveLog(0, "Api_tmc_trade_info_Obj isNull");
  374. return;
  375. }
  376. Content tObj = fullObj.content;
  377. List<Api_tmc_trade_info_Obj.LinesItem> orderList = tObj.lines;
  378. //未付款,未成功的单不需要 榆家不收
  379. if (tObj.status == "DELETED" || (tObj.status == "CANCEL" && tObj.refType != "JD") || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
  380. {
  381. return;
  382. }
  383. bool isCreate = false;
  384. CeErpTrade trade = null;
  385. trade = CeErpTrade.Get(tObj.refOid);
  386. tObj.sellerMemo = tObj.sellerMemo.Replace("默拍-发小礼物", "").Replace("电子稿-发小礼物", "").Replace("客户联系不上-发小礼物", "");
  387. if (trade == null)
  388. { //新生成订单的
  389. isCreate = true;
  390. trade = new CeErpTrade();
  391. trade.tid = tObj.refOid;
  392. trade.type = tObj.refType;
  393. trade.price = Convert.ToDouble(tObj.totalPrice);
  394. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  395. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  396. trade.created = StampToDateTime(tObj.orderTime);
  397. if (tObj.payTime != null && tObj.payTime.Length > 0)
  398. {
  399. trade.pay_time = StampToDateTime(tObj.payTime);
  400. }
  401. if (tObj.posCode != null) trade.posCode = tObj.posCode;
  402. trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
  403. if (trade.seller_nick == "")
  404. {
  405. trade.seller_nick = getShopNameByECode(trade.posCode);
  406. tObj.openSellerNick = trade.seller_nick;
  407. }
  408. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  409. trade.payment = Convert.ToDouble(tObj.payment);
  410. //trade.receiver_name = tObj.receiver_name;
  411. }
  412. if (trade.buyer_nick == null || trade.buyer_nick.Length == 0)
  413. {
  414. trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  415. }
  416. trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
  417. trade.receiver_state = tObj.receiverState;
  418. trade.receiver_city = tObj.receiverCity;
  419. trade.receiverId = tObj.receiverId;
  420. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  421. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  422. if (trade.type == "JD" && tObj.status == "CANCEL")
  423. trade.status = "CLOSE";
  424. else
  425. trade.status = tObj.status;
  426. //if (tObj.refundStatus == "PART_REFUNDED" || tObj.refundStatus == "ALL_REFUNDED")
  427. //{
  428. //}
  429. trade.seller_flag = tObj.flag;
  430. if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
  431. {
  432. trade.modified = StampToDateTime(tObj.modifyTime);
  433. }
  434. if (tObj.finishTime != null && tObj.finishTime.Length > 0)
  435. {
  436. trade.end_time = StampToDateTime(tObj.finishTime);
  437. }
  438. if (tObj.shippingTime != null && tObj.shippingTime.Length > 0)
  439. {
  440. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  441. }
  442. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  443. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  444. bool isSellerMemoChange = false;
  445. //备注修改
  446. tObj.sellerMemo = GetNoNullValue_string(tObj.sellerMemo);
  447. if (trade.seller_memo != tObj.sellerMemo)
  448. {
  449. isSellerMemoChange = true;
  450. }
  451. if (trade.seller_memo.Length != tObj.sellerMemo.Length)
  452. {
  453. isSellerMemoChange = true;
  454. }
  455. trade.seller_memo = tObj.sellerMemo;
  456. if (trade.seller_nick != "" && trade.pay_time > StampToDateTime("1725120000000"))
  457. {
  458. if (tObj.refType == "TMALL" || tObj.refType == "TB")
  459. {
  460. string[] acclist = tObj.sellerMemo.Split('-');
  461. List<string> list = new List<string>(acclist);
  462. string buyer_nick = "";
  463. //配件-80x80mm-200张-卡片-yxmrebekah-甘露
  464. if (trade.seller_memo.StartsWith("配件-"))
  465. {
  466. if (list.Count > 4)
  467. {
  468. buyer_nick = list[4];
  469. }
  470. }
  471. else if ((trade.seller_memo.IndexOf("logo") != -1 || trade.seller_memo.IndexOf("LOGO") != -1))
  472. {
  473. if (list.Count > 3)
  474. {
  475. buyer_nick = list[3];
  476. }
  477. }
  478. else if (trade.seller_memo.IndexOf("补差") != -1 && list.Count < 6)
  479. {
  480. if (list.Count > 1)
  481. {
  482. buyer_nick = list[1];
  483. }
  484. }
  485. else if (trade.seller_memo.IndexOf("默拍单") != -1 && list.Count < 6)
  486. {
  487. if (list.Count > 1)
  488. {
  489. buyer_nick = list[1];
  490. }
  491. }
  492. else if (trade.seller_memo.IndexOf("寄样") != -1)
  493. {
  494. if (list.Count > 3)
  495. {
  496. buyer_nick = list[3];
  497. }
  498. }
  499. else if (trade.seller_memo.IndexOf("拿样订单") != -1)
  500. {
  501. if (list.Count > 1)
  502. {
  503. buyer_nick = list[1];
  504. }
  505. }
  506. else if (trade.seller_memo.IndexOf("礼物") != -1 && list.Count < 6)
  507. {
  508. if (list.Count > 1)
  509. {
  510. buyer_nick = list[1];
  511. }
  512. }
  513. else
  514. {
  515. if (list.Count > 5)
  516. {
  517. buyer_nick = list[5];
  518. }
  519. }
  520. tObj.sellerMemo = string.Join("-", list);
  521. tObj.sellerMemo = tObj.sellerMemo.Replace("-" + buyer_nick, string.Empty);
  522. trade.buyer_nick = buyer_nick.Replace("+", "-").Replace("#", "logo").Replace("@", "LOGO");
  523. }
  524. }
  525. if (isCreate)
  526. {
  527. trade.create_time = DateTime.Now;
  528. trade.Create();
  529. }
  530. else
  531. {
  532. if (tObj.status == "CLOSE")
  533. {
  534. trade.consign_time = DateTime.Now;
  535. }
  536. trade.Update();
  537. }
  538. commonHelper.sendOrderInfo(trade.tid, "", trade.buyer_id, trade.buyer_nick);
  539. //dataHelper.sendErpTradeInfo(new dataSendTradeBean(tObj));
  540. try
  541. {
  542. if (tObj.status == "CLOSE" || tObj.status == "CANCEL")
  543. {
  544. StringBuilder sql = new StringBuilder();
  545. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, tObj.refOid);
  546. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  547. ApiVo apiVo = new ApiVo();
  548. apiVo.actionName = "closeDesign";
  549. apiVo.orderNumber = tObj.refOid;
  550. //designHelper.API_WorkCore(apiVo);//closeDesign
  551. LogHelper.addLog(tObj.refOid, 0, "交易关闭", (int)OrderState.交易关闭);
  552. // commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
  553. // removeOldCustomerInfo(trade);
  554. }
  555. else if (tObj.status == "COMPLETE")
  556. {
  557. StringBuilder sql = new StringBuilder();
  558. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, tObj.refOid);
  559. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  560. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
  561. }
  562. else if (tObj.status == "SHIPPED")//已发货
  563. {
  564. StringBuilder sql = new StringBuilder();
  565. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, tObj.refOid);
  566. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  567. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
  568. }
  569. }
  570. catch (Exception ex)
  571. {
  572. XLog.SaveLog(0, res + "shipped:" + ex.Message);
  573. throw ex;
  574. }
  575. int xianhuoProductCount = 0;
  576. bool isXianhuo = false;
  577. string xianhuoMemo = "(" + trade.tid + ")现货-";
  578. bool isNew = true;
  579. CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
  580. int shopId = 0;
  581. if (nShop != null)
  582. {
  583. shopId = nShop.ID;
  584. }
  585. try
  586. {
  587. foreach (Api_tmc_trade_info_Obj.LinesItem item in orderList)
  588. {
  589. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
  590. bool isCreateOrder = false;
  591. if (order == null)
  592. {
  593. order = new CeErpTradeOrder();
  594. isCreateOrder = true;
  595. order.oid = item.refOlId;
  596. order.tid = trade.tid;
  597. order.buyer_nick = trade.buyer_nick;
  598. }
  599. if (item.refundStatus == "PART_REFUNDED" || item.refundStatus == "REFUNDED" || item.refundStatus == "WAIT_BUYER_RETURN_GOODS")
  600. {
  601. CeErpTradeRefund refund = CeErpTradeRefund.GetByTid(tObj.refOid);
  602. if (refund == null)
  603. {
  604. refund = new CeErpTradeRefund();
  605. refund.refund_id = tObj.refOid;
  606. refund.tid = tObj.refOid;
  607. //refund.oid = item.oid;
  608. refund.created = DateTime.Now;
  609. if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
  610. {
  611. refund.modified = StampToDateTime(tObj.modifyTime);
  612. }
  613. refund.status = item.refundStatus;
  614. refund.order_status = tObj.status;
  615. refund.payment = tObj.payment;
  616. refund.refund_fee = tObj.payment;
  617. refund.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  618. refund.buyer_id = GetNull_tostring(tObj.openBuyerId);
  619. refund.seller_nick = trade.seller_nick;
  620. refund.total_fee = tObj.payment;
  621. refund.RefundState = 1;//1待审核2待确认
  622. refund.Create();
  623. //cell订单 添加退款标记
  624. int rstate = commonHelper.getRefundTagByState(item.refundStatus);
  625. commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  626. designHelper.API_refundOrder(tObj.refOid, "refundEd", "");
  627. LogHelper.addLog(tObj.refOid, 0, "已退款", (int)OrderState.交易关闭);
  628. }
  629. else
  630. {
  631. if (refund.status != item.refundStatus)
  632. {
  633. refund.modified = DateTime.Now;
  634. refund.status = item.refundStatus;
  635. refund.order_status = tObj.status;
  636. refund.Update();
  637. int rstate = commonHelper.getRefundTagByState(item.refundStatus);
  638. commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  639. LogHelper.addLog(tObj.refOid, 0, "更新退款状态", (int)OrderState.交易关闭);
  640. }
  641. }
  642. }
  643. else if (item.refundStatus == "REFUNDING" && order.refund_status != "REFUNDING")
  644. {
  645. commonHelper.UpdateRefundOrderState(tObj.refOid, 1);
  646. designHelper.API_refundOrder(tObj.refOid, "refundIng", "");
  647. LogHelper.addLog(tObj.refOid, 0, "申请退款中");
  648. }
  649. else if (item.refundStatus == "NO_REFUND" && order.refund_status != "NO_REFUND" && isCreateOrder == false)
  650. {
  651. //CeErpTradeRefund.Del(tObj.refOid);
  652. commonHelper.UpdateRefundOrderState(tObj.refOid, 0);
  653. designHelper.API_refundOrder(tObj.refOid, "refundCancel", "");
  654. LogHelper.addLog(tObj.refOid, 0, "关闭申请退款");
  655. }
  656. else if (item.refundStatus == "REJECT_REFUNDED" && order.refund_status != "REJECT_REFUNDED" && isCreateOrder == false)
  657. {
  658. //CeErpTradeRefund.Del(tObj.refOid);
  659. commonHelper.UpdateRefundOrderState(tObj.refOid, 0);
  660. LogHelper.addLog(tObj.refOid, 0, "拒绝退货退款");
  661. }
  662. order.refund_status = item.refundStatus;
  663. order.status = trade.status;
  664. order.title = item.title;
  665. order.price = Convert.ToDouble(item.price);
  666. if (item.picUrl != null)
  667. order.pic_path = item.picUrl;
  668. order.num = Convert.ToDouble(item.num.ToString());
  669. order.payment = Convert.ToDouble(item.price);
  670. order.total_fee = Convert.ToDouble(item.totalFee);
  671. //order.adjust_fee = Convert.ToDouble(item.price);
  672. if (item.refSkuId != null && item.refSkuId != "")
  673. {
  674. order.sku_id = item.refSkuId;
  675. }
  676. if (item.standards != null && item.standards != "")
  677. {
  678. order.sku_properties_name = item.standards;
  679. }
  680. if (item.refSpuId != null && item.refSpuId != "")
  681. {
  682. order.spu_id = item.refSpuId;
  683. }
  684. List<string> standards_list = new List<string>() { "现货", "封酒贴", "兔团团", "帆布", "手拉旗", "kt", "条幅", "臂贴", "挂画" };
  685. bool isInList = false;
  686. foreach (string text in standards_list)
  687. {
  688. if (item.standards.IndexOf(text) > -1)
  689. {
  690. isInList = true;
  691. }
  692. }
  693. if (item.standards.Contains("宠物") && (item.standards.Contains("转印贴") || item.standards.Contains("转印")))
  694. {
  695. trade.designType = 1;
  696. }
  697. if (item.title.Contains("宠物") && (item.title.Contains("转印贴") || item.title.Contains("转印")))
  698. {
  699. trade.designType = 1;
  700. }
  701. if (item.refSkuId != null && item.standards != null && (isInList || item.standards.IndexOf("#") != -1) && item.standards.IndexOf("定制") == -1)
  702. {
  703. isXianhuo = true;
  704. xianhuoMemo += order.sku_properties_name;
  705. xianhuoMemo += ("-数量:" + order.num + ";");
  706. xianhuoProductCount += (int)order.num;
  707. if (isCreateOrder)
  708. {
  709. string goodsSql = "select * from CE_ErpBagShopGoods";
  710. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  711. if (goodsDt.Rows.Count > 0)
  712. {
  713. foreach (DataRow gdr in goodsDt.Rows)
  714. {
  715. string bname = gdr["bname"].ToString();
  716. string bsize = gdr["bsize"].ToString();
  717. string bcount = gdr["bcount"].ToString();
  718. if (bname.Length > 0 && order.sku_properties_name.IndexOf(bname) != -1)
  719. {
  720. order.bagName = bname;
  721. order.isBagOrder = 1;
  722. }
  723. if (bsize.Length > 0 && order.sku_properties_name.IndexOf(bsize) != -1)
  724. {
  725. order.bagSize = bsize;
  726. }
  727. if (bcount.Length > 0 && order.sku_properties_name.IndexOf(bcount) != -1)
  728. {
  729. order.bagCount = bcount;
  730. int bbcount = commonHelper.getIntCountFromString(bcount);
  731. order.bagRealCount = bbcount * (int)order.num;
  732. }
  733. }
  734. }
  735. }
  736. }
  737. if (isCreateOrder)
  738. {
  739. order.Create();
  740. CeErpTradeSpu ceErpTradeSpu = CeErpTradeSpu.GetBySpuId(order.spu_id);
  741. //dataHelper.sendErpTradeOrderInfo(new dataSendTradeOrderBean(item, tObj));
  742. if (ceErpTradeSpu == null)
  743. {
  744. ceErpTradeSpu = new CeErpTradeSpu();
  745. ceErpTradeSpu.spuId = order.spu_id;
  746. ceErpTradeSpu.tid = order.tid;
  747. ceErpTradeSpu.shopId = shopId;
  748. ceErpTradeSpu.createTime = DateTime.Now;
  749. dataSendSpuBean bean = new dataSendSpuBean();
  750. bean.ShortText1728890680485 = order.title;
  751. bean.ShortText1728890649488 = order.spu_id;
  752. bean.shopId = shopId.ToString();
  753. bean.Date1728891156995 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  754. dataResponseVo response = dataHelper.sendSpuInfo(bean);
  755. if (response != null)
  756. {
  757. if ("0".Equals(response.errcode))
  758. {
  759. ceErpTradeSpu.isSync = true;
  760. }
  761. else
  762. {
  763. ceErpTradeSpu.message = response.errmsg;
  764. }
  765. }
  766. ceErpTradeSpu.Create();
  767. }
  768. DateTime orderTime = ceErpTradeSpu.createTime ?? DateTime.MinValue;
  769. if (DateTime.Compare(orderTime.AddDays(30), DateTime.Now) < 0)
  770. {
  771. isNew = false;
  772. }
  773. }
  774. else
  775. {
  776. order.Update();
  777. }
  778. }
  779. }
  780. catch (Exception ex)
  781. {
  782. XLog.SaveLog(0, res + "|order表:" + ex.Message);
  783. throw ex;
  784. }
  785. if (shopId == 5)
  786. {
  787. commonHelper.sendOrderInfoToNewPlant(res);
  788. commonHelper.sendOrderInfoToNewAIPlant(res);
  789. }
  790. //if (isXianhuo)
  791. //{
  792. // xianhuoMemo += "-";
  793. // xianhuoMemo += trade.seller_nick;
  794. //}
  795. if (!trade.IsNew)
  796. {
  797. trade.IsNew = isNew;
  798. }
  799. trade.Update();
  800. CeErpTradeCell entity = null;
  801. entity = CeErpTradeCell.GetByCtid_M(tObj.refOid);
  802. if (entity == null)
  803. {
  804. try
  805. {
  806. entity = new CeErpTradeCell();
  807. entity.ctid = tObj.refOid;
  808. //唯一标识
  809. entity.OrderSn = tObj.refOid;
  810. string orderSn = commonHelper.generateDateTimeRandomNos();
  811. if (orderSn != "")
  812. {
  813. entity.OrderSn = orderSn;
  814. }
  815. entity.tid = tObj.refOid;
  816. entity.seller_memo = "";
  817. entity.payment = Convert.ToDouble(tObj.payment);
  818. entity.AfterSalePayment = Convert.ToDouble(tObj.payment);
  819. if (tObj.payTime != null)
  820. {
  821. entity.pay_time = StampToDateTime(tObj.payTime);
  822. }
  823. entity.UpdateTime = DateTime.Now;
  824. entity.ShopId = shopId;
  825. if (isXianhuo)
  826. {
  827. entity.OrderState = 6;
  828. entity.seller_memo = xianhuoMemo;
  829. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  830. entity.IsXianHuo = 1;
  831. entity.FinishPlaceTime = entity.pay_time;
  832. entity.ProductCount = xianhuoProductCount.ToString();
  833. if (xianhuoMemo.IndexOf("封酒贴") != -1)
  834. {
  835. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  836. if (trade.buyer_memo != "")
  837. {
  838. entity.OrderState = 2;
  839. entity.ProductId = 1;
  840. entity.IsXianHuo = 0;
  841. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  842. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  843. entity.seller_memo = xianhuoMemo;
  844. if (entity.ShopId != 0)
  845. {
  846. entity.OrderState = orderAudit(entity.ShopId);
  847. }
  848. }
  849. }
  850. else if (xianhuoMemo.IndexOf("#") != -1)
  851. {
  852. entity.SupplierId = 87;
  853. }
  854. else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  855. {
  856. entity.SupplierId = 70;
  857. }
  858. else if (xianhuoMemo.IndexOf("兔团团") != -1)
  859. {
  860. entity.SupplierId = 101;
  861. }
  862. else if (xianhuoMemo.IndexOf("手拉旗") != -1)
  863. {
  864. entity.SupplierId = 108;
  865. }
  866. else if (xianhuoMemo.IndexOf("臂贴") != -1)
  867. {
  868. entity.OrderState = 2;
  869. entity.ProductId = 2690;
  870. entity.IsXianHuo = 0;
  871. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  872. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  873. entity.seller_memo = xianhuoMemo;
  874. }
  875. try
  876. {
  877. string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
  878. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  879. List<Dictionary<string, string>> material_list = new List<Dictionary<string, string>>();
  880. List<Dictionary<string, string>> name_list = new List<Dictionary<string, string>>();
  881. foreach (DataRow dr in goodsDt.Rows)
  882. {
  883. string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
  884. List<string> xianhuo = sqlMemo.Split(',').ToList();
  885. foreach (var item in xianhuo)
  886. {
  887. if (string.IsNullOrEmpty(item)) continue;
  888. Dictionary<string, string> material_map = new Dictionary<string, string>();//材质
  889. Dictionary<string, string> name_map = new Dictionary<string, string>();//特殊名称
  890. if (item.IndexOf('-') > -1)
  891. {
  892. List<string> list = item.Split('-').ToList();
  893. material_map.Add(dr["id"].ToString(), list[0]);
  894. name_map.Add(dr["id"].ToString(), list[1]);
  895. }
  896. else
  897. {
  898. material_map.Add(dr["id"].ToString(), item);
  899. }
  900. material_list.Add(material_map);
  901. name_list.Add(name_map);
  902. }
  903. }
  904. List<string> materials = new List<string>();
  905. List<string> names = new List<string>();
  906. List<string> result = new List<string>();
  907. for (int i = 0; i < material_list.Count; i++)
  908. {
  909. Dictionary<string, string> map = material_list[i];
  910. foreach (var item in map)
  911. {
  912. if (xianhuoMemo.IndexOf(item.Value) > -1)
  913. {
  914. Dictionary<string, string> map2 = name_list[i];
  915. if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
  916. {
  917. foreach (var item1 in map2)
  918. {
  919. if (xianhuoMemo.IndexOf(item1.Value) > -1)
  920. {
  921. names.Add(item1.Key);
  922. materials.Add(item.Key);
  923. }
  924. }
  925. }
  926. else
  927. {
  928. materials.Add(item.Key);
  929. }
  930. }
  931. }
  932. }
  933. if (names.Count > 0)//特殊名称有只先在特殊名称里选择
  934. {
  935. result = names.Distinct().ToList();
  936. }
  937. else
  938. {
  939. result = materials.Distinct().ToList();
  940. }
  941. if (result.Count > 0)
  942. {
  943. Random rnd = new Random();
  944. int index = rnd.Next(result.Count);
  945. entity.SupplierId = int.Parse(result[index]);
  946. }
  947. }
  948. catch (Exception e)
  949. {
  950. XLog.SaveLog(0, res + "|现货匹配|" + e.Message);
  951. }
  952. if (isCreate)
  953. {
  954. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  955. if (oldRes > 0)
  956. {
  957. entity.IsOldCustomer = 1;
  958. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  959. }
  960. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  961. }
  962. //if (trade != null)
  963. //{
  964. // trade.seller_memo = xianhuoMemo;
  965. // trade.Update();
  966. //}
  967. }
  968. //if (xianhuoMemo.IndexOf("修改文字下单备注") != -1)
  969. //{
  970. // entity.OrderState = Convert.ToInt32(OrderState.待设计); // Convert.ToInt32(OrderState.待设计);
  971. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  972. // entity.WaitDesignTime = DateTime.Now;
  973. // entity.FinishPlaceTime = null;
  974. // entity.SupplierId = 0;
  975. // LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
  976. //}
  977. entity.Create();
  978. CeErpTradeCellExtend.createInfo(entity.ctid);
  979. commonHelper.setSpuData(trade);
  980. }
  981. catch (Exception ex)
  982. {
  983. XLog.SaveLog(0, res + "|cell创建" + ex.Message);
  984. }
  985. }
  986. else
  987. {
  988. if (entity.OrderState == 0 && string.IsNullOrEmpty(entity.seller_memo))
  989. {
  990. isSellerMemoChange = true;
  991. }
  992. }
  993. CeErpTradeCell.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set UpdateTime = getdate() where tid = '{0}'", tObj.refOid));
  994. if (tObj.sellerMemo == "物料")
  995. {
  996. entity.seller_memo = "(" + trade.tid + ")-物料";
  997. entity.OrderState = 6; //下单完成
  998. entity.WaitDesignTime = DateTime.Now;
  999. entity.FinishDesignTime = DateTime.Now;
  1000. entity.StartDesignTime = DateTime.Now;
  1001. entity.FinishPlaceTime = DateTime.Now;
  1002. entity.IsSample = 1;
  1003. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1004. entity.Update();
  1005. }
  1006. //else if (isXianhuo && trade.status== "NOT_SHIPPED")
  1007. //{
  1008. // entity.seller_memo = xianhuoMemo;
  1009. // entity.IsXianHuo = 1;
  1010. // entity.FinishPlaceTime = entity.pay_time;
  1011. // entity.ProductCount = xianhuoProductCount.ToString();
  1012. // if (xianhuoMemo.IndexOf("封酒贴") != -1)
  1013. // {
  1014. // if (trade.buyer_memo != "") //没设计之前
  1015. // {
  1016. // if(entity.OrderState <= 2)
  1017. // {
  1018. // entity.OrderState = 2; //买家有备注的要设计
  1019. // }
  1020. // entity.ProductId = 1;
  1021. // entity.IsXianHuo = 0;
  1022. // xianhuoMemo = xianhuoMemo.Replace("现货", "");
  1023. // xianhuoMemo = xianhuoMemo.Replace(" ", "");
  1024. // entity.seller_memo = xianhuoMemo;
  1025. // }
  1026. // }
  1027. // else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  1028. // {
  1029. // entity.SupplierId = 70; //智涛
  1030. // LogHelper.addLog(entity.ctid,0,"喜字贴纸现货到智涛待发货",0);
  1031. // }
  1032. // entity.Update();
  1033. //}
  1034. if (isSellerMemoChange)
  1035. {
  1036. try
  1037. {
  1038. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  1039. commonHelper.checkIsVipOld(trade);
  1040. }
  1041. catch (Exception ex)
  1042. {
  1043. XLog.SaveLog(0, res + "|2|" + ex);
  1044. }
  1045. }
  1046. }
  1047. public static void Api_TmcTradeMsg_Create(string res)
  1048. {
  1049. Api_tmc_trade_info_Obj fullObj = null;
  1050. if (res == "") return;
  1051. try
  1052. {
  1053. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  1054. //res = res.Replace(" ", "");
  1055. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(res);
  1056. }
  1057. catch (Exception ex)
  1058. {
  1059. XLog.SaveLog(0, res + "|1 create|" + ex.Message);
  1060. throw ex;
  1061. }
  1062. if (fullObj == null)
  1063. {
  1064. XLog.SaveLog(0, "create Api_tmc_trade_info_Obj isNull");
  1065. return;
  1066. }
  1067. Content tObj = fullObj.content;
  1068. List<Api_tmc_trade_info_Obj.LinesItem> orderList = tObj.lines;
  1069. if (tObj.status == "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
  1070. {
  1071. return;
  1072. }
  1073. bool isCreate = false;
  1074. CeErpTrade trade = null;
  1075. trade = CeErpTrade.Get(tObj.refOid);
  1076. if (trade == null)
  1077. {
  1078. isCreate = true;
  1079. trade = new CeErpTrade();
  1080. trade.tid = tObj.refOid;
  1081. trade.type = tObj.refType;
  1082. trade.price = Convert.ToDouble(tObj.totalPrice);
  1083. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  1084. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  1085. trade.created = StampToDateTime(tObj.orderTime);
  1086. if (tObj.payTime != null && tObj.payTime.Length > 0)
  1087. {
  1088. trade.pay_time = StampToDateTime(tObj.payTime);
  1089. }
  1090. if (tObj.posCode != null) trade.posCode = tObj.posCode;
  1091. trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  1092. trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
  1093. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  1094. trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
  1095. if (trade.seller_nick == "")
  1096. {
  1097. trade.seller_nick = getShopNameByECode(trade.posCode);
  1098. }
  1099. trade.payment = Convert.ToDouble(tObj.payment);
  1100. //trade.receiver_name = tObj.receiver_name;
  1101. trade.receiver_state = tObj.receiverState;
  1102. trade.receiver_city = tObj.receiverCity;
  1103. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  1104. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  1105. }
  1106. trade.status = tObj.status;
  1107. //if (tObj.refundStatus == "PART_REFUNDED" || tObj.refundStatus == "ALL_REFUNDED")
  1108. //{
  1109. //}
  1110. trade.seller_flag = tObj.flag;
  1111. if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
  1112. {
  1113. trade.modified = StampToDateTime(tObj.modifyTime);
  1114. }
  1115. if (tObj.finishTime != null && tObj.finishTime.Length > 0)
  1116. {
  1117. trade.end_time = StampToDateTime(tObj.finishTime);
  1118. }
  1119. if (tObj.shippingTime != null && tObj.shippingTime.Length > 0)
  1120. {
  1121. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  1122. }
  1123. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  1124. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  1125. bool isSellerMemoChange = false;
  1126. if (trade.seller_memo != tObj.sellerMemo)
  1127. {
  1128. isSellerMemoChange = true;
  1129. }
  1130. trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo);
  1131. if (isCreate)
  1132. {
  1133. trade.Create();
  1134. }
  1135. else
  1136. {
  1137. trade.Update();
  1138. }
  1139. int xianhuoProductCount = 0;
  1140. bool isXianhuo = false;
  1141. string xianhuoMemo = "(" + trade.tid + ")现货-";
  1142. try
  1143. {
  1144. foreach (Api_tmc_trade_info_Obj.LinesItem item in orderList)
  1145. {
  1146. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
  1147. bool isCreateOrder = false;
  1148. if (order == null)
  1149. {
  1150. order = new CeErpTradeOrder();
  1151. isCreateOrder = true;
  1152. }
  1153. order.tid = trade.tid;
  1154. order.oid = item.refOlId;
  1155. order.buyer_nick = trade.buyer_nick;
  1156. order.refund_status = item.refundStatus;
  1157. order.status = trade.status;
  1158. order.title = item.title;
  1159. order.price = Convert.ToDouble(item.price);
  1160. if (item.picUrl != null)
  1161. order.pic_path = item.picUrl;
  1162. order.num = Convert.ToDouble(item.num.ToString());
  1163. order.payment = Convert.ToDouble(item.price);
  1164. //order.adjust_fee = Convert.ToDouble(item.price);
  1165. if (item.refSkuId != null && item.standards != null && (item.standards.IndexOf("现货") != -1 || item.standards.IndexOf("封酒贴") != -1) && item.standards.IndexOf("定制") == -1)
  1166. {
  1167. order.sku_properties_name = item.standards;
  1168. order.sku_id = item.refSkuId;
  1169. isXianhuo = true;
  1170. xianhuoMemo += order.sku_properties_name;
  1171. xianhuoMemo += ("-数量:" + order.num + "; ");
  1172. xianhuoProductCount += (int)order.num;
  1173. }
  1174. if (isCreateOrder)
  1175. {
  1176. order.Create();
  1177. }
  1178. else
  1179. {
  1180. order.Update();
  1181. }
  1182. }
  1183. }
  1184. catch (Exception ex)
  1185. {
  1186. XLog.SaveLog(0, res + "|create order表:" + ex.Message);
  1187. throw ex;
  1188. }
  1189. //if (isXianhuo)
  1190. //{
  1191. // xianhuoMemo += "-";
  1192. // xianhuoMemo += trade.seller_nick;
  1193. //}
  1194. CeErpTradeCell entity = null;
  1195. entity = CeErpTradeCell.GetByCtid_M(tObj.refOid);
  1196. if (entity == null)
  1197. {
  1198. try
  1199. {
  1200. entity = new CeErpTradeCell();
  1201. entity.ctid = tObj.refOid;
  1202. entity.tid = tObj.refOid;
  1203. entity.seller_memo = "";
  1204. entity.payment = Convert.ToDouble(tObj.payment);
  1205. entity.AfterSalePayment = Convert.ToDouble(tObj.payment);
  1206. if (tObj.payTime != null)
  1207. {
  1208. entity.pay_time = StampToDateTime(tObj.payTime);
  1209. }
  1210. CeErpShop nShop = CeErpShop.GetShopIdByName(tObj.openSellerNick);
  1211. int shopId = 0;
  1212. if (nShop != null)
  1213. {
  1214. shopId = nShop.ID;
  1215. }
  1216. entity.ShopId = shopId;
  1217. if (isXianhuo)
  1218. {
  1219. entity.FinishPlaceTime = DateTime.Now;
  1220. entity.OrderState = 6;
  1221. entity.seller_memo = xianhuoMemo;
  1222. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1223. entity.IsXianHuo = 1;
  1224. if (xianhuoMemo.IndexOf("封酒贴") != -1)
  1225. {
  1226. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);
  1227. if (trade.buyer_memo != "")
  1228. {
  1229. entity.OrderState = 2;
  1230. entity.ProductId = 1;
  1231. entity.IsXianHuo = 0;
  1232. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  1233. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  1234. entity.seller_memo = xianhuoMemo;
  1235. if (entity.ShopId != 0)
  1236. {
  1237. entity.OrderState = orderAudit(entity.ShopId);
  1238. }
  1239. }
  1240. }
  1241. else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  1242. {
  1243. entity.SupplierId = 70;
  1244. }
  1245. entity.FinishPlaceTime = entity.pay_time;
  1246. entity.ProductCount = xianhuoProductCount.ToString();
  1247. if (isCreate)
  1248. {
  1249. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  1250. if (oldRes == 2)
  1251. {
  1252. entity.IsOldCustomer = 1;
  1253. entity.IsOldCustomerMore = 1;
  1254. }
  1255. else if (oldRes == 1)
  1256. {
  1257. entity.IsOldCustomer = 1;
  1258. }
  1259. }
  1260. //if (trade != null)
  1261. //{
  1262. // trade.seller_memo = xianhuoMemo;
  1263. // trade.Update();
  1264. //}
  1265. }
  1266. entity.Create();
  1267. }
  1268. catch (Exception ex)
  1269. {
  1270. XLog.SaveLog(0, res + "|create cell创建" + ex.Message);
  1271. throw ex;
  1272. }
  1273. }
  1274. if (isSellerMemoChange && trade.seller_memo.Length > 0)
  1275. {
  1276. try
  1277. {
  1278. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  1279. }
  1280. catch (Exception ex)
  1281. {
  1282. XLog.SaveLog(0, res + "|2_create|" + ex.Message);
  1283. }
  1284. }
  1285. }
  1286. public static void createCellOrder(CeErpTrade father, string tid, string smemo, string buyer, bool isJump = false)
  1287. {
  1288. smemo = smemo.Replace("\r", " ");
  1289. smemo = smemo.Replace("\n", " ");
  1290. bool isNeedCellOrder = true;
  1291. //try
  1292. //{
  1293. string issql = "select * from ce_erptradecell where tid='" + tid + "';";
  1294. DataTable ishavedt = CeErpTradeCell.ExecuteDataset(issql).Tables[0];
  1295. if (ishavedt.Rows.Count > 0)
  1296. {
  1297. foreach (DataRow hdr in ishavedt.Rows)
  1298. {
  1299. if (smemo.IndexOf("封酒贴") != -1)
  1300. {
  1301. if (Convert.ToInt32(hdr["IsXianHuo"]) == 1 && Convert.ToInt32(hdr["OrderState"]) >= 4)
  1302. {
  1303. isNeedCellOrder = false;
  1304. break;
  1305. }
  1306. else if (Convert.ToInt32(hdr["IsXianHuo"]) == 0 && Convert.ToInt32(hdr["OrderState"]) > 2)
  1307. {
  1308. isNeedCellOrder = false;
  1309. break;
  1310. }
  1311. }
  1312. else if ((Convert.ToInt32(hdr["OrderState"]) > 2 && smemo.IndexOf("礼物") == -1) || (Convert.ToInt32(hdr["OrderState"]) >= 4 && smemo.IndexOf("礼物") != -1) || (Convert.ToInt32(hdr["OrderState"]) >= 4 && smemo.IndexOf("寄样") != -1))
  1313. {
  1314. isNeedCellOrder = false;
  1315. break;
  1316. }
  1317. }
  1318. if (isNeedCellOrder)
  1319. {
  1320. foreach (DataRow hdr in ishavedt.Rows)
  1321. {
  1322. if (hdr["ctid"].ToString().IndexOf("C") != -1)
  1323. {
  1324. string sql_del = "delete from CE_ErpTradeCell where tid='" + tid + "'";
  1325. CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
  1326. break;
  1327. }
  1328. }
  1329. }
  1330. }
  1331. //}
  1332. //catch(Exception ex)
  1333. //{
  1334. // isNeedCellOrder = false;
  1335. // XLog.SaveLog(0, "推送是否需要重新生成判断出错"+ tid + ex.Message);
  1336. //}
  1337. if (isJump)
  1338. {
  1339. isNeedCellOrder = true;
  1340. LogHelper.addLog(tid, 0, "原单强制重新生成", 0);
  1341. }
  1342. //if (smemo.IndexOf("g") != -1)
  1343. //{
  1344. // smemo = smemo.Replace("g", "克");
  1345. //}
  1346. if (smemo.IndexOf("补差价") != -1)
  1347. {
  1348. CeErpTradeCell entity = null;
  1349. entity = CeErpTradeCell.GetByCtid(tid);
  1350. bool ishaveBu = true;
  1351. if (entity == null)
  1352. {
  1353. entity = new CeErpTradeCell();
  1354. entity.ctid = tid;
  1355. //唯一标识
  1356. entity.OrderSn = tid;
  1357. string orderSn = commonHelper.generateDateTimeRandomNos();
  1358. if (orderSn != "")
  1359. {
  1360. entity.OrderSn = orderSn;
  1361. }
  1362. entity.tid = tid;
  1363. ishaveBu = false;
  1364. }
  1365. entity.UpdateTime = DateTime.Now;
  1366. if (entity.ShopId == 0)
  1367. {
  1368. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1369. int shopId = 0;
  1370. if (nShop != null)
  1371. {
  1372. shopId = nShop.ID;
  1373. }
  1374. entity.ShopId = shopId;
  1375. }
  1376. if (father.type != "PDD")
  1377. {
  1378. if (entity.OrderState >= 5) return;
  1379. }
  1380. //entity.seller_memo = smemo;
  1381. entity.payment = Convert.ToDouble(father.payment);
  1382. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  1383. entity.pay_time = father.pay_time;
  1384. smemo = smemo.Replace(":", ":");
  1385. string[] listmemo = smemo.Split(':');
  1386. if (listmemo.Length > 1)
  1387. {
  1388. string maintid = listmemo[1];//System.Text.RegularExpressions.Regex.Replace(listmemo[1], @"[^0-9]+", "");
  1389. string sql = "select top 1 * from ce_erptradecell where tid='" + maintid + "'";
  1390. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  1391. if (dt_bu.Rows.Count > 0)
  1392. {
  1393. entity.ptid = dt_bu.Rows[0]["tid"].ToString();
  1394. if (father.type != "PDD")
  1395. {
  1396. entity.OrderState = Convert.ToInt32(dt_bu.Rows[0]["OrderState"]);
  1397. }
  1398. entity.CustomerUserId = Convert.ToInt32(dt_bu.Rows[0]["CustomerUserId"]);
  1399. entity.DesignUserId = Convert.ToInt32(dt_bu.Rows[0]["DesignUserId"]);
  1400. entity.SupplierId = Convert.ToInt32(dt_bu.Rows[0]["SupplierId"]);
  1401. entity.seller_memo = "补差价:" + entity.ptid;
  1402. entity.payment = father.payment;
  1403. entity.IsSample = 2;
  1404. if (dt_bu.Rows[0]["WaitDesignTime"] != DBNull.Value)
  1405. {
  1406. entity.WaitDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["WaitDesignTime"]);
  1407. }
  1408. if (dt_bu.Rows[0]["StartDesignTime"] != DBNull.Value)
  1409. {
  1410. entity.StartDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["StartDesignTime"]);
  1411. }
  1412. if (dt_bu.Rows[0]["FinishDesignTime"] != DBNull.Value)
  1413. {
  1414. entity.FinishDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishDesignTime"]);
  1415. }
  1416. if (dt_bu.Rows[0]["FinishPlaceTime"] != DBNull.Value)
  1417. {
  1418. entity.FinishPlaceTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishPlaceTime"]);
  1419. }
  1420. }
  1421. }
  1422. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  1423. {
  1424. entity.OrderState = -1;
  1425. entity.DesignUserId = 0;
  1426. entity.WaitDesignTime = null;
  1427. }
  1428. if (ishaveBu)
  1429. {
  1430. entity.Update();
  1431. }
  1432. else
  1433. {
  1434. father.create_time = DateTime.Now;
  1435. father.orderType = 20;
  1436. father.Update();
  1437. entity.Create();
  1438. CeErpTradeCellExtend.createInfo(entity.ctid, 20, 10);
  1439. }
  1440. ApiVo apiVo = new ApiVo();
  1441. apiVo.orderNumber = entity.ptid;
  1442. apiVo.payment = entity.payment;
  1443. apiVo.actionName = "repairDesign";
  1444. designHelper.API_WorkCore(apiVo);//repairDesign
  1445. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  1446. CeErpSukuraData.createInfo(entity.ctid, 1);
  1447. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  1448. isNeedCellOrder = false;
  1449. commonHelper.setSpuData(father);
  1450. }
  1451. else if (smemo.IndexOf("拿样订单") != -1)
  1452. {
  1453. CeErpTradeCell entity = null;
  1454. entity = CeErpTradeCell.GetByCtid(tid);
  1455. if (entity == null)
  1456. {
  1457. if (entity.ShopId == 0)
  1458. {
  1459. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1460. int shopId = 0;
  1461. if (nShop != null)
  1462. {
  1463. shopId = nShop.ID;
  1464. }
  1465. entity.ShopId = shopId;
  1466. }
  1467. entity = new CeErpTradeCell();
  1468. entity.ctid = tid;
  1469. //唯一标识
  1470. entity.OrderSn = tid;
  1471. string orderSn = commonHelper.generateDateTimeRandomNos();
  1472. if (orderSn != "")
  1473. {
  1474. entity.OrderSn = orderSn;
  1475. }
  1476. entity.UpdateTime = DateTime.Now;
  1477. entity.tid = tid;
  1478. entity.seller_memo = smemo;
  1479. entity.payment = Convert.ToDouble(father.payment);
  1480. entity.pay_time = father.pay_time;
  1481. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  1482. entity.OrderState = 6; //下单完成
  1483. entity.FinishPlaceTime = DateTime.Now;
  1484. entity.IsSample = 1;
  1485. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1486. entity.IsOldCustomer = 0;
  1487. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  1488. {
  1489. entity.OrderState = -1;
  1490. entity.DesignUserId = 0;
  1491. entity.WaitDesignTime = null;
  1492. }
  1493. father.create_time = DateTime.Now;
  1494. father.Update();
  1495. entity.Create();
  1496. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  1497. }
  1498. else
  1499. {
  1500. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  1501. {
  1502. entity.OrderState = -1;
  1503. entity.DesignUserId = 0;
  1504. entity.WaitDesignTime = null;
  1505. }
  1506. entity.IsSample = 1;
  1507. entity.UpdateTime = DateTime.Now;
  1508. entity.seller_memo = smemo;
  1509. entity.OrderState = 6;
  1510. entity.FinishPlaceTime = DateTime.Now;
  1511. entity.IsOldCustomer = 0;
  1512. entity.Update();
  1513. }
  1514. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  1515. CeErpSukuraData.createInfo(entity.ctid, 1);
  1516. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  1517. isNeedCellOrder = false;
  1518. commonHelper.setSpuData(father);
  1519. }
  1520. if (isNeedCellOrder == false)
  1521. {
  1522. return;
  1523. }
  1524. if (smemo.IndexOf("*") != -1)
  1525. {
  1526. return;
  1527. }
  1528. if (smemo.IndexOf("{") != -1 && smemo.IndexOf("+") != -1)
  1529. {
  1530. createNewSplitFn(smemo, father);
  1531. return;
  1532. }
  1533. string[] memoList = null;
  1534. if (smemo.IndexOf(",") != -1)
  1535. {
  1536. smemo = smemo.Replace(',', ',');
  1537. }
  1538. if (smemo.IndexOf(",,") != -1)
  1539. {
  1540. return;
  1541. }
  1542. memoList = smemo.Split(',');
  1543. int orderIdx = 1;
  1544. int hebaoCount = 0;
  1545. bool isMulity = false;
  1546. if (memoList.Length > 1)
  1547. {
  1548. isMulity = true;
  1549. foreach (string mstr in memoList)
  1550. {
  1551. if (mstr.IndexOf("合包") != -1)
  1552. {
  1553. hebaoCount += 1;
  1554. }
  1555. }
  1556. }
  1557. if (hebaoCount == 1)
  1558. {
  1559. createHebaoCell(isMulity, 0, smemo, father);
  1560. }
  1561. else
  1562. {
  1563. decimal hePrice = Convert.ToDecimal(father.payment); //合包价格
  1564. string needHebaoItem = "";
  1565. foreach (string item in memoList)
  1566. {
  1567. if (item.IndexOf("合包") != -1)
  1568. {
  1569. needHebaoItem += item;
  1570. needHebaoItem += ",";
  1571. }
  1572. else
  1573. {
  1574. //if (item.IndexOf("电子稿") != -1)
  1575. //{
  1576. // createDianziCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1577. //}
  1578. //else
  1579. if (item.StartsWith("配件-"))
  1580. {
  1581. createPJCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1582. }
  1583. else if (item.IndexOf("logo") != -1 || item.IndexOf("LOGO") != -1)
  1584. {
  1585. createLogoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1586. }
  1587. else if (item.IndexOf("寄样") != -1)
  1588. {
  1589. createDemoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1590. }
  1591. else if (item.IndexOf("礼物") != -1)
  1592. {
  1593. createSmallGiftCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1594. }
  1595. else
  1596. {
  1597. createNotHeBaoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1598. }
  1599. orderIdx = orderIdx + 1;
  1600. }
  1601. }
  1602. bool isHaveHebaoOrder = false;
  1603. if (needHebaoItem.Length > 0)
  1604. {
  1605. isHaveHebaoOrder = true;
  1606. needHebaoItem = needHebaoItem.Substring(0, needHebaoItem.Length - 1);
  1607. createHebaoCell(isMulity, orderIdx, needHebaoItem, father, hePrice);
  1608. orderIdx = orderIdx + 1;
  1609. }
  1610. if (orderIdx > 2)
  1611. {
  1612. try
  1613. {
  1614. string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "';";
  1615. LogHelper.addLog(tid, 0, "delete ctid=tid orderidx=" + orderIdx, 0);
  1616. if (System.Math.Abs(hePrice) > Convert.ToDecimal(0.01) && hePrice != Convert.ToDecimal(father.payment) && isHaveHebaoOrder == false)
  1617. {
  1618. sql_del += "update CE_ErpTradeCell with(rowlock) set orderstate=0 where tid='" + tid + "';";
  1619. LogHelper.addLog(tid, 0, "拆分金额相加与总金额不等", 0);
  1620. }
  1621. CeErpTradeCell.ExecuteNonQuery(sql_del);
  1622. }
  1623. catch (Exception ex)
  1624. {
  1625. XLog.SaveLog(0, tid + "|删除首单错误|" + ex.Message);
  1626. string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "';";
  1627. CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
  1628. }
  1629. }
  1630. commonHelper.setSpuData(father);
  1631. //autoCell(tid);
  1632. }
  1633. }
  1634. public static void createNewSplitFn(string smemo, CeErpTrade father)
  1635. {
  1636. if (smemo.IndexOf("合包") != -1)
  1637. {
  1638. createHebaoCell(false, 0, smemo, father);
  1639. }
  1640. else
  1641. {
  1642. int firstDaKuoHaoCount = 0;
  1643. string firstoneContent = commonHelper.MidStrEx(smemo, "{", "}");
  1644. string[] oneElementList = firstoneContent.Split('+');
  1645. firstDaKuoHaoCount = oneElementList.Length;
  1646. string[] memoList = smemo.Split('-');
  1647. for (int idx = 0; idx < firstDaKuoHaoCount; idx++)
  1648. {
  1649. string newMemoStr = "";
  1650. foreach (string oneStr in memoList)
  1651. {
  1652. string oneContent = "";
  1653. if (oneStr.IndexOf("{") != -1)
  1654. {
  1655. oneContent = commonHelper.MidStrEx(oneStr, "{", "}");
  1656. string[] oneList = oneContent.Split('+');
  1657. if (oneList.Length != firstDaKuoHaoCount)
  1658. {
  1659. XLog.SaveLog(0, father.tid + ",备注大括号内的元素个数不相等");
  1660. return;
  1661. }
  1662. newMemoStr += oneList[idx];
  1663. }
  1664. else
  1665. newMemoStr += oneStr;
  1666. newMemoStr += "-";
  1667. }
  1668. newMemoStr = newMemoStr.Substring(0, newMemoStr.Length - 1);
  1669. if (idx == 0)
  1670. createNewSplitCell(true, idx + 1, newMemoStr, father, father.payment - firstDaKuoHaoCount * 0.1, firstDaKuoHaoCount);
  1671. else
  1672. createNewSplitCell(true, idx + 1, newMemoStr, father, 0.1, firstDaKuoHaoCount);
  1673. }
  1674. try
  1675. {
  1676. string sql_del = "delete from CE_ErpTradeCell where ctid='" + father.tid + "'";
  1677. CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
  1678. LogHelper.addLog(father.tid, 0, "新拆分方法 delete ctid=tid ", 0);
  1679. }
  1680. catch (Exception ex)
  1681. {
  1682. XLog.SaveLog(0, "|新拆分删除首单错误|" + ex.Message);
  1683. }
  1684. }
  1685. }
  1686. public static void createLogoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  1687. {
  1688. if (itemMemo.Length <= 0) return;
  1689. string ctid = "";
  1690. string splitTag = "";
  1691. if (isMulty && itemMemo.Length > 2)
  1692. {
  1693. string preStr = "C" + orderIndex + "_";
  1694. ctid = preStr + father.tid;
  1695. splitTag = "C" + orderIndex;
  1696. }
  1697. else if (itemMemo.Length > 2)
  1698. {
  1699. ctid = father.tid;
  1700. }
  1701. CeErpTradeCell entity = null;
  1702. entity = CeErpTradeCell.GetByCtid(ctid);
  1703. bool isNull = false;
  1704. if (entity == null)
  1705. {
  1706. entity = new CeErpTradeCell();
  1707. isNull = true;
  1708. entity.ctid = ctid;
  1709. //唯一标识
  1710. entity.OrderSn = ctid;
  1711. string orderSn = commonHelper.generateDateTimeRandomNos();
  1712. if (orderSn != "")
  1713. {
  1714. entity.OrderSn = orderSn;
  1715. }
  1716. }
  1717. entity.UpdateTime = DateTime.Now;
  1718. entity.tid = father.tid;
  1719. entity.SplitTag = splitTag;
  1720. if (entity.ShopId == 0)
  1721. {
  1722. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1723. int shopId = 0;
  1724. if (nShop != null)
  1725. {
  1726. shopId = nShop.ID;
  1727. }
  1728. entity.ShopId = shopId;
  1729. }
  1730. if (entity.IsSample == 1 || entity.IsSample == 2)
  1731. {
  1732. entity.IsSample = 0;
  1733. entity.ptid = "";
  1734. }
  1735. if (entity.isDianziOrder == 1)
  1736. {
  1737. entity.isDianziOrder = 0;
  1738. }
  1739. string[] acclist = itemMemo.Split('-');
  1740. if (acclist.Length < 4) return;
  1741. string count = acclist[0];
  1742. string product = acclist[1];
  1743. string account = acclist[3];
  1744. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  1745. if (cusInfo != null)
  1746. {
  1747. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  1748. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  1749. {
  1750. }
  1751. else
  1752. {
  1753. entity.OrderState = 2;
  1754. if (entity.ShopId != 0)
  1755. {
  1756. entity.OrderState = orderAudit(entity.ShopId);
  1757. }
  1758. }
  1759. }
  1760. entity.ProductId = getProductIdByName("logo");
  1761. if (entity.ProductId == 0)
  1762. {
  1763. return;
  1764. }
  1765. entity.ProductCount = commonHelper.getProductCount(count);// commonHelper.changeCountFromChiness(count); ;
  1766. if (isMulty)
  1767. {
  1768. try
  1769. {
  1770. string strPrice = acclist[4];
  1771. if (strPrice.IndexOf("元") != -1)
  1772. {
  1773. strPrice = strPrice.Replace("元", "");
  1774. }
  1775. entity.payment = Convert.ToDouble(strPrice);
  1776. hePrice = hePrice - Convert.ToDecimal(acclist[4]);
  1777. }
  1778. catch (Exception ex)
  1779. {
  1780. }
  1781. }
  1782. else
  1783. {
  1784. entity.payment = Convert.ToDouble(father.payment);
  1785. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  1786. }
  1787. string newmemo = "(" + entity.OrderSn + ")-";
  1788. string newOtherMemo = "";
  1789. for (int i = 0; i < acclist.Length; i++)
  1790. {
  1791. if (i == 3) continue;
  1792. if (i >= 4)
  1793. {
  1794. newOtherMemo += acclist[i];
  1795. }
  1796. else
  1797. newmemo += acclist[i];
  1798. if (i < acclist.Length - 2)
  1799. {
  1800. newmemo += "-";
  1801. }
  1802. }
  1803. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  1804. newmemo += ("-" + sName);
  1805. if (father.buyer_nick.IndexOf("*") < 0)
  1806. {
  1807. newmemo += ("-" + father.buyer_nick);
  1808. }
  1809. newmemo += ("-" + father.receiver_state);
  1810. if (cusInfo != null)
  1811. {
  1812. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  1813. }
  1814. if (isMulty)
  1815. {
  1816. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  1817. }
  1818. if (itemMemo.IndexOf("顺丰到付") != -1)
  1819. {
  1820. if (newmemo.IndexOf("顺丰到付") == -1)
  1821. newmemo += ("-顺丰到付");
  1822. entity.IsSF = 2;
  1823. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  1824. }
  1825. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  1826. {
  1827. if (newmemo.IndexOf("顺丰寄付") == -1)
  1828. newmemo += ("-顺丰寄付");
  1829. entity.IsSF = 1;
  1830. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  1831. }
  1832. if (itemMemo.IndexOf("加急") != -1)
  1833. {
  1834. if (newmemo.IndexOf("加急") == -1)
  1835. newmemo += ("-加急");
  1836. entity.IsUrgency = true;
  1837. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  1838. }
  1839. entity.seller_memo = newmemo;
  1840. entity.OtherMemo = newOtherMemo;
  1841. entity.pay_time = father.pay_time;
  1842. //int oldRes = isOldAndInsertCustomerInfo(father, entity);
  1843. //if (oldRes>0)
  1844. //{
  1845. // entity.IsOldCustomer = 1;
  1846. // if (oldRes == 2)
  1847. // {
  1848. // entity.IsOldCustomer = 1;
  1849. // entity.IsOldCustomerMore = 1;
  1850. // }
  1851. //}
  1852. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  1853. {
  1854. }
  1855. else
  1856. {
  1857. if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
  1858. {
  1859. entity.IsOldCustomer = 0;
  1860. }
  1861. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  1862. if (oldRes > 0)
  1863. {
  1864. entity.IsOldCustomer = 1;
  1865. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  1866. int curHour = DateTime.Now.Hour;
  1867. int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
  1868. if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  1869. {
  1870. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
  1871. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1872. entity.DesignUserId = initSysDesignerId;
  1873. entity.WaitDesignTime = DateTime.Now;
  1874. }
  1875. else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  1876. {
  1877. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  1878. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1879. entity.DesignUserId = initSysDesignerId;
  1880. entity.WaitDesignTime = DateTime.Now;
  1881. }
  1882. else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  1883. {
  1884. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
  1885. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1886. entity.DesignUserId = initSysDesignerId;
  1887. entity.WaitDesignTime = DateTime.Now;
  1888. }
  1889. else
  1890. {
  1891. CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
  1892. if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
  1893. {
  1894. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1895. entity.DesignUserId = initSysDesignerId;
  1896. entity.WaitDesignTime = DateTime.Now;
  1897. }
  1898. }
  1899. }
  1900. }
  1901. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  1902. {
  1903. entity.OrderState = -1;
  1904. entity.DesignUserId = 0;
  1905. entity.WaitDesignTime = null;
  1906. }
  1907. if (entity.ProductId > 0)
  1908. {
  1909. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  1910. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  1911. {
  1912. entity.NewProduct = 1;
  1913. }
  1914. bool size_result = commonHelper.interceptionSizeUnit(entity.ProductSize, ceErpProduct);
  1915. if (!size_result)
  1916. {
  1917. entity.OrderState = 0;
  1918. CeErpMessageTip ct = new CeErpMessageTip();
  1919. ct.tid = entity.tid;
  1920. ct.sectionId = 0;
  1921. ct.userId = entity.CustomerUserId;
  1922. ct.type = 3;
  1923. ct.isVisit = false;
  1924. ct.content = entity.tid + ",领单尺寸单位不符合规范,尺寸单位为:" + ceErpProduct.SizeUnit;
  1925. ct.Create();
  1926. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "尺寸单位不符合规范!" + entity.seller_memo, entity.OrderState);
  1927. }
  1928. }
  1929. if (isNull)
  1930. {
  1931. father.create_time = DateTime.Now;
  1932. father.Update();
  1933. entity.Create();
  1934. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  1935. }
  1936. else
  1937. {
  1938. entity.Update();
  1939. }
  1940. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  1941. CeErpSukuraData.createInfo(entity.ctid, 1);
  1942. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "logo推送生成" + entity.seller_memo, entity.OrderState);
  1943. }
  1944. public static void createDianziCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  1945. {
  1946. if (itemMemo.Length <= 0) return;
  1947. string ctid = "";
  1948. string splitTag = "";
  1949. if (isMulity && itemMemo.Length > 2)
  1950. {
  1951. string preStr = "C" + orderIndex + "_";
  1952. ctid = preStr + father.tid;
  1953. splitTag = "C" + orderIndex;
  1954. }
  1955. else if (itemMemo.Length > 2)
  1956. {
  1957. ctid = father.tid;
  1958. }
  1959. CeErpTradeCell entity = null;
  1960. entity = CeErpTradeCell.GetByCtid(ctid);
  1961. bool isNull = false;
  1962. if (entity == null)
  1963. {
  1964. entity = new CeErpTradeCell();
  1965. isNull = true;
  1966. }
  1967. entity.ctid = ctid;
  1968. entity.tid = father.tid;
  1969. entity.SplitTag = splitTag;
  1970. if (entity.ShopId == 0)
  1971. {
  1972. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1973. int shopId = 0;
  1974. if (nShop != null)
  1975. {
  1976. shopId = nShop.ID;
  1977. }
  1978. entity.ShopId = shopId;
  1979. }
  1980. if (entity.IsSample == 1 || entity.IsSample == 2)
  1981. {
  1982. entity.IsSample = 0;
  1983. entity.ptid = "";
  1984. }
  1985. if (entity.isDianziOrder == 1)
  1986. {
  1987. entity.isDianziOrder = 0;
  1988. }
  1989. string[] acclist = itemMemo.Split('-');
  1990. if (acclist.Length < 4) return;
  1991. string count = acclist[0];
  1992. string product = acclist[1];
  1993. string account = acclist[3];
  1994. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  1995. if (cusInfo != null)
  1996. {
  1997. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  1998. }
  1999. if (entity.OrderState < 3 && entity.DesignUserId == 0)
  2000. {
  2001. entity.OrderState = Convert.ToInt32(OrderState.待抢单);
  2002. //entity.OrderState = Convert.ToInt32(OrderState.待设计);
  2003. //entity.DesignUserId = 255; //电子稿给亿佳设计
  2004. //entity.WaitDesignTime = DateTime.Now;
  2005. }
  2006. entity.ProductId = getProductIdByName(product);
  2007. if (entity.ProductId == 0)
  2008. {
  2009. return;
  2010. }
  2011. entity.ProductCount = commonHelper.getProductCount(count); ;// commonHelper.changeCountFromChiness(count); ;
  2012. entity.isDianziOrder = 1;//电子稿
  2013. entity.pay_time = father.pay_time;
  2014. if (isMulity)
  2015. {
  2016. try
  2017. {
  2018. string strPrice = acclist[4];
  2019. if (strPrice.IndexOf("元") != -1)
  2020. {
  2021. strPrice = strPrice.Replace("元", "");
  2022. }
  2023. entity.payment = Convert.ToDouble(strPrice);
  2024. hePrice = hePrice - Convert.ToDecimal(acclist[4]);
  2025. }
  2026. catch (Exception ex)
  2027. {
  2028. //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  2029. }
  2030. }
  2031. else
  2032. {
  2033. entity.payment = Convert.ToDouble(father.payment);
  2034. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  2035. }
  2036. string newmemo = "(" + entity.tid + ")-";
  2037. string newOtherMemo = "";
  2038. for (int i = 0; i < acclist.Length; i++)
  2039. {
  2040. if (i == 3) continue;
  2041. newmemo += acclist[i];
  2042. if (i < acclist.Length - 2)
  2043. {
  2044. newmemo += "-";
  2045. }
  2046. }
  2047. string sName = getShopSNameByName(father.seller_nick);
  2048. newmemo += ("-" + sName);
  2049. if (father.buyer_nick.IndexOf("*") < 0)
  2050. {
  2051. newmemo += ("-" + father.buyer_nick);
  2052. }
  2053. newmemo += ("-" + father.receiver_state);
  2054. if (cusInfo != null)
  2055. {
  2056. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2057. }
  2058. if (isMulity)
  2059. {
  2060. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2061. }
  2062. entity.seller_memo = newmemo;
  2063. entity.OtherMemo = newOtherMemo;
  2064. //int oldRes = isOldAndInsertCustomerInfo(father, entity);
  2065. //if (oldRes > 0)
  2066. //{
  2067. // entity.IsOldCustomer = 1;
  2068. // if (oldRes == 2)
  2069. // {
  2070. // entity.IsOldCustomer = 1;
  2071. // entity.IsOldCustomerMore = 1;
  2072. // }
  2073. //}
  2074. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2075. {
  2076. }
  2077. else
  2078. {
  2079. entity.IsOldCustomer = 0;
  2080. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  2081. if (oldRes > 0)
  2082. {
  2083. entity.IsOldCustomer = 1;
  2084. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  2085. dealOldCustomerEntityAuto(ref entity);
  2086. }
  2087. }
  2088. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  2089. {
  2090. entity.OrderState = -1;
  2091. entity.DesignUserId = 0;
  2092. entity.WaitDesignTime = null;
  2093. }
  2094. if (entity.ProductId > 0)
  2095. {
  2096. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  2097. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  2098. {
  2099. entity.NewProduct = 1;
  2100. }
  2101. bool size_result = commonHelper.interceptionSizeUnit(entity.ProductSize, ceErpProduct);
  2102. if (!size_result)
  2103. {
  2104. entity.OrderState = 0;
  2105. CeErpMessageTip ct = new CeErpMessageTip();
  2106. ct.tid = entity.tid;
  2107. ct.sectionId = 0;
  2108. ct.userId = entity.CustomerUserId;
  2109. ct.type = 3;
  2110. ct.isVisit = false;
  2111. ct.content = entity.tid + ",领单尺寸单位不符合规范,尺寸单位为:" + ceErpProduct.SizeUnit;
  2112. ct.Create();
  2113. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "尺寸单位不符合规范!" + entity.seller_memo, entity.OrderState);
  2114. }
  2115. }
  2116. if (isNull)
  2117. {
  2118. father.create_time = DateTime.Now;
  2119. father.Update();
  2120. entity.Create();
  2121. }
  2122. else
  2123. {
  2124. entity.Update();
  2125. }
  2126. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2127. CeErpSukuraData.createInfo(entity.ctid, 1);
  2128. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "电子稿推送生成" + entity.seller_memo, entity.OrderState);
  2129. }
  2130. public static void createPJCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  2131. {
  2132. if (itemMemo.Length <= 0) return;
  2133. string ctid = "";
  2134. string splitTag = "";
  2135. if (isMulty && itemMemo.Length > 2)
  2136. {
  2137. string preStr = "C" + orderIndex + "_";
  2138. ctid = preStr + father.tid;
  2139. splitTag = "C" + orderIndex;
  2140. }
  2141. else if (itemMemo.Length > 2)
  2142. {
  2143. ctid = father.tid;
  2144. }
  2145. CeErpTradeCell entity = null;
  2146. entity = CeErpTradeCell.GetByCtid(ctid);
  2147. bool isNull = false;
  2148. if (entity == null)
  2149. {
  2150. entity = new CeErpTradeCell();
  2151. isNull = true;
  2152. entity.ctid = ctid;
  2153. //唯一标识
  2154. entity.OrderSn = ctid;
  2155. string orderSn = commonHelper.generateDateTimeRandomNos();
  2156. if (orderSn != "")
  2157. {
  2158. entity.OrderSn = orderSn;
  2159. }
  2160. }
  2161. entity.UpdateTime = DateTime.Now;
  2162. entity.tid = father.tid;
  2163. entity.SplitTag = splitTag;
  2164. if (entity.ShopId == 0)
  2165. {
  2166. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2167. int shopId = 0;
  2168. if (nShop != null)
  2169. {
  2170. shopId = nShop.ID;
  2171. }
  2172. entity.ShopId = shopId;
  2173. }
  2174. entity.IsSample = 4;
  2175. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2176. entity.isDianziOrder = 0;
  2177. string[] acclist = itemMemo.Split('-');
  2178. //配件-80x80mm-200张-卡片-甘露
  2179. if (acclist.Length <= 4) return;
  2180. //string count = acclist[0];
  2181. string product = acclist[3];
  2182. string account = acclist[4];
  2183. DataRow cusInfo = getUserInfoByAccount(account);
  2184. if (cusInfo != null)
  2185. {
  2186. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2187. if (entity.OrderState > 6)
  2188. {
  2189. }
  2190. else
  2191. {
  2192. entity.OrderState = Convert.ToInt32(OrderState.设计完成);
  2193. }
  2194. }
  2195. entity.ProductId = 2716;
  2196. if (entity.ProductId == 0)
  2197. {
  2198. return;
  2199. }
  2200. if (isMulty)
  2201. {
  2202. try
  2203. {
  2204. string strPrice = acclist[5];
  2205. if (strPrice.IndexOf("元") != -1)
  2206. {
  2207. strPrice = strPrice.Replace("元", "");
  2208. }
  2209. entity.payment = Convert.ToDouble(strPrice);
  2210. hePrice = hePrice - Convert.ToDecimal(strPrice);
  2211. }
  2212. catch (Exception ex)
  2213. {
  2214. //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  2215. }
  2216. }
  2217. else
  2218. {
  2219. entity.payment = Convert.ToDouble(father.payment);
  2220. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  2221. }
  2222. string newmemo = "(" + entity.OrderSn + ")-";
  2223. string newOtherMemo = "";
  2224. List<string> list = new List<string>();
  2225. for (int i = 0; i < acclist.Length; i++)
  2226. {
  2227. //配件-80x80mm-200张-卡片-甘露
  2228. if (i == 4) continue;
  2229. if (isMulty)
  2230. {
  2231. if (i == 5) continue;
  2232. }
  2233. list.Add(acclist[i]);
  2234. }
  2235. newmemo += string.Join("-", list);
  2236. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  2237. newmemo += ("-" + sName);
  2238. if (father.buyer_nick.IndexOf("*") < 0)
  2239. {
  2240. newmemo += ("-" + father.buyer_nick);
  2241. }
  2242. newmemo += ("-" + father.receiver_state);
  2243. if (cusInfo != null)
  2244. {
  2245. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2246. }
  2247. if (isMulty)
  2248. {
  2249. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2250. }
  2251. if (itemMemo.IndexOf("顺丰到付") != -1)
  2252. {
  2253. if (newmemo.IndexOf("顺丰到付") == -1)
  2254. newmemo += ("-顺丰到付");
  2255. entity.IsSF = 2;
  2256. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2257. }
  2258. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2259. {
  2260. if (newmemo.IndexOf("顺丰寄付") == -1)
  2261. newmemo += ("-顺丰寄付");
  2262. entity.IsSF = 1;
  2263. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2264. }
  2265. if (itemMemo.IndexOf("加急") != -1)
  2266. {
  2267. if (newmemo.IndexOf("加急") == -1)
  2268. newmemo += ("-加急");
  2269. entity.IsUrgency = true;
  2270. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2271. }
  2272. entity.seller_memo = newmemo;
  2273. entity.OtherMemo = newOtherMemo;
  2274. entity.pay_time = father.pay_time;
  2275. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  2276. LogHelper.addLog(entity.ctid, 0, "配件单指派到下单部" + entity.DesignUserId, entity.OrderState);
  2277. entity.FinishDesignTime = DateTime.Now;
  2278. entity.StartDesignTime = DateTime.Now;
  2279. entity.WaitDesignTime = DateTime.Now;
  2280. entity.IsOldCustomer = 0;
  2281. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  2282. if (oldRes > 0)
  2283. {
  2284. entity.IsOldCustomer = 1;
  2285. if (oldRes == 2)
  2286. {
  2287. entity.IsOldCustomer = 1;
  2288. entity.IsOldCustomerMore = 1;
  2289. }
  2290. }
  2291. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  2292. {
  2293. entity.OrderState = -1;
  2294. entity.DesignUserId = 0;
  2295. entity.WaitDesignTime = null;
  2296. }
  2297. if (entity.ProductId > 0)
  2298. {
  2299. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  2300. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  2301. {
  2302. entity.NewProduct = 1;
  2303. }
  2304. }
  2305. if (isNull)
  2306. {
  2307. father.create_time = DateTime.Now;
  2308. father.Update();
  2309. entity.Create();
  2310. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  2311. }
  2312. else
  2313. {
  2314. entity.Update();
  2315. }
  2316. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2317. CeErpSukuraData.createInfo(entity.ctid, 1);
  2318. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "配件推送生成" + entity.seller_memo, entity.OrderState);
  2319. }
  2320. public static void createDemoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  2321. {
  2322. if (itemMemo.Length <= 0) return;
  2323. string ctid = "";
  2324. string splitTag = "";
  2325. if (isMulty && itemMemo.Length > 2)
  2326. {
  2327. string preStr = "C" + orderIndex + "_";
  2328. ctid = preStr + father.tid;
  2329. splitTag = "C" + orderIndex;
  2330. }
  2331. else if (itemMemo.Length > 2)
  2332. {
  2333. ctid = father.tid;
  2334. }
  2335. CeErpTradeCell entity = null;
  2336. entity = CeErpTradeCell.GetByCtid(ctid);
  2337. bool isNull = false;
  2338. if (entity == null)
  2339. {
  2340. entity = new CeErpTradeCell();
  2341. isNull = true;
  2342. entity.ctid = ctid;
  2343. //唯一标识
  2344. entity.OrderSn = ctid;
  2345. string orderSn = commonHelper.generateDateTimeRandomNos();
  2346. if (orderSn != "")
  2347. {
  2348. entity.OrderSn = orderSn;
  2349. }
  2350. }
  2351. entity.UpdateTime = DateTime.Now;
  2352. entity.tid = father.tid;
  2353. entity.SplitTag = splitTag;
  2354. if (entity.ShopId == 0)
  2355. {
  2356. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2357. int shopId = 0;
  2358. if (nShop != null)
  2359. {
  2360. shopId = nShop.ID;
  2361. }
  2362. entity.ShopId = shopId;
  2363. }
  2364. entity.IsSample = 3;
  2365. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2366. if (entity.isDianziOrder == 1)
  2367. {
  2368. entity.isDianziOrder = 0;
  2369. }
  2370. string[] acclist = itemMemo.Split('-');
  2371. if (acclist.Length <= 3) return;
  2372. //string count = acclist[0];
  2373. string product = acclist[1];
  2374. string account = acclist[3];
  2375. DataRow cusInfo = getUserInfoByAccount(account);
  2376. if (cusInfo != null)
  2377. {
  2378. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2379. if (entity.OrderState > 6)
  2380. {
  2381. }
  2382. else
  2383. {
  2384. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  2385. }
  2386. }
  2387. entity.ProductId = getProductIdByName(product);
  2388. if (entity.ProductId == 0)
  2389. {
  2390. return;
  2391. }
  2392. if (isMulty)
  2393. {
  2394. try
  2395. {
  2396. string strPrice = acclist[4];
  2397. if (strPrice.IndexOf("元") != -1)
  2398. {
  2399. strPrice = strPrice.Replace("元", "");
  2400. }
  2401. entity.payment = Convert.ToDouble(strPrice);
  2402. hePrice = hePrice - Convert.ToDecimal(strPrice);
  2403. }
  2404. catch (Exception ex)
  2405. {
  2406. //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  2407. }
  2408. }
  2409. else
  2410. {
  2411. entity.payment = Convert.ToDouble(father.payment);
  2412. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  2413. }
  2414. string newmemo = "(" + entity.OrderSn + ")-";
  2415. string newOtherMemo = "";
  2416. List<string> list = new List<string>();
  2417. for (int i = 0; i < acclist.Length; i++)
  2418. {
  2419. if (i == 3) continue;
  2420. if (isMulty)
  2421. {
  2422. if (i == 4) continue;
  2423. }
  2424. list.Add(acclist[i]);
  2425. }
  2426. newmemo += string.Join("-", list);
  2427. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  2428. newmemo += ("-" + sName);
  2429. if (father.buyer_nick.IndexOf("*") < 0)
  2430. {
  2431. newmemo += ("-" + father.buyer_nick);
  2432. }
  2433. newmemo += ("-" + father.receiver_state);
  2434. if (cusInfo != null)
  2435. {
  2436. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2437. }
  2438. if (isMulty)
  2439. {
  2440. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2441. }
  2442. if (itemMemo.IndexOf("顺丰到付") != -1)
  2443. {
  2444. if (newmemo.IndexOf("顺丰到付") == -1)
  2445. newmemo += ("-顺丰到付");
  2446. entity.IsSF = 2;
  2447. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2448. }
  2449. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2450. {
  2451. if (newmemo.IndexOf("顺丰寄付") == -1)
  2452. newmemo += ("-顺丰寄付");
  2453. entity.IsSF = 1;
  2454. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2455. }
  2456. if (itemMemo.IndexOf("加急") != -1)
  2457. {
  2458. if (newmemo.IndexOf("加急") == -1)
  2459. newmemo += ("-加急");
  2460. entity.IsUrgency = true;
  2461. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2462. }
  2463. entity.seller_memo = newmemo;
  2464. entity.OtherMemo = newOtherMemo;
  2465. entity.pay_time = father.pay_time;
  2466. entity.FinishDesignTime = DateTime.Now;
  2467. entity.StartDesignTime = DateTime.Now;
  2468. entity.WaitDesignTime = DateTime.Now;
  2469. entity.FinishPlaceTime = DateTime.Now;
  2470. entity.IsOldCustomer = 0;
  2471. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  2472. if (oldRes > 0)
  2473. {
  2474. entity.IsOldCustomer = 1;
  2475. if (oldRes == 2)
  2476. {
  2477. entity.IsOldCustomer = 1;
  2478. entity.IsOldCustomerMore = 1;
  2479. }
  2480. }
  2481. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  2482. {
  2483. entity.OrderState = -1;
  2484. entity.DesignUserId = 0;
  2485. entity.WaitDesignTime = null;
  2486. }
  2487. if (entity.ProductId > 0)
  2488. {
  2489. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  2490. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  2491. {
  2492. entity.NewProduct = 1;
  2493. }
  2494. }
  2495. if (isNull)
  2496. {
  2497. father.create_time = DateTime.Now;
  2498. father.Update();
  2499. entity.Create();
  2500. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  2501. }
  2502. else
  2503. {
  2504. entity.Update();
  2505. }
  2506. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2507. CeErpSukuraData.createInfo(entity.ctid, 1);
  2508. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "寄样推送生成" + entity.seller_memo, entity.OrderState);
  2509. }
  2510. public static void createSmallGiftCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  2511. {
  2512. if (itemMemo.Length <= 0) return;
  2513. string ctid = "";
  2514. string splitTag = "";
  2515. if (isMulty && itemMemo.Length > 2)
  2516. {
  2517. string preStr = "C" + orderIndex + "_";
  2518. ctid = preStr + father.tid;
  2519. splitTag = "C" + orderIndex;
  2520. }
  2521. else if (itemMemo.Length > 2)
  2522. {
  2523. ctid = father.tid;
  2524. }
  2525. CeErpTradeCell entity = null;
  2526. entity = CeErpTradeCell.GetByCtid(ctid);
  2527. bool isNull = false;
  2528. if (entity == null)
  2529. {
  2530. entity = new CeErpTradeCell();
  2531. isNull = true;
  2532. }
  2533. if (entity.OrderState > 6) return;
  2534. if (entity.ShopId == 0)
  2535. {
  2536. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2537. int shopId = 0;
  2538. if (nShop != null)
  2539. {
  2540. shopId = nShop.ID;
  2541. }
  2542. entity.ShopId = shopId;
  2543. }
  2544. if (entity.IsSample == 1 || entity.IsSample == 2)
  2545. {
  2546. entity.IsSample = 0;
  2547. entity.ptid = "";
  2548. }
  2549. if (entity.isDianziOrder == 1)
  2550. {
  2551. entity.isDianziOrder = 0;
  2552. }
  2553. entity.ctid = ctid;
  2554. if (string.IsNullOrEmpty(entity.OrderSn))
  2555. {
  2556. //唯一标识
  2557. string orderSn = commonHelper.generateDateTimeRandomNos();
  2558. if (orderSn != "")
  2559. {
  2560. entity.OrderSn = orderSn;
  2561. }
  2562. }
  2563. entity.UpdateTime = DateTime.Now;
  2564. entity.tid = father.tid;
  2565. entity.SplitTag = splitTag;
  2566. string[] acclist = itemMemo.Split('-');
  2567. if (acclist.Length < 2) return;
  2568. if (itemMemo.Contains("插牌") || itemMemo.Contains("插排"))
  2569. {
  2570. return;
  2571. }
  2572. string product = acclist[0];
  2573. string account = acclist[1];
  2574. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  2575. if (cusInfo != null)
  2576. {
  2577. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2578. }
  2579. entity.IsOldCustomer = 0;
  2580. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  2581. entity.IsXianHuo = 1;
  2582. entity.IsGift = 1;
  2583. entity.FinishPlaceTime = father.pay_time;
  2584. if (entity.OrderState < 6)
  2585. {
  2586. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  2587. }
  2588. if (isMulty)
  2589. {
  2590. try
  2591. {
  2592. string strPrice = acclist[2];
  2593. if (strPrice.IndexOf("元") != -1)
  2594. {
  2595. strPrice = strPrice.Replace("元", "");
  2596. }
  2597. entity.payment = Convert.ToDouble(strPrice);
  2598. hePrice = hePrice - Convert.ToDecimal(acclist[2]);
  2599. }
  2600. catch (Exception ex)
  2601. {
  2602. //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  2603. }
  2604. }
  2605. else
  2606. {
  2607. entity.payment = Convert.ToDouble(father.payment);
  2608. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  2609. }
  2610. string newmemo = "(" + entity.OrderSn + ")-";
  2611. string newOtherMemo = "";
  2612. for (int i = 0; i < acclist.Length; i++)
  2613. {
  2614. if (i == 1) continue;
  2615. newmemo += acclist[i];
  2616. if (i < acclist.Length - 1)
  2617. {
  2618. newmemo += "-";
  2619. }
  2620. }
  2621. string sName = getShopSNameByName(father.seller_nick);
  2622. newmemo += ("" + sName);
  2623. newmemo += ("-" + father.buyer_nick);
  2624. newmemo += ("-" + father.receiver_state);
  2625. if (cusInfo != null)
  2626. {
  2627. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2628. }
  2629. if (isMulty)
  2630. {
  2631. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2632. }
  2633. if (newmemo.IndexOf("现货") != -1)
  2634. {
  2635. newmemo = newmemo.Replace("礼物", "");
  2636. }
  2637. if (itemMemo.IndexOf("顺丰到付") != -1)
  2638. {
  2639. newmemo += ("-顺丰到付");
  2640. entity.IsSF = 2;
  2641. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2642. }
  2643. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2644. {
  2645. newmemo += ("-顺丰寄付");
  2646. entity.IsSF = 1;
  2647. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2648. }
  2649. if (itemMemo.IndexOf("加急") != -1)
  2650. {
  2651. newmemo += ("-加急");
  2652. entity.IsUrgency = true;
  2653. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2654. }
  2655. entity.seller_memo = newmemo;
  2656. entity.OtherMemo = newOtherMemo;
  2657. entity.pay_time = father.pay_time;
  2658. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  2659. {
  2660. entity.OrderState = -1;
  2661. entity.DesignUserId = 0;
  2662. entity.WaitDesignTime = null;
  2663. }
  2664. if (entity.ProductId > 0)
  2665. {
  2666. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  2667. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  2668. {
  2669. entity.NewProduct = 1;
  2670. }
  2671. }
  2672. if (isNull)
  2673. {
  2674. father.create_time = DateTime.Now;
  2675. father.Update();
  2676. entity.Create();
  2677. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  2678. }
  2679. else
  2680. {
  2681. entity.Update();
  2682. }
  2683. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2684. CeErpSukuraData.createInfo(entity.ctid, 1);
  2685. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "礼物推送生成" + entity.seller_memo, entity.OrderState);
  2686. }
  2687. public static void createHebaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, decimal hePrice = 0)
  2688. {
  2689. if (itemMemo.Length <= 0) return;
  2690. string[] hebaoMemoList = itemMemo.Split(',');
  2691. string memo_index1 = hebaoMemoList[0];
  2692. string ctid = "";
  2693. string splitTag = "";
  2694. if (isMulity && orderIndex > 1 && itemMemo.Length > 2)
  2695. {
  2696. string preStr = "C" + orderIndex + "_";
  2697. ctid = preStr + father.tid;
  2698. splitTag = "C" + orderIndex + "+" + orderIndex;
  2699. }
  2700. else if (itemMemo.Length > 2)
  2701. {
  2702. ctid = father.tid;
  2703. }
  2704. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  2705. bool ishave = true;
  2706. if (entity == null)
  2707. {
  2708. entity = new CeErpTradeCell();
  2709. ishave = false;
  2710. }
  2711. if (entity.ShopId == 0)
  2712. {
  2713. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2714. int shopId = 0;
  2715. if (nShop != null)
  2716. {
  2717. shopId = nShop.ID;
  2718. }
  2719. entity.ShopId = shopId;
  2720. }
  2721. if (entity.IsSample == 1 || entity.IsSample == 2)
  2722. {
  2723. entity.IsSample = 0;
  2724. entity.ptid = "";
  2725. }
  2726. if (entity.isDianziOrder == 1)
  2727. {
  2728. entity.isDianziOrder = 0;
  2729. }
  2730. entity.ctid = ctid;
  2731. if (string.IsNullOrEmpty(entity.OrderSn))
  2732. {
  2733. //唯一标识
  2734. string orderSn = commonHelper.generateDateTimeRandomNos();
  2735. if (orderSn != "")
  2736. {
  2737. entity.OrderSn = orderSn;
  2738. }
  2739. }
  2740. entity.UpdateTime = DateTime.Now;
  2741. entity.tid = father.tid;
  2742. entity.SplitTag = splitTag;
  2743. string[] acclist = memo_index1.Split('-');
  2744. bool isXianhuo = false;
  2745. if (acclist[0] == "现货")
  2746. {
  2747. System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
  2748. System.Array.Resize(ref acclist, acclist.Length - 1);
  2749. isXianhuo = true;
  2750. }
  2751. if (acclist.Length < 6)
  2752. {
  2753. return;
  2754. }
  2755. string size = acclist[0];
  2756. string count = acclist[1];
  2757. bool isBuGanJiao = false;
  2758. string product = "";
  2759. string mt = "", ct = "";
  2760. string account = "";
  2761. memo_index1 = memo_index1.Replace("PVC", "pvc");
  2762. if ((acclist[3] == "不干胶" || memo_index1.IndexOf("PVC卡片") != -1 || memo_index1.IndexOf("pvc卡片") != -1 || memo_index1.IndexOf("海报") != -1) && memo_index1.IndexOf("礼物") == -1)
  2763. {
  2764. isBuGanJiao = true;
  2765. product = acclist[3];
  2766. mt = acclist[2];
  2767. }
  2768. else
  2769. {
  2770. product = acclist[2];
  2771. mt = acclist[3];
  2772. }
  2773. account = acclist[5];
  2774. ct = acclist[4];
  2775. entity.ProductId = getProductIdByName(product);
  2776. if (entity.ProductId == 0)
  2777. {
  2778. return;
  2779. }
  2780. if (isMulity && hePrice != 0)
  2781. {
  2782. entity.payment = Convert.ToDouble(hePrice);
  2783. }
  2784. else
  2785. {
  2786. entity.payment = father.payment;
  2787. }
  2788. DataRow cusInfo = getUserInfoByAccount(account);
  2789. if (cusInfo != null)
  2790. {
  2791. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2792. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2793. {
  2794. }
  2795. else
  2796. {
  2797. entity.OrderState = 2;
  2798. if (entity.ShopId != 0)
  2799. {
  2800. entity.OrderState = orderAudit(entity.ShopId);
  2801. }
  2802. if (entity.DesignUserId > 0)
  2803. {
  2804. entity.OrderState = 3;
  2805. }
  2806. }
  2807. }
  2808. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  2809. {
  2810. entity.IsOldCustomer = 1;
  2811. if (itemMemo.IndexOf("改稿") != -1)
  2812. {
  2813. if (entity.payment > 0)
  2814. {
  2815. //designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
  2816. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2817. {
  2818. }
  2819. else
  2820. {
  2821. dealOldCustomerEntityTag(ref entity, father);
  2822. }
  2823. }
  2824. }
  2825. else
  2826. {
  2827. entity.OrderState = 3;
  2828. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  2829. entity.WaitDesignTime = DateTime.Now;
  2830. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  2831. }
  2832. }
  2833. entity.Material = mt;
  2834. entity.ProductSize = size;
  2835. entity.ProductCount = commonHelper.getProductCount(count); ;//commonHelper.changeCountFromChiness(count); ;
  2836. entity.Craft = ct;
  2837. entity.pay_time = father.pay_time;
  2838. string newmemo = "(" + entity.OrderSn + ")-";
  2839. if (isXianhuo)
  2840. {
  2841. newmemo += "现货-";
  2842. entity.IsXianHuo = 1;
  2843. }
  2844. string newOtherMemo = "";
  2845. for (int idx = 0; idx < hebaoMemoList.Length; idx++)
  2846. {
  2847. string smallitem = hebaoMemoList[idx];
  2848. if (idx == 0 && smallitem.IndexOf("海报") != -1)
  2849. {
  2850. newmemo = "";
  2851. }
  2852. string[] smallList = smallitem.Split('-');
  2853. if (smallList.Length > 5 && idx > 0)
  2854. {
  2855. string itemsize = smallList[0];
  2856. string itemcount = smallList[1];
  2857. string itemmt = "", itemct = "";
  2858. if ((smallList[3] == "不干胶" || smallitem.IndexOf("PVC卡片") != -1 || smallitem.IndexOf("pvc卡片") != -1 || smallitem.IndexOf("海报") != -1) && smallitem.IndexOf("礼物") == -1)
  2859. {
  2860. itemmt = acclist[2];
  2861. }
  2862. else
  2863. {
  2864. itemmt = acclist[3];
  2865. }
  2866. itemct = acclist[4];
  2867. entity.ProductSize = entity.ProductSize + "," + itemsize;
  2868. entity.ProductCount = entity.ProductCount + "," + itemcount;
  2869. entity.Material = entity.Material + "," + itemmt;
  2870. entity.Craft = entity.Craft + "," + itemct;
  2871. }
  2872. if (smallList.Length >= 7)
  2873. {
  2874. smallList[6] = smallList[6].Replace("(", "");
  2875. smallList[6] = smallList[6].Replace(")", "");
  2876. smallList[6] = smallList[6].Replace("(", "");
  2877. smallList[6] = smallList[6].Replace(")", "");
  2878. entity.MakeSupplier = smallList[6];
  2879. smallList[6] = "(" + smallList[6] + ")";
  2880. newmemo += smallList[6];
  2881. newmemo += "-";
  2882. }
  2883. if (smallitem.IndexOf("海报") != -1)
  2884. {
  2885. newmemo += smallList[2];
  2886. newmemo += smallList[0];
  2887. newmemo += "-";
  2888. newmemo += smallList[1];
  2889. newmemo += "(";
  2890. newmemo += entity.OrderSn;
  2891. newmemo += ")";
  2892. newmemo += "-";
  2893. newmemo += smallList[4];
  2894. if (smallList.Length > 7)
  2895. {
  2896. for (int i = 7; i < smallList.Length; i++)
  2897. {
  2898. newOtherMemo += smallList[i];
  2899. newOtherMemo += "-";
  2900. }
  2901. }
  2902. if (smallitem.IndexOf("5mmpvc") != -1)
  2903. {
  2904. entity.ProductId = 8; //pvc卡片
  2905. }
  2906. }
  2907. else
  2908. {
  2909. for (int i = 0; i < smallList.Length; i++)
  2910. {
  2911. if (isMulity && i == 5)
  2912. {
  2913. continue;
  2914. }
  2915. if (i >= 7)
  2916. {
  2917. newOtherMemo += smallList[i];
  2918. if (i < smallList.Length - 2 && i != 2 && i != 3)
  2919. {
  2920. newOtherMemo += "-";
  2921. }
  2922. }
  2923. else
  2924. {
  2925. if (i == 6)
  2926. {
  2927. continue;
  2928. }
  2929. else
  2930. newmemo += smallList[i];
  2931. if (i != 2 && i != 3)
  2932. {
  2933. newmemo += "-";
  2934. }
  2935. }
  2936. }
  2937. }
  2938. if (hebaoMemoList.Length > idx + 1)
  2939. {
  2940. newmemo += ",";
  2941. newOtherMemo += ",";
  2942. }
  2943. }
  2944. entity.ProductCount = commonHelper.getProductCount(entity.ProductCount);
  2945. string sName = getShopSNameByName(father.seller_nick);
  2946. newmemo += (sName);
  2947. if (father.buyer_nick.IndexOf("*") < 0)
  2948. {
  2949. newmemo += ("-" + father.buyer_nick);
  2950. }
  2951. newmemo += ("-" + father.receiver_state);
  2952. if (cusInfo != null)
  2953. {
  2954. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2955. }
  2956. if (orderIndex > 1 && isMulity)
  2957. {
  2958. newmemo += "-[C" + orderIndex + "+" + orderIndex + "]";
  2959. }
  2960. //newmemo += "-合包";
  2961. if (itemMemo.IndexOf("顺丰到付") != -1)
  2962. {
  2963. //if(newmemo.IndexOf("顺丰到付")==-1)
  2964. // newmemo += ("-顺丰到付");
  2965. entity.IsSF = 2;
  2966. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2967. }
  2968. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2969. {
  2970. //if (newmemo.IndexOf("顺丰寄付") == -1)
  2971. // newmemo += ("-顺丰寄付");
  2972. entity.IsSF = 1;
  2973. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2974. }
  2975. if (itemMemo.IndexOf("加急") != -1)
  2976. {
  2977. //if (newmemo.IndexOf("加急") == -1)
  2978. // newmemo += ("-加急");
  2979. entity.IsUrgency = true;
  2980. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2981. }
  2982. entity.seller_memo = newmemo;
  2983. entity.OtherMemo = newOtherMemo;
  2984. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  2985. {
  2986. string odt = commonHelper.getDateFromString(newOtherMemo);
  2987. if (odt.Length > 0)
  2988. {
  2989. entity.OldCustomerTime = Convert.ToDateTime(odt);
  2990. }
  2991. }
  2992. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2993. {
  2994. }
  2995. else
  2996. {
  2997. if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
  2998. {
  2999. entity.IsOldCustomer = 0;
  3000. }
  3001. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  3002. if (oldRes > 0)
  3003. {
  3004. entity.IsOldCustomer = 1;
  3005. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  3006. dealOldCustomerEntityAuto(ref entity);
  3007. }
  3008. }
  3009. if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
  3010. {
  3011. entity.OrderState = 6;
  3012. entity.FinishPlaceTime = DateTime.Now;
  3013. entity.SupplierId = 98;//-领鸿
  3014. }
  3015. if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
  3016. {
  3017. entity.OrderState = 6;
  3018. entity.FinishPlaceTime = DateTime.Now;
  3019. entity.SupplierId = 5;//-福广
  3020. }
  3021. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  3022. {
  3023. entity.OrderState = -1;
  3024. entity.DesignUserId = 0;
  3025. entity.WaitDesignTime = null;
  3026. }
  3027. if (entity.ProductId > 0)
  3028. {
  3029. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  3030. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  3031. {
  3032. entity.NewProduct = 1;
  3033. }
  3034. bool size_result = commonHelper.interceptionSizeUnit(entity.ProductSize, ceErpProduct);
  3035. if (!size_result)
  3036. {
  3037. entity.OrderState = 0;
  3038. CeErpMessageTip ceErpMessageTip = new CeErpMessageTip();
  3039. ceErpMessageTip.tid = entity.tid;
  3040. ceErpMessageTip.sectionId = 0;
  3041. ceErpMessageTip.userId = entity.CustomerUserId;
  3042. ceErpMessageTip.type = 3;
  3043. ceErpMessageTip.isVisit = false;
  3044. ceErpMessageTip.content = entity.tid + ",领单尺寸单位不符合规范,尺寸单位为:" + ceErpProduct.SizeUnit;
  3045. ceErpMessageTip.Create();
  3046. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "尺寸单位不符合规范!" + entity.seller_memo, entity.OrderState);
  3047. }
  3048. }
  3049. if (ishave)
  3050. {
  3051. entity.Update();
  3052. }
  3053. else
  3054. {
  3055. father.create_time = DateTime.Now;
  3056. father.Update();
  3057. entity.Create();
  3058. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  3059. }
  3060. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  3061. CeErpSukuraData.createInfo(entity.ctid, 1);
  3062. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "合包推送生成" + entity.seller_memo, entity.OrderState);
  3063. }
  3064. public static void createNotHeBaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  3065. {
  3066. if (itemMemo.Length <= 0) return;
  3067. //itemMemo = "现货-240x50cm-100张-条幅-旗帜布-上打2个孔-辞暮尔尔";
  3068. string ctid = "";
  3069. string splitTag = "";
  3070. if (isMulity && itemMemo.Length > 2)
  3071. {
  3072. string preStr = "C" + orderIndex + "_";
  3073. ctid = preStr + father.tid;
  3074. splitTag = "C" + totalCount + "+" + orderIndex;
  3075. }
  3076. else if (itemMemo.Length > 2)
  3077. {
  3078. ctid = father.tid;
  3079. }
  3080. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  3081. bool ishave = true;
  3082. if (entity == null)
  3083. {
  3084. entity = new CeErpTradeCell();
  3085. ishave = false;
  3086. }
  3087. entity.ctid = ctid;
  3088. if (string.IsNullOrEmpty(entity.OrderSn))
  3089. {
  3090. //唯一标识
  3091. string orderSn = commonHelper.generateDateTimeRandomNos();
  3092. if (orderSn != "")
  3093. {
  3094. entity.OrderSn = orderSn;
  3095. }
  3096. }
  3097. entity.UpdateTime = DateTime.Now;
  3098. entity.tid = father.tid;
  3099. entity.SplitTag = splitTag;
  3100. string[] acclist = itemMemo.Split('-');
  3101. bool isXianhuo = false;
  3102. if (acclist[0] == "现货")
  3103. {
  3104. isXianhuo = true;
  3105. System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
  3106. System.Array.Resize(ref acclist, acclist.Length - 1);
  3107. }
  3108. if (entity.ShopId == 0)
  3109. {
  3110. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  3111. int shopId = 0;
  3112. if (nShop != null)
  3113. {
  3114. shopId = nShop.ID;
  3115. }
  3116. entity.ShopId = shopId;
  3117. }
  3118. if (entity.IsSample == 1 || entity.IsSample == 2)
  3119. {
  3120. entity.IsSample = 0;
  3121. entity.ptid = "";
  3122. }
  3123. if (entity.isDianziOrder == 1)
  3124. {
  3125. entity.isDianziOrder = 0;
  3126. }
  3127. if (entity.IsXianHuo == 1)
  3128. {
  3129. entity.IsXianHuo = 0;
  3130. }
  3131. if (isMulity && acclist.Length < 7)
  3132. {
  3133. return;
  3134. }
  3135. if (acclist.Length < 6)
  3136. {
  3137. return;
  3138. }
  3139. string size = acclist[0];
  3140. string count = acclist[1];
  3141. bool isBuGanJiao = false;
  3142. string product = "";
  3143. string mt = "", ct = "";
  3144. string account = "";
  3145. itemMemo = itemMemo.Replace("PVC", "pvc");
  3146. if ((acclist[3] == "不干胶" || itemMemo.IndexOf("电子稿") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("礼物") == -1)
  3147. {
  3148. isBuGanJiao = true;
  3149. product = acclist[3];
  3150. mt = acclist[2];
  3151. }
  3152. else
  3153. {
  3154. product = acclist[2];
  3155. mt = acclist[3];
  3156. }
  3157. account = acclist[5];
  3158. ct = acclist[4];
  3159. if (isMulity)
  3160. {
  3161. try
  3162. {
  3163. string strPrice = acclist[6];
  3164. if (strPrice.IndexOf("元") != -1)
  3165. {
  3166. strPrice = strPrice.Replace("元", "");
  3167. }
  3168. entity.payment = Convert.ToDouble(strPrice);
  3169. hePrice = hePrice - Convert.ToDecimal(strPrice);
  3170. }
  3171. catch (Exception ex)
  3172. {
  3173. entity.payment = 0;
  3174. return;
  3175. }
  3176. if (acclist.Length >= 8)
  3177. {
  3178. acclist[7] = acclist[7].Replace("(", "");
  3179. acclist[7] = acclist[7].Replace(")", "");
  3180. acclist[7] = acclist[7].Replace("(", "");
  3181. acclist[7] = acclist[7].Replace(")", "");
  3182. entity.MakeSupplier = acclist[7];
  3183. acclist[7] = "(" + acclist[7] + ")";
  3184. }
  3185. }
  3186. else
  3187. {
  3188. entity.payment = father.payment;
  3189. if (acclist.Length >= 7)
  3190. {
  3191. acclist[6] = acclist[6].Replace("(", "");
  3192. acclist[6] = acclist[6].Replace(")", "");
  3193. acclist[6] = acclist[6].Replace("(", "");
  3194. acclist[6] = acclist[6].Replace(")", "");
  3195. entity.MakeSupplier = acclist[6];
  3196. acclist[6] = "(" + acclist[6] + ")";
  3197. }
  3198. }
  3199. entity.ProductId = getProductIdByName(product);
  3200. if (entity.ProductId == 0)
  3201. {
  3202. return;
  3203. }
  3204. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  3205. if (cusInfo != null)
  3206. {
  3207. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  3208. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3209. {
  3210. }
  3211. else
  3212. {
  3213. entity.OrderState = 2;
  3214. if (entity.ShopId != 0)
  3215. {
  3216. entity.OrderState = orderAudit(entity.ShopId);
  3217. }
  3218. if (entity.DesignUserId > 0)
  3219. {
  3220. entity.OrderState = 3;
  3221. }
  3222. }
  3223. }
  3224. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  3225. {
  3226. entity.IsOldCustomer = 1;
  3227. if (itemMemo.IndexOf("改稿") != -1)
  3228. {
  3229. if (entity.payment > 0)
  3230. {
  3231. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3232. {
  3233. }
  3234. else
  3235. {
  3236. dealOldCustomerEntityTag(ref entity, father);
  3237. }
  3238. }
  3239. }
  3240. else
  3241. {
  3242. if (entity.payment != 0)
  3243. {
  3244. entity.OrderState = -1; // Convert.ToInt32(OrderState.待设计);
  3245. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  3246. entity.WaitDesignTime = DateTime.Now;
  3247. entity.FinishPlaceTime = DateTime.Now;
  3248. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
  3249. }
  3250. }
  3251. }
  3252. if (mt.IndexOf("铜板纸") != -1)
  3253. {
  3254. mt = mt.Replace("铜板纸", "铜版纸");
  3255. }
  3256. entity.Material = mt;
  3257. entity.ProductSize = size;
  3258. entity.ProductCount = commonHelper.getProductCount(count); ;//commonHelper.changeCountFromChiness(count);
  3259. entity.Craft = ct;
  3260. entity.pay_time = father.pay_time;
  3261. if (itemMemo.IndexOf("电子稿") != -1)
  3262. {
  3263. entity.isDianziOrder = 1;
  3264. }
  3265. if (product == "现货手提袋")
  3266. {
  3267. entity.OrderState = 6;//下单完成
  3268. entity.FinishPlaceTime = DateTime.Now;
  3269. }
  3270. string newmemo = "(" + entity.OrderSn + ")-";
  3271. if (isXianhuo)
  3272. {
  3273. newmemo += "现货-";
  3274. entity.IsXianHuo = 1;
  3275. }
  3276. string newOtherMemo = "";
  3277. if (false)
  3278. {
  3279. newmemo = acclist[2];
  3280. newmemo += acclist[0];
  3281. newmemo += "-";
  3282. newmemo += acclist[1];
  3283. newmemo += "(";
  3284. newmemo += father.tid;
  3285. newmemo += ")";
  3286. newmemo += "-";
  3287. newmemo += acclist[4];
  3288. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  3289. newmemo += ("-" + sName);
  3290. newmemo += ("-" + father.buyer_nick);
  3291. if (father.buyer_nick.IndexOf("*") < 0)
  3292. {
  3293. newmemo += ("-" + father.buyer_nick);
  3294. }
  3295. if (cusInfo != null)
  3296. {
  3297. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3298. }
  3299. if (isMulity)
  3300. {
  3301. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3302. }
  3303. if (acclist.Length > 7)
  3304. {
  3305. for (int i = 7; i < acclist.Length; i++)
  3306. {
  3307. newOtherMemo += acclist[i];
  3308. newOtherMemo += "-";
  3309. }
  3310. }
  3311. }
  3312. else
  3313. {
  3314. if (acclist.Length >= 7 && !isMulity)
  3315. {
  3316. newmemo += acclist[6];
  3317. newmemo += "-";
  3318. }
  3319. if (isMulity && acclist.Length >= 8)
  3320. {
  3321. newmemo += acclist[7];
  3322. newmemo += "-";
  3323. }
  3324. for (int i = 0; i < acclist.Length; i++)
  3325. {
  3326. if ((isMulity && i == 6) || i == 5)
  3327. {
  3328. continue;
  3329. }
  3330. if ((i >= 7 && !isMulity) || (isMulity && i >= 8))
  3331. {
  3332. newOtherMemo += acclist[i];
  3333. newOtherMemo += "-";
  3334. }
  3335. else
  3336. {
  3337. if ((i == 6 && !isMulity) || (isMulity && i == 7))
  3338. {
  3339. continue;
  3340. }
  3341. else
  3342. newmemo += acclist[i];
  3343. if (i != 2 && i != 3)
  3344. {
  3345. newmemo += "-";
  3346. }
  3347. }
  3348. }
  3349. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  3350. newmemo += (sName);
  3351. if (father.buyer_nick.IndexOf("*") < 0)
  3352. {
  3353. newmemo += ("-" + father.buyer_nick);
  3354. }
  3355. newmemo += ("-" + father.receiver_state);
  3356. if (cusInfo != null)
  3357. {
  3358. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3359. }
  3360. if (itemMemo.IndexOf("顺丰到付") != -1)
  3361. {
  3362. //if (newmemo.IndexOf("顺丰到付") == -1)
  3363. // newmemo += ("-顺丰到付");
  3364. entity.IsSF = 2;
  3365. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  3366. }
  3367. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  3368. {
  3369. //if (newmemo.IndexOf("顺丰寄付") == -1)
  3370. // newmemo += ("-顺丰寄付");
  3371. entity.IsSF = 1;
  3372. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  3373. }
  3374. if (itemMemo.IndexOf("加急") != -1)
  3375. {
  3376. //if (newmemo.IndexOf("加急") == -1)
  3377. // newmemo += ("-加急");
  3378. entity.IsUrgency = true;
  3379. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  3380. }
  3381. }
  3382. if (isMulity)
  3383. {
  3384. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3385. }
  3386. newmemo = newmemo.Replace("\n", " ");
  3387. entity.seller_memo = newmemo;
  3388. entity.OtherMemo = newOtherMemo;
  3389. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  3390. {
  3391. string odt = commonHelper.getDateFromString(newOtherMemo);
  3392. if (odt.Length > 0)
  3393. {
  3394. entity.OldCustomerTime = Convert.ToDateTime(odt);
  3395. }
  3396. }
  3397. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3398. {
  3399. //到了设计那边,就更新memo,状态不设置
  3400. }
  3401. else
  3402. {
  3403. if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
  3404. {
  3405. entity.IsOldCustomer = 0;
  3406. }
  3407. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  3408. if (oldRes > 0)
  3409. {
  3410. entity.IsOldCustomer = 1;
  3411. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  3412. dealOldCustomerEntityAuto(ref entity);
  3413. }
  3414. }
  3415. if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
  3416. {
  3417. entity.OrderState = 6;
  3418. entity.FinishPlaceTime = DateTime.Now;
  3419. entity.SupplierId = 98;//-领鸿
  3420. }
  3421. if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
  3422. {
  3423. entity.OrderState = 6;
  3424. entity.FinishPlaceTime = DateTime.Now;
  3425. entity.SupplierId = 5;//-福广
  3426. }
  3427. if (entity.seller_memo.Contains("法式蛋糕"))
  3428. {
  3429. entity.OrderState = 6;
  3430. entity.FinishPlaceTime = DateTime.Now;
  3431. entity.SupplierId = 35;//-福广
  3432. }
  3433. //台湾省要审核
  3434. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  3435. {
  3436. entity.OrderState = -1;
  3437. entity.DesignUserId = 0;
  3438. entity.WaitDesignTime = null;
  3439. }
  3440. if (entity.ProductId > 0)
  3441. {
  3442. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  3443. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  3444. {
  3445. entity.NewProduct = 1;
  3446. }
  3447. bool size_result = commonHelper.interceptionSizeUnit(entity.ProductSize, ceErpProduct);
  3448. if (!size_result)
  3449. {
  3450. entity.OrderState = 0;
  3451. CeErpMessageTip ceErpMessageTip = new CeErpMessageTip();
  3452. ceErpMessageTip.tid = entity.tid;
  3453. ceErpMessageTip.sectionId = 0;
  3454. ceErpMessageTip.userId = entity.CustomerUserId;
  3455. ceErpMessageTip.type = 3;
  3456. ceErpMessageTip.isVisit = false;
  3457. ceErpMessageTip.content = entity.tid + ",领单尺寸单位不符合规范,尺寸单位为:" + ceErpProduct.SizeUnit;
  3458. ceErpMessageTip.Create();
  3459. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "尺寸单位不符合规范!" + entity.seller_memo, entity.OrderState);
  3460. }
  3461. }
  3462. if (ishave)
  3463. {
  3464. entity.Update();
  3465. }
  3466. else
  3467. {
  3468. father.create_time = DateTime.Now;
  3469. father.Update();
  3470. entity.Create();
  3471. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  3472. }
  3473. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  3474. CeErpSukuraData.createInfo(entity.ctid, 1);
  3475. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "普通推送生成:" + entity.seller_memo, entity.OrderState);
  3476. }
  3477. public static List<int> shop_list = new List<int>() { 5, 6, 8, 10, 11, 12, 14, 15, 16, 18, 24, 26, 28, 31, 32, 45, 56, 61, 126, 128 };
  3478. public static void dealOldCustomerEntityTag(ref CeErpTradeCell entity, CeErpTrade father)
  3479. {
  3480. //UV跟指定店铺
  3481. int[] shopList = { 49, 67, 13, 68, 20, 17, 52, 21, 66, 63, 64 };
  3482. if ((entity.ProductId == 43 && !shop_list.Contains(entity.ShopId)) || shopList.Contains(entity.ShopId))
  3483. {
  3484. /**int curHour = DateTime.Now.Hour;
  3485. int initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3486. if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3487. {
  3488. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3489. entity.DesignUserId = initSysDesignerId;
  3490. entity.WaitDesignTime = DateTime.Now;
  3491. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3492. }
  3493. else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3494. {
  3495. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
  3496. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3497. entity.DesignUserId = initSysDesignerId;
  3498. entity.WaitDesignTime = DateTime.Now;
  3499. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3500. }
  3501. else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3502. {
  3503. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
  3504. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3505. entity.DesignUserId = initSysDesignerId;
  3506. entity.WaitDesignTime = DateTime.Now;
  3507. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3508. }
  3509. else
  3510. {**/
  3511. int designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
  3512. if (designId != 0)
  3513. {
  3514. entity.DesignUserId = designId;
  3515. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3516. entity.WaitDesignTime = DateTime.Now;
  3517. LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给之前设计师", entity.OrderState);
  3518. }
  3519. }
  3520. }
  3521. public static void dealOldCustomerEntityAuto(ref CeErpTradeCell entity)
  3522. {
  3523. int curHour = DateTime.Now.Hour;
  3524. int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
  3525. /**if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3526. {
  3527. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3528. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3529. entity.DesignUserId = initSysDesignerId;
  3530. entity.WaitDesignTime = DateTime.Now;
  3531. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3532. }
  3533. else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3534. {
  3535. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
  3536. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3537. entity.DesignUserId = initSysDesignerId;
  3538. entity.WaitDesignTime = DateTime.Now;
  3539. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3540. }
  3541. else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3542. {
  3543. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
  3544. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3545. entity.DesignUserId = initSysDesignerId;
  3546. entity.WaitDesignTime = DateTime.Now;
  3547. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3548. }
  3549. else
  3550. {**/
  3551. CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
  3552. //这个设计师有上班,有关联此店铺
  3553. if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
  3554. {
  3555. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3556. entity.DesignUserId = initSysDesignerId;
  3557. entity.WaitDesignTime = DateTime.Now;
  3558. LogHelper.addLog(entity.ctid, 0, "老客户单指派" + entity.DesignUserId, entity.OrderState);
  3559. }
  3560. //}
  3561. }
  3562. public static void createNewSplitCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, double orderPrice, int totalCount)
  3563. {
  3564. if (itemMemo.Length <= 0) return;
  3565. string ctid = "";
  3566. string splitTag = "";
  3567. if (isMulity && itemMemo.Length > 2)
  3568. {
  3569. string preStr = "C" + orderIndex + "_";
  3570. ctid = preStr + father.tid;
  3571. splitTag = "C" + orderIndex;
  3572. }
  3573. else if (itemMemo.Length > 2)
  3574. {
  3575. ctid = father.tid;
  3576. }
  3577. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  3578. bool ishave = true;
  3579. if (entity == null)
  3580. {
  3581. entity = new CeErpTradeCell();
  3582. ishave = false;
  3583. }
  3584. entity.ctid = ctid;
  3585. entity.tid = father.tid;
  3586. entity.SplitTag = splitTag;
  3587. string[] acclist = itemMemo.Split('-');
  3588. if (entity.ShopId == 0)
  3589. {
  3590. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  3591. int shopId = 0;
  3592. if (nShop != null)
  3593. {
  3594. shopId = nShop.ID;
  3595. }
  3596. entity.ShopId = shopId;
  3597. }
  3598. if (entity.IsSample == 1 || entity.IsSample == 2)
  3599. {
  3600. entity.IsSample = 0;
  3601. }
  3602. if (entity.isDianziOrder == 1)
  3603. {
  3604. entity.isDianziOrder = 0;
  3605. }
  3606. if (acclist.Length < 6)
  3607. {
  3608. return;
  3609. }
  3610. string size = acclist[0];
  3611. string count = acclist[1];
  3612. bool isBuGanJiao = false;
  3613. string product = "";
  3614. string mt = "", ct = "";
  3615. string account = "";
  3616. itemMemo = itemMemo.Replace("PVC", "pvc");
  3617. if ((acclist[3] == "不干胶" || itemMemo.IndexOf("PVC卡片") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("礼物") == -1)
  3618. {
  3619. isBuGanJiao = true;
  3620. product = acclist[3];
  3621. mt = acclist[2];
  3622. }
  3623. else
  3624. {
  3625. product = acclist[2];
  3626. mt = acclist[3];
  3627. }
  3628. account = acclist[5];
  3629. ct = acclist[4];
  3630. if (isMulity)
  3631. {
  3632. entity.payment = orderPrice;
  3633. if (acclist.Length >= 7)
  3634. {
  3635. acclist[6] = acclist[6].Replace("(", "");
  3636. acclist[6] = acclist[6].Replace(")", "");
  3637. acclist[6] = acclist[6].Replace("(", "");
  3638. acclist[6] = acclist[6].Replace(")", "");
  3639. entity.MakeSupplier = acclist[6];
  3640. acclist[6] = "(" + acclist[6] + ")";
  3641. }
  3642. }
  3643. entity.ProductId = getProductIdByName(product);
  3644. if (entity.ProductId == 0)
  3645. {
  3646. return;
  3647. }
  3648. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  3649. if (cusInfo != null)
  3650. {
  3651. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  3652. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3653. {
  3654. }
  3655. else
  3656. {
  3657. entity.OrderState = 2;
  3658. if (entity.ShopId != 0)
  3659. {
  3660. entity.OrderState = orderAudit(entity.ShopId);
  3661. }
  3662. if (entity.DesignUserId > 0)
  3663. {
  3664. entity.OrderState = 3;
  3665. }
  3666. }
  3667. }
  3668. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  3669. {
  3670. entity.IsOldCustomer = 1;
  3671. if (itemMemo.IndexOf("改稿") != -1)
  3672. {
  3673. if (entity.payment > 0)
  3674. {
  3675. //designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
  3676. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3677. {
  3678. }
  3679. else
  3680. {
  3681. int designId = Convert.ToInt32(webConfig.PlaceChangeId);
  3682. CeErpUser oldGaiPlace = CeErpUser.Get(designId);
  3683. if (oldGaiPlace != null && ("," + oldGaiPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldGaiPlace.Person.OnDuty == 1)
  3684. {
  3685. }
  3686. else
  3687. {
  3688. designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
  3689. }
  3690. if (designId != 0)
  3691. {
  3692. entity.DesignUserId = designId;
  3693. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3694. entity.WaitDesignTime = DateTime.Now;
  3695. LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给" + (designId == Convert.ToInt32(webConfig.PlaceChangeId) ? "下单部" : "原设计师"), entity.OrderState);
  3696. }
  3697. }
  3698. }
  3699. }
  3700. else
  3701. {
  3702. if (entity.payment != 0)
  3703. {
  3704. entity.OrderState = 3; // Convert.ToInt32(OrderState.待设计);
  3705. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  3706. entity.WaitDesignTime = DateTime.Now;
  3707. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
  3708. }
  3709. }
  3710. }
  3711. if (mt.IndexOf("铜板纸") != -1)
  3712. {
  3713. mt = mt.Replace("铜板纸", "铜版纸");
  3714. }
  3715. entity.Material = mt;
  3716. entity.ProductSize = size;
  3717. entity.ProductCount = commonHelper.getProductCount(count); ;//commonHelper.changeCountFromChiness(count);
  3718. entity.Craft = ct;
  3719. entity.pay_time = father.pay_time;
  3720. if (product == "现货手提袋")
  3721. {
  3722. entity.OrderState = 6;//下单完成
  3723. entity.FinishPlaceTime = DateTime.Now;
  3724. }
  3725. string newmemo = "(" + father.tid + ")-";
  3726. string newOtherMemo = "";
  3727. if (itemMemo.IndexOf("海报") != -1)
  3728. {
  3729. newmemo = acclist[2];
  3730. newmemo += acclist[0];
  3731. newmemo += "-";
  3732. newmemo += acclist[1];
  3733. newmemo += "(";
  3734. newmemo += father.tid;
  3735. newmemo += ")";
  3736. newmemo += "-";
  3737. newmemo += acclist[4];
  3738. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  3739. newmemo += ("-" + sName);
  3740. if (father.buyer_nick.IndexOf("*") < 0)
  3741. {
  3742. newmemo += ("-" + father.buyer_nick);
  3743. }
  3744. newmemo += ("-" + father.receiver_state);
  3745. if (cusInfo != null)
  3746. {
  3747. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3748. }
  3749. if (isMulity)
  3750. {
  3751. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3752. }
  3753. if (acclist.Length > 7)
  3754. {
  3755. for (int i = 7; i < acclist.Length; i++)
  3756. {
  3757. newOtherMemo += acclist[i];
  3758. newOtherMemo += "-";
  3759. }
  3760. }
  3761. }
  3762. else
  3763. {
  3764. if (acclist.Length >= 7)
  3765. {
  3766. newmemo += acclist[6];
  3767. newmemo += "-";
  3768. }
  3769. for (int i = 0; i < acclist.Length; i++)
  3770. {
  3771. if (i == 5)
  3772. {
  3773. continue;
  3774. }
  3775. if (i >= 7)
  3776. {
  3777. newOtherMemo += acclist[i];
  3778. newOtherMemo += "-";
  3779. }
  3780. else
  3781. {
  3782. if (i == 6)
  3783. {
  3784. continue;
  3785. }
  3786. else
  3787. newmemo += acclist[i];
  3788. if (i != 2 && i != 3)
  3789. {
  3790. newmemo += "-";
  3791. }
  3792. }
  3793. }
  3794. string sName = getShopSNameByName(father.seller_nick);
  3795. newmemo += (sName);
  3796. if (father.buyer_nick.IndexOf("*") < 0)
  3797. {
  3798. newmemo += ("-" + father.buyer_nick);
  3799. }
  3800. newmemo += ("-" + father.receiver_state);
  3801. if (cusInfo != null)
  3802. {
  3803. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3804. }
  3805. if (itemMemo.IndexOf("顺丰到付") != -1)
  3806. {
  3807. entity.IsSF = 2;
  3808. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  3809. }
  3810. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  3811. {
  3812. //if (newmemo.IndexOf("顺丰寄付") == -1)
  3813. // newmemo += ("-顺丰寄付");
  3814. entity.IsSF = 1;
  3815. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  3816. }
  3817. if (itemMemo.IndexOf("加急") != -1)
  3818. {
  3819. //if (newmemo.IndexOf("加急") == -1)
  3820. // newmemo += ("-加急");
  3821. entity.IsUrgency = true;
  3822. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  3823. }
  3824. }
  3825. if (isMulity)
  3826. {
  3827. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3828. }
  3829. newmemo = newmemo.Replace("\n", " ");
  3830. entity.seller_memo = newmemo;
  3831. entity.OtherMemo = newOtherMemo;
  3832. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  3833. {
  3834. string odt = commonHelper.getDateFromString(newOtherMemo);
  3835. if (odt.Length > 0)
  3836. {
  3837. entity.OldCustomerTime = Convert.ToDateTime(odt);
  3838. }
  3839. }
  3840. if (entity.IsOldCustomer == 0)
  3841. {
  3842. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3843. {
  3844. //到了设计那边,就更新memo,状态不设置
  3845. }
  3846. else
  3847. {
  3848. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  3849. if (oldRes > 0)
  3850. {
  3851. entity.IsOldCustomer = 1;
  3852. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  3853. int curHour = DateTime.Now.Hour;
  3854. int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
  3855. if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3856. {
  3857. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3858. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3859. entity.DesignUserId = initSysDesignerId;
  3860. entity.WaitDesignTime = DateTime.Now;
  3861. }
  3862. else
  3863. {
  3864. CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
  3865. if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
  3866. {
  3867. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3868. entity.DesignUserId = initSysDesignerId;
  3869. entity.WaitDesignTime = DateTime.Now;
  3870. }
  3871. }
  3872. }
  3873. }
  3874. }
  3875. if (ishave)
  3876. {
  3877. entity.Update();
  3878. }
  3879. else
  3880. {
  3881. entity.Create();
  3882. }
  3883. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "新备注推送生成:" + entity.seller_memo, entity.OrderState);
  3884. }
  3885. public static int getOldCusByBuyer(string buyer, int shopId, int prodcutId)
  3886. {
  3887. DateTime nowTime = DateTime.Now;
  3888. if (nowTime.Hour >= 17)
  3889. {
  3890. return 0;
  3891. }
  3892. string sql = "select top 5 * from view_erptradecell where buyer_nick='" + buyer + "';";
  3893. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3894. foreach (DataRow dr in dt.Rows)
  3895. {
  3896. if (Convert.ToInt32(dr["DesignUserId"]) != 0 && Convert.ToInt32(dr["DesignUserId"]) != Convert.ToInt32(webConfig.PlaceDesigner_id)) //188林春鸿下单部设计
  3897. {
  3898. int designId = Convert.ToInt32(dr["DesignUserId"]);
  3899. string sql_user = "select * from view_erpuser where ','+pemShop+',' like '%," + shopId + ",%' and (PostCode='Designer' or PostCode='DesignerMr') and ','+pemDesign+',' like '%," + prodcutId + ",%' and OnDuty=1 and id=" + designId;
  3900. DataTable dt_user = CeErpTradeRefund.ExecuteDataset(sql_user).Tables[0];
  3901. if (dt_user.Rows.Count > 0)
  3902. {
  3903. return designId;
  3904. }
  3905. else
  3906. return 0;
  3907. }
  3908. }
  3909. return 0;
  3910. }
  3911. public static int getProductIdByName(string proName)
  3912. {
  3913. string dname = proName;
  3914. if (dname == "暧心贴")
  3915. {
  3916. dname = "暖心贴";
  3917. }
  3918. string sql = "select top 1 * from ce_erpproduct where uuid='" + dname + "';";
  3919. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3920. if (dt.Rows.Count > 0)
  3921. {
  3922. return Convert.ToInt32(dt.Rows[0]["ID"]);
  3923. }
  3924. return 0;
  3925. }
  3926. public static string getShopSNameByName(string seller_nick)
  3927. {
  3928. string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
  3929. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3930. if (dt.Rows.Count > 0)
  3931. {
  3932. return Convert.ToString(dt.Rows[0]["SName"]);
  3933. }
  3934. return "";
  3935. }
  3936. //public static string getShopRealName(string seller_nick)
  3937. //{
  3938. // string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
  3939. // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3940. // if (dt.Rows.Count > 0)
  3941. // {
  3942. // if(dt.Rows[0]["ShopName"].ToString()!= dt.Rows[0]["Summary"].ToString())
  3943. // return Convert.ToString(dt.Rows[0]["ShopName"]);
  3944. // }
  3945. // return seller_nick;
  3946. //}
  3947. public static DataRow getRelationOrder(string buyer, string sampTid)
  3948. {
  3949. string sql = "select top 3 * from view_erptradecell where buyer_nick='" + buyer + "' and seller_memo not like '%补差价%' and tid<>'" + sampTid + "' order by id desc";
  3950. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3951. if (dt.Rows.Count > 0)
  3952. {
  3953. DataRow need = dt.Rows[0];
  3954. if (dt.Rows.Count == 1)
  3955. {
  3956. return need;
  3957. }
  3958. int idx = 0;
  3959. foreach (DataRow dr in dt.Rows)
  3960. {
  3961. if (idx != 0)
  3962. {
  3963. int day = Convert.ToDateTime(need["pay_time"]).Day;
  3964. int nday = Convert.ToDateTime(dr["pay_time"]).Day;
  3965. if (day == nday)
  3966. {
  3967. need = dr;
  3968. }
  3969. }
  3970. idx++;
  3971. }
  3972. return need;
  3973. }
  3974. return null;
  3975. }
  3976. public static DataRow getUserInfoByAccount(string account)
  3977. {
  3978. string sql = "select * from view_erpuser where isOpen=1 and Account='" + account + "'";
  3979. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  3980. if (dt != null && dt.Rows.Count > 0)
  3981. {
  3982. return dt.Rows[0];
  3983. }
  3984. return null;
  3985. }
  3986. public static string getShopNameByECode(string code)
  3987. {
  3988. string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
  3989. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  3990. if (dt != null && dt.Rows.Count > 0)
  3991. {
  3992. return dt.Rows[0]["ShopName"].ToString();
  3993. }
  3994. return "";
  3995. }
  3996. // 时间戳转为C#格式时间
  3997. public static DateTime StampToDateTime(string timeStamp)
  3998. {
  3999. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  4000. long lTime = long.Parse(timeStamp + "0000");
  4001. TimeSpan toNow = new TimeSpan(lTime);
  4002. return dateTimeStart.Add(toNow);
  4003. }
  4004. public static void Api_Tmc_CreateNewOrder(string res)
  4005. {
  4006. Api_trade_fullinfo_get_response_Obj fullObj = null;
  4007. if (res == "") return;
  4008. try
  4009. {
  4010. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  4011. //res = res.Replace(" ", "");
  4012. fullObj = JsonConvert.DeserializeObject<Api_trade_fullinfo_get_response_Obj>(res);
  4013. }
  4014. catch (Exception ex)
  4015. {
  4016. XLog.SaveLog(0, ex.Message);
  4017. }
  4018. if (fullObj == null)
  4019. {
  4020. Console.WriteLine("Api_trade_fullinfo_get_response_Obj isNull");
  4021. return;
  4022. }
  4023. ContentItem tObj = null;
  4024. if (fullObj.response.data.content.Count > 0)
  4025. {
  4026. tObj = fullObj.response.data.content[0];
  4027. }
  4028. if (tObj == null)
  4029. {
  4030. return;
  4031. }
  4032. //未付款,未成功的单不需要
  4033. if (tObj.status == "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
  4034. {
  4035. return;
  4036. }
  4037. List<Api_trade_fullinfo_get_response_Obj.LinesItem> orderList = tObj.lines;
  4038. StringBuilder sql = new StringBuilder();
  4039. CeErpTrade trade = CeErpTrade.Get(tObj.refOid);
  4040. bool isCreate = false;
  4041. if (trade == null)
  4042. {
  4043. trade = new CeErpTrade();
  4044. isCreate = true;
  4045. }
  4046. //原始单创建
  4047. trade.tid = tObj.refOid;
  4048. if (tObj.posCode != null)
  4049. trade.posCode = tObj.posCode;
  4050. //trade.num = tObj.num;
  4051. trade.status = tObj.status;
  4052. trade.seller_flag = tObj.flag;
  4053. trade.type = tObj.refType;
  4054. trade.price = Convert.ToDouble(tObj.totalPrice);
  4055. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  4056. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  4057. trade.created = StampToDateTime(tObj.orderTime);
  4058. if (tObj.payTime != null)
  4059. {
  4060. trade.pay_time = StampToDateTime(tObj.payTime);
  4061. }
  4062. if (tObj.modifyTime != null)
  4063. {
  4064. trade.modified = StampToDateTime(tObj.modifyTime);
  4065. }
  4066. if (tObj.finishTime != null)
  4067. {
  4068. trade.end_time = StampToDateTime(tObj.finishTime);
  4069. }
  4070. trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  4071. trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
  4072. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  4073. trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
  4074. if (trade.seller_nick == "")
  4075. {
  4076. trade.seller_nick = getShopNameByECode(trade.posCode);
  4077. }
  4078. trade.payment = Convert.ToDouble(tObj.payment);
  4079. //trade.receiver_name = tObj.receiver_name;
  4080. trade.receiver_state = tObj.receiverState;
  4081. trade.receiver_city = tObj.receiverCity;
  4082. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  4083. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  4084. //trade.receiver_address = tObj.receiver_address;
  4085. //trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile);
  4086. //trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone);
  4087. //if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null)
  4088. //{
  4089. // trade.consign_time = tObj.consign_time;
  4090. //}
  4091. if (tObj.shippingTime != null)
  4092. {
  4093. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  4094. }
  4095. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  4096. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  4097. trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo);
  4098. if (trade.seller_nick != "" && trade.pay_time > StampToDateTime("1725120000000"))
  4099. {
  4100. if (tObj.refType == "TMALL" || tObj.refType == "TB")
  4101. {
  4102. string[] acclist = tObj.sellerMemo.Split('-');
  4103. List<string> list = new List<string>(acclist);
  4104. string buyer_nick = "";
  4105. if ((trade.seller_memo.IndexOf("logo") != -1 || trade.seller_memo.IndexOf("LOGO") != -1))
  4106. {
  4107. if (list.Count > 3)
  4108. {
  4109. buyer_nick = list[3];
  4110. }
  4111. }
  4112. else if (trade.seller_memo.IndexOf("补差") != -1 && list.Count < 6)
  4113. {
  4114. if (list.Count > 1)
  4115. {
  4116. buyer_nick = list[1];
  4117. }
  4118. }
  4119. else if (trade.seller_memo.IndexOf("默拍单") != -1 && list.Count < 6)
  4120. {
  4121. if (list.Count > 1)
  4122. {
  4123. buyer_nick = list[1];
  4124. }
  4125. }
  4126. else if (trade.seller_memo.IndexOf("寄样") != -1)
  4127. {
  4128. if (list.Count > 3)
  4129. {
  4130. buyer_nick = list[3];
  4131. }
  4132. }
  4133. else if (trade.seller_memo.IndexOf("拿样订单") != -1)
  4134. {
  4135. if (list.Count > 1)
  4136. {
  4137. buyer_nick = list[1];
  4138. }
  4139. }
  4140. else if (trade.seller_memo.IndexOf("礼物") != -1 && list.Count < 6)
  4141. {
  4142. if (list.Count > 1)
  4143. {
  4144. buyer_nick = list[1];
  4145. }
  4146. }
  4147. else
  4148. {
  4149. if (list.Count > 5)
  4150. {
  4151. buyer_nick = list[5];
  4152. }
  4153. }
  4154. tObj.sellerMemo = string.Join("-", list);
  4155. tObj.sellerMemo = tObj.sellerMemo.Replace("-" + buyer_nick, string.Empty);
  4156. trade.buyer_nick = buyer_nick.Replace("+", "-").Replace("#", "logo").Replace("@", "LOGO");
  4157. }
  4158. }
  4159. if (isCreate)
  4160. {
  4161. trade.Create();
  4162. }
  4163. else
  4164. {
  4165. trade.Update();
  4166. }
  4167. bool isXianhuo = false;
  4168. string xianhuoMemo = "(" + trade.tid + ")现货-";
  4169. //order表创建
  4170. foreach (Api_trade_fullinfo_get_response_Obj.LinesItem item in orderList)
  4171. {
  4172. bool orderCreate = false;
  4173. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
  4174. if (order == null)
  4175. {
  4176. order = new CeErpTradeOrder();
  4177. orderCreate = true;
  4178. }
  4179. order.tid = trade.tid;
  4180. order.oid = item.refOlId;
  4181. order.buyer_nick = trade.buyer_nick;
  4182. order.refund_status = item.refundStatus;
  4183. order.status = trade.status;
  4184. order.title = item.title;
  4185. order.price = Convert.ToDouble(item.price);
  4186. if (item.picUrl != null)
  4187. order.pic_path = item.picUrl;
  4188. order.num = Convert.ToDouble(item.num.ToString());
  4189. order.payment = Convert.ToDouble(item.price);
  4190. if (item.refSpuId != null && item.refSpuId != "")
  4191. {
  4192. order.spu_id = item.refSpuId;
  4193. }
  4194. //order.adjust_fee = Convert.ToDouble(item.price);
  4195. if (item.refSkuId != null && item.standards != null && (item.standards.IndexOf("现货") != -1 || item.standards.IndexOf("封酒贴") != -1) && item.standards.IndexOf("定制") == -1)
  4196. {
  4197. order.sku_properties_name = item.standards;
  4198. order.sku_id = item.refSkuId;
  4199. isXianhuo = true;
  4200. xianhuoMemo += order.sku_properties_name;
  4201. xianhuoMemo += ("-数量:" + order.num + "; ");
  4202. }
  4203. if (orderCreate)
  4204. {
  4205. order.Create();
  4206. }
  4207. else
  4208. {
  4209. order.Update();
  4210. }
  4211. }
  4212. //if (isXianhuo)
  4213. //{
  4214. // xianhuoMemo += "-";
  4215. // xianhuoMemo += trade.seller_nick;
  4216. //}
  4217. //cell表创建
  4218. CeErpTradeCell entity = null;
  4219. entity = CeErpTradeCell.GetByCtid(tObj.refOid);
  4220. if (entity == null)
  4221. {
  4222. try
  4223. {
  4224. entity = new CeErpTradeCell();
  4225. entity.ctid = tObj.refOid;
  4226. entity.tid = tObj.refOid;
  4227. entity.payment = Convert.ToDouble(tObj.payment);
  4228. if (tObj.payTime != null)
  4229. {
  4230. entity.pay_time = StampToDateTime(tObj.payTime);
  4231. }
  4232. CeErpShop nShop = CeErpShop.GetShopIdByName(tObj.openSellerNick);
  4233. int shopId = 0;
  4234. if (nShop != null)
  4235. {
  4236. shopId = nShop.ID;
  4237. }
  4238. entity.ShopId = shopId;
  4239. if (isXianhuo)
  4240. {
  4241. entity.OrderState = 6;//现货直接下单完成
  4242. entity.seller_memo = xianhuoMemo;
  4243. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  4244. entity.IsXianHuo = 1;
  4245. entity.FinishPlaceTime = entity.pay_time;
  4246. if (xianhuoMemo.IndexOf("封酒贴") != -1)
  4247. {
  4248. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  4249. if (trade.buyer_memo != "")
  4250. {
  4251. entity.OrderState = 2; //买家有备注的要设计
  4252. entity.ProductId = 1;
  4253. entity.IsXianHuo = 0;
  4254. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  4255. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  4256. entity.seller_memo = xianhuoMemo;
  4257. }
  4258. }
  4259. else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  4260. {
  4261. entity.SupplierId = 70; //智涛
  4262. }
  4263. //if (trade != null)
  4264. //{
  4265. // trade.seller_memo = xianhuoMemo;
  4266. // trade.Update();
  4267. //}
  4268. }
  4269. entity.Create();
  4270. commonHelper.setSpuData(trade);
  4271. }
  4272. catch (Exception ex)
  4273. {
  4274. XLog.SaveLog(0, ex.Message);
  4275. }
  4276. }
  4277. if (tObj.sellerMemo.Length > 0)
  4278. {
  4279. try
  4280. {
  4281. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  4282. }
  4283. catch (Exception ex)
  4284. {
  4285. XLog.SaveLog(0, res + "|" + ex.Message);
  4286. }
  4287. }
  4288. ////生成档案客户信息
  4289. //insertCustomerInfo(tObj);
  4290. }
  4291. public static int isOldCustomerOrder(CeErpTrade father)
  4292. {
  4293. if (father.seller_nick == "") return 0;
  4294. CeErpCustomer cusone = null;
  4295. cusone = CeErpCustomer.GetByNick(father.buyer_nick);
  4296. if (cusone != null)
  4297. {
  4298. return 1;
  4299. }
  4300. return 0;
  4301. }
  4302. public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
  4303. {
  4304. if (father.seller_nick == "") return 0;
  4305. CeErpCustomer cus = null;
  4306. cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
  4307. if (cus == null)
  4308. {
  4309. cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
  4310. }
  4311. int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
  4312. //CeErpCustomer cusone = null;
  4313. //cusone = CeErpCustomer.GetByNick(father.buyer_nick);
  4314. if (cus != null)
  4315. {
  4316. if (cus.lastbuy_time.ToString() == "") return 0;
  4317. if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
  4318. //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  4319. //cus.phone = Obj.receiver_mobile;
  4320. cus.buyer_id = father.buyer_id;
  4321. int returnNum = 0;
  4322. int lastpCount = cus.product_count;
  4323. if (cus.lastTid == father.tid)
  4324. {
  4325. if (pcount != cus.product_count)
  4326. {
  4327. cus.product_count = pcount;
  4328. cus.Update();
  4329. }
  4330. }
  4331. else
  4332. {
  4333. TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
  4334. cus.buyer_nick = father.buyer_nick;
  4335. cus.buy_day = Convert.ToInt32(tsday.TotalDays);
  4336. cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
  4337. cus.buy_count = cus.buy_count + 1;
  4338. cus.lastbuy_time2 = cus.lastbuy_time;
  4339. cus.lastbuy_time = father.pay_time;
  4340. cus.product_count = pcount;
  4341. cus.lastTid2 = cus.lastTid;
  4342. cus.lastTid = father.tid;
  4343. cus.Update();
  4344. }
  4345. if (cus.buy_day > 1)
  4346. {
  4347. if (pcount > lastpCount && cus.product_count != 0)
  4348. {
  4349. cus.isMore = 1;
  4350. returnNum = 2;
  4351. }
  4352. else
  4353. returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
  4354. }
  4355. else
  4356. {
  4357. returnNum = 0;
  4358. }
  4359. return returnNum;
  4360. }
  4361. //else if (cusone != null)
  4362. //{
  4363. // cusone.seller_nick = father.seller_nick;
  4364. // TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cusone.lastbuy_time);
  4365. // cusone.buy_day = Convert.ToInt32(tsday.TotalDays);
  4366. // cusone.total_fee = cusone.total_fee + Convert.ToDouble(father.payment);
  4367. // cusone.buy_count = cusone.buy_count + 1;
  4368. // cusone.lastbuy_time2 = cusone.lastbuy_time;
  4369. // cusone.lastbuy_time = father.pay_time;
  4370. // cusone.product_count = pcount;
  4371. // cusone.lastTid2 = cusone.lastTid;
  4372. // cusone.lastTid = father.tid;
  4373. // cusone.Update();
  4374. // return 1;
  4375. //}
  4376. else
  4377. {
  4378. try
  4379. {
  4380. cus = new CeErpCustomer();
  4381. cus.buyer_nick = father.buyer_nick;
  4382. cus.seller_nick = father.seller_nick;
  4383. cus.buyer_id = father.buyer_id;
  4384. //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  4385. //cus.phone = Obj.receiver_mobile;
  4386. cus.buy_day = 0;
  4387. cus.buy_count = 1;
  4388. cus.lastbuy_time = father.pay_time;
  4389. cus.lastTid = father.tid;
  4390. cus.total_fee = Convert.ToDouble(father.payment);
  4391. cus.product_count = pcount;
  4392. cus.Create();
  4393. //StringBuilder sql = new StringBuilder();
  4394. //sql.AppendFormat("select * from Sheet2$ where customer_name='{0}' and CHARINDEX(company_name,'{1}')>0 ", father.buyer_nick,father.seller_nick);
  4395. //DataTable dt = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
  4396. //if (dt.Rows.Count > 0)
  4397. //{
  4398. // return true;
  4399. //}
  4400. return 0;
  4401. }
  4402. catch (Exception ex)
  4403. {
  4404. XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
  4405. }
  4406. }
  4407. return 0;
  4408. }
  4409. public static void removeOldCustomerInfo(CeErpTrade trade)
  4410. {
  4411. CeErpCustomer cus = null;
  4412. cus = CeErpCustomer.GetByNickAndShop(trade.buyer_nick, trade.seller_nick);
  4413. if (cus != null)
  4414. {
  4415. if (cus.lastTid == trade.tid)
  4416. {
  4417. if (cus.buy_count > 1)
  4418. {
  4419. cus.lastTid = cus.lastTid2;
  4420. cus.lastbuy_time = cus.lastbuy_time2;
  4421. cus.buy_count = cus.buy_count - 1;
  4422. cus.Update();
  4423. }
  4424. else
  4425. {
  4426. CeErpCustomer.Del(cus.ID);
  4427. }
  4428. }
  4429. }
  4430. }
  4431. //接收到--新订单生成消息
  4432. public static void API_Tmc_TradeBuyerPay(string content)
  4433. {
  4434. Api_tmc_trade_info_Obj fullObj = null;
  4435. if (content == "") return;
  4436. try
  4437. {
  4438. content = GetUTF8String(Encoding.UTF8.GetBytes(content));
  4439. //res = res.Replace(" ", "");
  4440. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
  4441. }
  4442. catch (Exception ex)
  4443. {
  4444. }
  4445. if (fullObj == null)
  4446. {
  4447. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  4448. return;
  4449. }
  4450. Content tObj = fullObj.content;
  4451. string res = apiHelper.API_TradeFullinfoGet(tObj.refOid); //taobaoHelper.test();
  4452. Api_Tmc_CreateNewOrder(res);
  4453. }
  4454. //推送接收到卖家备注修改
  4455. public static void API_Tmc_TradeMemoModified(string content)
  4456. {
  4457. Api_tmc_trade_info_Obj fullObj = null;
  4458. if (content == "") return;
  4459. try
  4460. {
  4461. content = GetUTF8String(Encoding.UTF8.GetBytes(content));
  4462. //res = res.Replace(" ", "");
  4463. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
  4464. }
  4465. catch (Exception ex)
  4466. {
  4467. }
  4468. if (fullObj == null)
  4469. {
  4470. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  4471. return;
  4472. }
  4473. Content tObj = fullObj.content;
  4474. //原始表--没有这个单,不能拆分
  4475. CeErpTrade mainEn = CeErpTrade.Get(tObj.refOid);
  4476. if (mainEn == null) return;
  4477. createCellOrder(mainEn, tObj.refOid, tObj.sellerMemo, tObj.sellerMemo);
  4478. }
  4479. public static int orderAudit(int shopId)
  4480. {
  4481. try
  4482. {
  4483. CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
  4484. if (ceErpShop == null) return 2;
  4485. if (!ceErpShop.orderAudit) return 2;
  4486. return -1;
  4487. }
  4488. catch (Exception ex)
  4489. {
  4490. return 2;
  4491. }
  4492. }
  4493. public static void autoCell(string tid)
  4494. {
  4495. if (tid.Length == 0)
  4496. {
  4497. return;
  4498. }
  4499. DateTime nowTime = DateTime.Now;
  4500. if (nowTime.Hour < 9 || nowTime.Hour > 18)//超出时间
  4501. {
  4502. return;
  4503. }
  4504. try
  4505. {
  4506. string sql = string.Format("select ctid,IsOldCustomer,shopid from view_ErpTradeCell where tid='{0}' and orderstate=2 and productid<>0 and designuserid=0 and payment>0 and isrefund=0 order by IsUrgency desc,pay_time asc;", tid);
  4507. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4508. if (dt != null && dt.Rows.Count > 0)
  4509. {
  4510. bool changeBl = false;
  4511. //int c = Convert.ToInt32(result);// / 20 + 1;
  4512. foreach (DataRow dr in dt.Rows)
  4513. {
  4514. if (nowTime.Hour > 12 && nowTime.Hour < 17)
  4515. {
  4516. //这段时间白班晚班平均分配
  4517. if (changeBl)
  4518. {
  4519. changeBl = false;
  4520. }
  4521. else
  4522. {
  4523. changeBl = true;
  4524. }
  4525. }
  4526. else
  4527. changeBl = false;
  4528. string IsOldCustomer = dr["IsOldCustomer"].ToString();
  4529. string res = "";
  4530. CeErpShop ceErpShop = CeErpShop.Get(dr["shopid"]);
  4531. int userId = 0;
  4532. if (ceErpShop != null)
  4533. {
  4534. userId = ceErpShop.UserID;
  4535. }
  4536. SqlParameter[] sqlParameter = {
  4537. new SqlParameter("@inctid", SqlDbType.VarChar,200),
  4538. new SqlParameter("@intype", SqlDbType.Int,5),
  4539. new SqlParameter("@res", SqlDbType.VarChar, 50) };
  4540. sqlParameter[0].Value = dr["ctid"].ToString();
  4541. sqlParameter[1].Value = changeBl ? 1 : 0;
  4542. sqlParameter[2].Direction = ParameterDirection.Output;
  4543. if (IsOldCustomer == "1" && userId == 241)//老客户分给指定部门
  4544. {
  4545. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch_day", sqlParameter);
  4546. }
  4547. else
  4548. {
  4549. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch", sqlParameter);
  4550. }
  4551. res = sqlParameter[2].Value.ToString();
  4552. }
  4553. }
  4554. }
  4555. catch (Exception ex)
  4556. {
  4557. XLog.SaveLog(0, tid + "|实时派单错误|" + ex.Message);
  4558. }
  4559. }
  4560. }
  4561. }