tmcHelper.cs 177 KB

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