tmcHelper.cs 196 KB

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