tmcHelper.cs 179 KB

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