tmcHelper.cs 182 KB

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