tmcHelper.cs 196 KB

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