tmcHelper.cs 196 KB

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