preSalesHelper.cs 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using NHibernate.Cache;
  4. using NHibernate.Engine;
  5. using NPOI.OpenXmlFormats.Shared;
  6. using NPOI.OpenXmlFormats.Wordprocessing;
  7. using NPOI.SS.Formula.Functions;
  8. using SiteCore.Handler;
  9. using SiteCore.taoObj;
  10. using SQLData;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Collections.Specialized;
  14. using System.Data;
  15. using System.Linq;
  16. using System.Net;
  17. using System.Reflection;
  18. using System.Security.Cryptography.X509Certificates;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Web;
  22. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  23. using static SiteCore.taoObj.Api_refund_info;
  24. using static SiteCore.taoObj.Api_trade_info;
  25. using static SiteCore.taoObj.Refunds_receive_get_response_Obj;
  26. using static SiteCore.taoObj.work_core_vo;
  27. namespace SiteCore.Handler
  28. {
  29. public class preSalesHelper : BaseHandler, IHttpHandler
  30. {
  31. public void ProcessRequest(HttpContext context)
  32. {
  33. if (UrlParmsCheck("t"))
  34. {
  35. String tname = GetString("t");
  36. MethodInfo method;
  37. Type type = this.GetType();
  38. method = type.GetMethod(tname);
  39. con = context;
  40. if (method == null)
  41. {
  42. conError("找不到对应方法,服务器返回错误");
  43. return;
  44. }
  45. successFlag = false;
  46. context.Response.ContentType = "application/json";
  47. context.Response.Headers.Set("Access-Control-Allow-Origin", "*");
  48. try
  49. {
  50. method.Invoke(this, null);
  51. }
  52. catch (Exception ex)
  53. {
  54. XLog.SaveLog(0, "preSalesHelper:" + ex);
  55. conError("处理接口错误,服务器返回错误");
  56. }
  57. finally
  58. {
  59. }
  60. }
  61. }
  62. /**
  63. * 加急
  64. * ctid
  65. * name 客服名称
  66. * urgencytime 出货时间
  67. **/
  68. public void set_urgency()
  69. {
  70. if (UrlPostParmsCheck("ctid"))
  71. {
  72. string eid = GetPostString("ctid");
  73. string name = GetPostString("name");
  74. int UserID = GetPostInt("UserID");
  75. CeErpTradeCell entity = null;
  76. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  77. if (entity != null)
  78. {
  79. string utime = GetPostString("urgencytime");
  80. if (utime.Length > 0)
  81. {
  82. entity.UrgencyTime = Convert.ToDateTime(utime);
  83. }
  84. else
  85. {
  86. returnErrorMsg("请选择加急时间");
  87. return;
  88. }
  89. if (entity.OrderState <= 4 || entity.ctid.IndexOf("S_") != -1)
  90. {
  91. //entity.seller_memo = entity.seller_memo + "-加急";
  92. string smemo = entity.seller_memo;
  93. int kindex = smemo.IndexOf(")");
  94. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  95. if (lastoneStr != "-")
  96. {
  97. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  98. }
  99. string prememo = smemo.Substring(0, kindex + 2);
  100. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  101. int lastkindex = lastmemo.IndexOf("(");
  102. DateTime urgtime = Convert.ToDateTime(utime);
  103. string newlastmemo = "";
  104. if (lastkindex == 0)
  105. {
  106. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  107. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  108. }
  109. else
  110. {
  111. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  112. }
  113. entity.seller_memo = prememo + newlastmemo;
  114. }
  115. entity.IsUrgency = true;
  116. entity.Update();
  117. LogHelper.addLog(eid, UserID, name + "手动订单加急", 0, 1);
  118. returnSuccessMsg("设置成功!");
  119. return;
  120. }
  121. returnErrorMsg("找不到记录");
  122. return;
  123. }
  124. returnErrorMsg("缺少必要的参数ctid");
  125. }
  126. /**
  127. * 拿样
  128. * ctid
  129. *
  130. **/
  131. public void upd_sampleorder()
  132. {
  133. if (UrlPostParmsCheck("ctid"))
  134. {
  135. string eid = GetPostString("ctid");
  136. int UserID = GetPostInt("UserID");
  137. string[] eArr = eid.Split(',');
  138. if (eArr.Length > 1)
  139. {
  140. List<string> eLst = new List<string>();
  141. for (int i = 0; i < eArr.Length; i++)
  142. {
  143. eLst.Add("'" + eArr[i] + "'");
  144. }
  145. eid = string.Join(",", eLst.ToArray());
  146. }
  147. else
  148. {
  149. eid = "'" + eid + "'";
  150. }
  151. StringBuilder sql = new StringBuilder();
  152. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  153. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  154. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  155. if (dt.Rows.Count > 0)
  156. {
  157. string errmsg = "";
  158. foreach (DataRow dr in dt.Rows)
  159. {
  160. StringBuilder sqlsb = new StringBuilder();
  161. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  162. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), UserID);
  163. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  164. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  165. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  166. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  167. {
  168. continue;
  169. }
  170. else
  171. {
  172. string emsg = commonHelper.KeepChinese(apires);
  173. errmsg += emsg;
  174. }
  175. }
  176. if (errmsg.Length > 0)
  177. {
  178. returnErrorMsg(errmsg);
  179. return;
  180. }
  181. returnSuccessMsg("操作成功");
  182. return;
  183. }
  184. returnErrorMsg("找不到记录");
  185. return;
  186. }
  187. returnErrorMsg("缺少必要的参数ctid");
  188. }
  189. /**
  190. * 标记售后
  191. *
  192. * ctid
  193. * AfterSaleReason 理由
  194. * name 客服名称
  195. **/
  196. public void set_atersale()
  197. {
  198. if (UrlPostParmsCheck("ctid"))
  199. {
  200. string eid = GetPostString("ctid");
  201. string reason = GetPostString("AfterSaleReason");
  202. string name = GetPostString("name");
  203. int UserID = GetPostInt("UserID");
  204. CeErpTradeCell entity = null;
  205. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  206. if (entity != null)
  207. {
  208. if (entity.AfterSaleState > 0)
  209. {
  210. returnErrorMsg("此订单已经在售后");
  211. return;
  212. }
  213. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  214. //entity.AfterSaleReason = reason;
  215. entity.AfterSaleTime = DateTime.Now;
  216. entity.Update();
  217. LogHelper.addLog(entity.ctid, UserID, name + "标记售后-" + reason, entity.OrderState, 1);
  218. returnSuccessMsg("转售后成功!");
  219. return;
  220. }
  221. returnErrorMsg("找不到记录");
  222. return;
  223. }
  224. returnErrorMsg("缺少必要的参数ctid");
  225. }
  226. /**
  227. * 关联
  228. * ctid
  229. * ftid 关联单号
  230. * name 客服名称
  231. **/
  232. public void upd_setrelationorder()
  233. {
  234. if (UrlPostParmsCheck("ctid"))
  235. {
  236. string eid = GetPostString("ctid");
  237. string ftid = GetPostString("ftid");
  238. string name = GetPostString("name");
  239. int UserID = GetPostInt("UserID");
  240. CeErpTradeCell entity = null;
  241. CeErpTradeCell fentity = null;
  242. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  243. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  244. if (fentity == null)
  245. {
  246. returnErrorMsg("找不到关联的主订单");
  247. return;
  248. }
  249. if (entity != null)
  250. {
  251. if (entity.OrderState >= 5)
  252. {
  253. returnErrorMsg("本单已经设计完成无法关联");
  254. return;
  255. }
  256. entity.ptid = ftid;
  257. entity.OrderState = fentity.OrderState;
  258. //entity.status = fentity.status;
  259. entity.CustomerUserId = fentity.CustomerUserId;
  260. entity.DesignUserId = fentity.DesignUserId;
  261. entity.seller_memo = "补差价单:" + ftid;
  262. entity.IsSample = 2;
  263. entity.Update();
  264. LogHelper.addLog(entity.ctid, UserID, name + "手动关联补差价", entity.OrderState, 1);
  265. returnSuccessMsg("关联成功!");
  266. return;
  267. }
  268. returnErrorMsg("找不到记录");
  269. return;
  270. }
  271. returnErrorMsg("缺少必要的参数ctid");
  272. }
  273. /**
  274. * 预发货
  275. * ctid
  276. * name 客服名称
  277. **/
  278. public void set_predelivery()
  279. {
  280. if (UrlPostParmsCheck("ctid"))
  281. {
  282. string eid = GetPostString("ctid");
  283. string name = GetPostString("name");
  284. int UserID = GetPostInt("UserID");
  285. CeErpTradeCell entity = null;
  286. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  287. if (entity != null)
  288. {
  289. entity.IsPreDelivery = 1;
  290. entity.Update();
  291. LogHelper.addLog(entity.ctid, UserID, name + "预发货", entity.OrderState);
  292. returnSuccessMsg("预发货成功!");
  293. return;
  294. }
  295. returnErrorMsg("找不到订单记录");
  296. return;
  297. }
  298. returnErrorMsg("缺少必要的参数ctid");
  299. }
  300. /**
  301. * 返现
  302. * tid
  303. * type : 送样返现、退款返现、好评返现、多拍返现、微信返现、其他返现
  304. * seller_nick 店铺名称
  305. * payment 支付金额
  306. * buyer_nick 买家名称
  307. * returnprice 返现金额
  308. * con 说明
  309. * img 图片地址
  310. **/
  311. public void ins_returncashrecord()
  312. {
  313. if (UrlPostParmsCheck("tid"))
  314. {
  315. string tid = GetPostString("tid");
  316. string retype = GetPostString("type");
  317. string name = GetPostString("name");
  318. int UserID = GetPostInt("UserID");
  319. StringBuilder sql = new StringBuilder();
  320. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  321. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  322. if (dt.Rows.Count > 0)
  323. {
  324. returnErrorMsg("相同返现类型记录已存在");
  325. return;
  326. }
  327. CeErpReturnCash entity = new CeErpReturnCash();
  328. entity.tid = tid;
  329. entity.seller_nick = GetPostString("seller_nick");
  330. string pment = GetPostString("payment");
  331. if (pment.Length > 0)
  332. {
  333. entity.payment = Convert.ToDouble(pment);
  334. }
  335. entity.buyer_nick = GetPostString("buyer_nick");
  336. entity.cashstate = 0;
  337. entity.rtype = retype;
  338. string rPrice = GetPostString("returnprice");
  339. if (rPrice.Length > 0)
  340. {
  341. entity.returnprice = Convert.ToDouble(rPrice);
  342. }
  343. entity.created = DateTime.Now;
  344. entity.con = GetPostString("con");
  345. entity.img = GetPostString("img");
  346. entity.applyuserid = UserID;
  347. entity.Create();
  348. LogHelper.addLog(entity.tid, UserID, name + "添加:" + entity.rtype);
  349. returnSuccessMsg("操作成功!");
  350. return;
  351. }
  352. returnErrorMsg("缺少必要的参数tid");
  353. }
  354. /**
  355. *指派
  356. *ctid
  357. *DesignUserId
  358. *name
  359. **/
  360. public void upd_distributedesigner()
  361. {
  362. if (UrlPostParmsCheck("ctid"))
  363. {
  364. string eid = GetPostString("ctid");
  365. int userid = GetPostInt("DesignUserId");
  366. string custom_name = GetPostString("name");
  367. int UserID = GetPostInt("UserID");
  368. string[] idlist = eid.Split(',');
  369. if (idlist.Length <= 0)
  370. {
  371. returnErrorMsg("订单不能为空");
  372. return;
  373. }
  374. foreach (string ctid in idlist)
  375. {
  376. CeErpTradeCell entity = null;
  377. CeErpDesignerBill entitys = null;
  378. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  379. else continue;
  380. if (entity != null)
  381. {
  382. if (userid == 2125)
  383. {
  384. CeErpOrderFormData formData = null;
  385. formData = CeErpOrderFormData.GetByTid(entity.ctid);
  386. if (formData == null)
  387. {
  388. returnErrorMsg("请填写订单的手机号或者微信号才可指派到设计系统");
  389. return;
  390. }
  391. }
  392. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  393. {
  394. returnErrorMsg("金额错误的订单无法指派");
  395. return;
  396. }
  397. if (entity.OrderState >= 5)
  398. {
  399. returnErrorMsg("已经设计完成无法指派");
  400. return;
  401. }
  402. if (entity.OrderState == -1)
  403. {
  404. returnErrorMsg("审核中的订单无法指派");
  405. return;
  406. }
  407. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  408. {
  409. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  410. return;
  411. }
  412. if (entity.DispatchSort == 2 && userid != 3542)
  413. {
  414. returnErrorMsg("指派设计共创无法再次指派!");
  415. return;
  416. }
  417. CeErpUserPost userEntity = CeErpUserPost.GetByUserID(userid);
  418. if (userEntity != null && entity.ctid.IndexOf("S_") == -1 && userEntity.OrgID == 10)
  419. {
  420. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  421. entity.SupplierId = suid;
  422. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  423. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  424. }
  425. if (userid == 2125 && entity.seller_memo != "")
  426. {
  427. apiDesign.API_GetPrintData_CreateOrder(entity);
  428. }
  429. if (userid == 3542 && entity.seller_memo != "")
  430. {
  431. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity);
  432. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  433. if (response.msg != "设计共创:成功")
  434. {
  435. returnErrorMsg(response.msg);
  436. return;
  437. }
  438. entity.DispatchSort = 2;
  439. }
  440. entity.DesignUserId = userid;
  441. entity.OrderState = 3;
  442. entity.WaitDesignTime = DateTime.Now;
  443. entity.Update();
  444. string name = commonHelper.getUserNameById(userid);
  445. commonHelper.UpdateRelationOrder(entity.ctid);
  446. LogHelper.addLog(entity.ctid, UserID, custom_name + "指派设计师" + name + userid, entity.OrderState);
  447. }
  448. }
  449. returnSuccessMsg("操作成功!");
  450. return;
  451. }
  452. returnErrorMsg("缺少必要的参数ctid");
  453. }
  454. /**
  455. *重置
  456. *ctid
  457. *name
  458. **/
  459. public void set_reset()
  460. {
  461. if (UrlPostParmsCheck("tid"))
  462. {
  463. string eid = GetPostString("tid");
  464. string name = GetPostString("name");
  465. int UserID = GetPostInt("UserID");
  466. string sql = "select ID,ctid, OrderState from CE_ErpTradeCell where tid='" + eid + "'";
  467. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  468. if (dt != null && dt.Rows.Count > 0)
  469. {
  470. foreach (DataRow dr in dt.Rows)
  471. {
  472. int OrderState = Convert.ToInt32(dr["OrderState"]);
  473. if (OrderState >= 4)
  474. {
  475. returnErrorMsg(dr["ctid"] + "财务要求已下单已发货无法重置");
  476. return;
  477. }
  478. }
  479. }
  480. CeErpTradeCell.ExecuteNonQuery("delete from CE_ErpTradeCell where tid='" + eid + "'");
  481. CeErpTrade.ExecuteNonQuery("delete from CE_ErpTrade where tid='" + eid + "'");
  482. CeErpTradeOrder.ExecuteNonQuery("delete from CE_ErpTradeOrder where tid='" + eid + "'");
  483. returnSuccessMsg("重置成功!");
  484. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(eid);
  485. if (desginBill != null)
  486. {
  487. desginBill.isDel = 1;
  488. desginBill.Update();
  489. LogHelper.addDesignerBillLog(eid, UserID, name + "订单重置", name, 0);
  490. }
  491. return;
  492. }
  493. returnErrorMsg("缺少必要的参数tid");
  494. }
  495. /**
  496. * 清空退款状态
  497. * ctid
  498. * name
  499. **/
  500. public void clear_refundstate()
  501. {
  502. if (UrlPostParmsCheck("ctid"))
  503. {
  504. string eids = GetPostString("ctid");
  505. string name = GetPostString("name");
  506. int UserID = GetPostInt("UserID");
  507. string[] ctidList = eids.Split(',');
  508. foreach (string ctid in ctidList)
  509. {
  510. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  511. if (entity != null)
  512. {
  513. entity.IsRefund = 0;
  514. entity.Update();
  515. LogHelper.addLog(ctid, UserID, name + "清除退款状态", 0, 1);
  516. }
  517. else
  518. continue;
  519. }
  520. returnSuccessMsg("操作成功");
  521. return;
  522. }
  523. returnErrorMsg("缺少必要的参数ctid");
  524. }
  525. /**
  526. * 顺丰到付\顺丰寄付
  527. * ctid
  528. * memotag 顺丰到付、顺丰寄付、撤销顺丰
  529. * name
  530. **/
  531. public void upd_addmemotag()
  532. {
  533. if (UrlPostParmsCheck("ctid"))
  534. {
  535. int UserID = GetPostInt("UserID");
  536. string eid = GetPostString("ctid");
  537. string sfTagstr = GetPostString("memotag");
  538. string name = GetPostString("name");
  539. CeErpTradeCell entity = null;
  540. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  541. if (entity != null)
  542. {
  543. if (entity.OrderState == 0)
  544. {
  545. returnErrorMsg("请先领单");
  546. return;
  547. }
  548. //撤销顺丰
  549. if (sfTagstr == "撤销顺丰")
  550. {
  551. entity.IsSF = 0;
  552. string reMsg = "";
  553. string oldmemo = entity.seller_memo;
  554. if (entity.OrderState < 5)
  555. {
  556. oldmemo = oldmemo.Replace("顺丰到付", "");
  557. oldmemo = oldmemo.Replace("顺丰寄付", "");
  558. entity.seller_memo = oldmemo;
  559. }
  560. else
  561. {
  562. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  563. {
  564. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  565. }
  566. }
  567. entity.Update();
  568. LogHelper.addLog(entity.ctid, UserID, name + "撤销标记顺丰", entity.OrderState, 1);
  569. returnSuccessMsg("撤销成功!" + reMsg);
  570. return;
  571. }
  572. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  573. {
  574. //string oldmemo = entity.seller_memo;
  575. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  576. string sfStr = GetPostString("memotag");
  577. string smemo = entity.seller_memo;
  578. int kindex = smemo.IndexOf(")");
  579. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  580. if (lastoneStr != "-")
  581. {
  582. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  583. }
  584. string prememo = smemo.Substring(0, kindex + 2);
  585. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  586. int lastkindex = lastmemo.IndexOf("(");
  587. string newlastmemo = "";
  588. if (lastkindex == 0)
  589. {
  590. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  591. newlastmemo = "(" + sfStr + "." + useLastmemo;
  592. }
  593. else
  594. {
  595. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  596. }
  597. entity.seller_memo = prememo + newlastmemo;
  598. }
  599. string sfTagMSg = "";
  600. if (sfTagstr == "顺丰寄付")
  601. {
  602. entity.IsSF = 1;
  603. sfTagMSg = "顺丰寄付";
  604. }
  605. else if (sfTagstr == "顺丰到付")
  606. {
  607. entity.IsSF = 2;
  608. sfTagMSg = "顺丰到付";
  609. }
  610. entity.Update();
  611. LogHelper.addLog(entity.ctid, UserID, name + ":" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  612. returnSuccessMsg("标记成功!");
  613. return;
  614. }
  615. returnErrorMsg("找不到记录");
  616. return;
  617. }
  618. returnErrorMsg("缺少必要的参数ctid");
  619. }
  620. /**
  621. * 微信单
  622. * ctid
  623. * wechattag 1:微信返现 2:推购返现 3:挽回推多 4 :推多 5:推购
  624. * name
  625. **/
  626. public void upd_ordertag()
  627. {
  628. if (UrlPostParmsCheck("ctid"))
  629. {
  630. string name = GetPostString("name");
  631. string eid = GetPostString("ctid");
  632. int UserID = GetPostInt("UserID");
  633. CeErpTradeCell entity = null;
  634. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  635. if (entity != null)
  636. {
  637. int tag = GetPostInt("wechattag");
  638. //if(tag==4 && entity.IsSample == 2)
  639. //{
  640. // returnErrorMsg("补差价单不能标记微信单");
  641. // return;
  642. //}
  643. entity.wechatTag = tag;
  644. entity.Update();
  645. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  646. if (tag == 1)
  647. {
  648. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  649. if (cash == null)
  650. {
  651. CeErpTrade main = CeErpTrade.Get(entity.tid);
  652. cash = new CeErpReturnCash();
  653. cash.tid = entity.tid;
  654. cash.seller_nick = main.seller_nick;
  655. cash.payment = trade.payment;
  656. cash.buyer_nick = main.buyer_nick;
  657. cash.cashstate = 0;
  658. cash.rtype = "微信返现";
  659. cash.returnprice = 0;
  660. cash.created = DateTime.Now;
  661. cash.con = "订单标记微信单";
  662. cash.img = "";
  663. cash.applyuserid = UserID;
  664. cash.Create();
  665. LogHelper.addLog(entity.ctid, UserID, name + "添加:微信返现");
  666. }
  667. else
  668. {
  669. cash.cashstate = 0;
  670. cash.Update();
  671. }
  672. }
  673. else if (tag == 2)
  674. {
  675. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  676. if (cash == null)
  677. {
  678. CeErpTrade main = CeErpTrade.Get(entity.tid);
  679. cash = new CeErpReturnCash();
  680. cash.tid = entity.tid;
  681. cash.seller_nick = main.seller_nick;
  682. cash.payment = trade.payment;
  683. cash.buyer_nick = main.buyer_nick;
  684. cash.cashstate = 0;
  685. cash.rtype = "推购返现";
  686. cash.returnprice = 5;
  687. cash.created = DateTime.Now;
  688. cash.con = "订单标记推购单";
  689. cash.img = "";
  690. cash.applyuserid = UserID;
  691. cash.Create();
  692. LogHelper.addLog(entity.ctid, UserID, name + "添加:推购返现");
  693. }
  694. else
  695. {
  696. cash.cashstate = 0;
  697. cash.Update();
  698. }
  699. }
  700. else if (tag == 3)
  701. {
  702. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  703. if (pers == null)
  704. {
  705. pers = new CeErpPersuade();
  706. pers.ctid = entity.ctid;
  707. pers.pstate = 0;
  708. pers.created = DateTime.Now;
  709. pers.applyuserid = UserID;
  710. pers.Create();
  711. LogHelper.addLog(entity.ctid, UserID, name + "添加:挽回推多");
  712. }
  713. else
  714. {
  715. pers.pstate = 0;
  716. pers.Update();
  717. }
  718. }
  719. else if (tag == 4 || tag == 5)
  720. {
  721. CeErpTrade main = CeErpTrade.Get(entity.tid);
  722. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  723. if (pers == null)
  724. {
  725. pers = new CeErpStayGoods();
  726. pers.t_id = entity.tid;
  727. pers.status = "待审核";
  728. pers.audit_type = 0;
  729. if (tag == 4)
  730. {
  731. pers.stay_type = "推多";
  732. }
  733. else
  734. {
  735. pers.stay_type = "推购";
  736. }
  737. if (entity.IsXianHuo == 0)
  738. {
  739. pers.product_id = entity.ProductId;
  740. }
  741. pers.wangwang = main.buyer_nick;
  742. pers.shop_name = main.seller_nick;
  743. pers.creata_time = DateTime.Now;
  744. pers.create_u_id = UserID;
  745. pers.create_u_name = name;
  746. pers.Create();
  747. LogHelper.addLog(entity.ctid, UserID, name + "添加:推多推购");
  748. }
  749. else
  750. {
  751. pers.audit_type = 0;
  752. pers.Update();
  753. }
  754. }
  755. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  756. returnSuccessMsg("标记成功!");
  757. return;
  758. }
  759. returnErrorMsg("找不到记录");
  760. return;
  761. }
  762. returnErrorMsg("缺少必要的参数ctid");
  763. }
  764. /**
  765. * 小礼物
  766. * ctid
  767. * name
  768. **/
  769. public void upd_sendXlw()
  770. {
  771. if (UrlPostParmsCheck("ctid"))
  772. {
  773. string name = GetPostString("name");
  774. string eid = GetPostString("ctid");
  775. int UserID = GetPostInt("UserID");
  776. CeErpTradeCell entity = null;
  777. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  778. if (entity != null)
  779. {
  780. if (entity.IsSendGift == 1)
  781. {
  782. returnErrorMsg("请勿重复标记");
  783. return;
  784. }
  785. entity.IsSendGift = 1;
  786. entity.Update();
  787. LogHelper.addLog(eid, UserID, name + "送小礼物");
  788. returnSuccessMsg("操作成功!");
  789. return;
  790. }
  791. returnErrorMsg("找不到记录");
  792. return;
  793. }
  794. returnErrorMsg("缺少必要的参数ctid");
  795. }
  796. /**
  797. * 添加微信
  798. * ctid
  799. * name
  800. **/
  801. public void upd_addweichattag()
  802. {
  803. if (UrlPostParmsCheck("ctid"))
  804. {
  805. string name = GetPostString("name");
  806. string eid = GetPostString("ctid");
  807. int UserID = GetPostInt("UserID");
  808. CeErpTradeCell entity = null;
  809. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  810. if (entity != null)
  811. {
  812. if (entity.IsAddWechat > 0)
  813. {
  814. returnErrorMsg("此单已经标记过了");
  815. return;
  816. }
  817. string sql = string.Format("select * from view_erptradecell where IsAddWechat>0 and buyer_nick=(select buyer_nick from ce_erptrade where tid='{0}')", entity.tid);
  818. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  819. if (dt.Rows.Count > 0)
  820. {
  821. entity.IsAddWechat = 2;
  822. }
  823. else
  824. {
  825. entity.IsAddWechat = 1;
  826. }
  827. entity.Update();
  828. LogHelper.addLog(entity.ctid, UserID, name + "标记已添加微信", entity.OrderState, 1);
  829. returnSuccessMsg("标记成功!");
  830. return;
  831. }
  832. returnErrorMsg("找不到记录");
  833. return;
  834. }
  835. returnErrorMsg("缺少必要的参数ctid");
  836. }
  837. /**
  838. * 售后
  839. *
  840. * id 售后单id
  841. * afterstate 1认可0不认可
  842. * supmemo 理由
  843. * image 图片
  844. **/
  845. public void upd_personaftersale()
  846. {
  847. if (UrlPostParmsCheck("id"))
  848. {
  849. string id = GetPostString("id");
  850. int UserID = GetPostInt("UserID");
  851. int st = GetPostInt("afterstate");
  852. string afmemo = GetPostString("supmemo");
  853. string image = GetPostString("image");
  854. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  855. if (ceErpTradeResponsible != null)
  856. {
  857. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  858. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  859. ceErpTradeResponsible.Update();
  860. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  861. if (entity != null)
  862. {
  863. entity.AfterSaleSupplierMemo = afmemo;
  864. if (st == 1)
  865. {
  866. bool isAll = commonHelper.tradeResponsibleAll(entity);
  867. if (isAll)
  868. {
  869. entity.AfterSaleState = 4;
  870. entity.FinishAfterSaleTime = DateTime.Now;
  871. if (entity.AfterSaleResSupId > 0)
  872. {
  873. entity.AfterSaleSupplierState = 1;
  874. }
  875. }
  876. }
  877. else
  878. {
  879. CeErpTradeResponsible.dateByTid(entity.ctid);
  880. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  881. if (ceErpTradeAfterSaleExtend != null)
  882. {
  883. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  884. ceErpTradeAfterSaleExtend.Update();
  885. }
  886. else
  887. {
  888. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  889. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  890. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  891. ceErpTradeAfterSaleExtend.Create();
  892. }
  893. //退回到主管
  894. //entity.AfterSaleState = 2;
  895. }
  896. if (entity.AfterSaleState == 4)
  897. {
  898. ApiVo apiVo = new ApiVo();
  899. apiVo.orderNumber = entity.ctid;
  900. apiVo.actionName = "afterOver";
  901. designHelper.API_WorkCore(apiVo); //afterOver
  902. }
  903. entity.Update();
  904. returnSuccessMsg("操作成功!");
  905. LogHelper.addLog(entity.ctid, UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  906. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), UserID, st == 1 ? 0 : 1, afmemo, image);
  907. return;
  908. }
  909. }
  910. returnErrorMsg("找不到订单记录");
  911. return;
  912. }
  913. returnErrorMsg("缺少必要的参数id");
  914. }
  915. public void upd_erp_masteraftersale()
  916. {
  917. if (UrlPostParmsCheck("id"))
  918. {
  919. string id = GetPostString("id");
  920. int st = GetPostInt("afterstate");
  921. string afmemo = GetPostString("supmemo");
  922. string image = GetPostString("image");
  923. string textResult = GetPostString("textResult");
  924. int UserID = GetPostInt("UserID");
  925. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  926. if (ceErpTradeResponsible != null)
  927. {
  928. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  929. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  930. ceErpTradeResponsible.Update();
  931. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  932. if (entity != null)
  933. {
  934. entity.AfterSaleSupplierState = st;
  935. entity.AfterSaleSupplierMemo = afmemo;
  936. if (st == 1)
  937. {
  938. }
  939. else
  940. {
  941. CeErpTradeResponsible.dateByTid(entity.ctid);
  942. //退回到售后
  943. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  944. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  945. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  946. if (num <= 1)
  947. {
  948. entity.AfterSaleState = 1;
  949. }
  950. else
  951. {
  952. entity.AfterSaleState = 5;
  953. }
  954. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  955. if (ceErpTradeAfterSaleExtend != null)
  956. {
  957. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  958. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  959. ceErpTradeAfterSaleExtend.Update();
  960. }
  961. else
  962. {
  963. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  964. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  965. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  966. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  967. ceErpTradeAfterSaleExtend.Create();
  968. }
  969. }
  970. entity.Update();
  971. returnSuccessMsg("操作成功!");
  972. LogHelper.addLog(entity.ctid, UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  973. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), UserID, st == 1 ? 0 : 1, afmemo, image);
  974. return;
  975. }
  976. }
  977. returnErrorMsg("找不到订单记录");
  978. }
  979. }
  980. public void save_erp_billinfo()
  981. {
  982. if (UrlPostParmsCheck("ctid"))
  983. {
  984. string eid = GetPostString("ctid");
  985. CeErpTradeCell entity = null;
  986. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  987. if (entity != null)
  988. {
  989. CeErpBill bill = CeErpBill.GetByTid(eid);
  990. bool isHave = false;
  991. if (bill != null)
  992. {
  993. isHave = true;
  994. if (bill.state != 4)
  995. {
  996. returnErrorMsg("此单已经申请过发票了");
  997. return;
  998. }
  999. }
  1000. if (entity.IsNeedBill == 0)
  1001. {
  1002. entity.IsNeedBill = 1;
  1003. }
  1004. entity.Update();
  1005. string errjson = "";
  1006. try
  1007. {
  1008. CeErpBill bill_entity = new CeErpBill();
  1009. bill_entity.tid = entity.tid;
  1010. bill_entity.title = GetPostString("title");
  1011. string taxstr = GetPostString("tax");
  1012. taxstr = taxstr.Replace(" ", "");
  1013. bill_entity.tax = taxstr;
  1014. bill_entity.bank = GetPostString("bank");
  1015. string bankacstr = GetPostString("bankac");
  1016. bankacstr = bankacstr.Replace(" ", "");
  1017. bill_entity.bankac = bankacstr;
  1018. bill_entity.address = GetPostString("address");
  1019. bill_entity.phone = GetPostString("phone");
  1020. bill_entity.price = GetPostString("price");
  1021. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1022. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1023. {
  1024. billCount += 1;
  1025. }
  1026. string prebill = "ltb";
  1027. for (int idx = 1; idx <= billCount; idx++)
  1028. {
  1029. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1030. string billoid = prebill + idx + dtstr;
  1031. bill_entity.billOrderId += billoid;
  1032. if (idx < billCount)
  1033. {
  1034. bill_entity.billOrderId += ",";
  1035. }
  1036. }
  1037. bill_entity.productId = GetPostInt("ProductName");
  1038. bill_entity.num = GetPostInt("num");
  1039. bill_entity.unit = GetPostString("unit");
  1040. bill_entity.type = GetPostString("type");
  1041. bill_entity.sendType = GetPostString("SendType");
  1042. bill_entity.email = GetPostString("email");
  1043. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1044. bill_entity.shopName = GetPostString("ShopName");
  1045. bill_entity.applymemo = GetPostString("applyMemo");
  1046. bill_entity.createTime = DateTime.Now;
  1047. bill_entity.state = 0;
  1048. bill_entity.userId = 11;
  1049. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1050. bill_entity.Create();
  1051. }
  1052. catch (Exception ex)
  1053. {
  1054. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1055. returnErrorMsg("创建发票出错!");
  1056. return;
  1057. }
  1058. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1059. returnSuccessMsg("发票申请成功!");
  1060. return;
  1061. }
  1062. returnErrorMsg("找不到记录");
  1063. }
  1064. }
  1065. /**
  1066. * 查货
  1067. * ctid
  1068. * name
  1069. **/
  1070. public void ins_checkorder()
  1071. {
  1072. if (UrlPostParmsCheck("ctid"))
  1073. {
  1074. string ctid = GetPostString("ctid");
  1075. string name = GetPostString("name");
  1076. int UserID = GetPostInt("UserID");
  1077. CeErpTradeCell entity = null;
  1078. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1079. if (entity != null)
  1080. {
  1081. if (entity.OrderState < 6)
  1082. {
  1083. returnErrorMsg("下单完成后才可查货");
  1084. return;
  1085. }
  1086. if (entity.OrderState > 6)
  1087. {
  1088. returnErrorMsg("订单已发货");
  1089. return;
  1090. }
  1091. if (entity.FinishPlaceTime != null)
  1092. {
  1093. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  1094. {
  1095. returnErrorMsg("下单时间不足,无法查货");
  1096. return;
  1097. }
  1098. }
  1099. entity.MemoOpt = 3;
  1100. entity.CheckOrderTime = DateTime.Now;
  1101. entity.Update();
  1102. LogHelper.addLog(entity.ctid, UserID, name + "标记:查货", entity.OrderState, 1);
  1103. returnSuccessMsg("操作成功!");
  1104. return;
  1105. }
  1106. returnErrorMsg("找不到记录");
  1107. return;
  1108. }
  1109. returnErrorMsg("缺少必要的参数ctid");
  1110. }
  1111. public void ins_checkdesign()
  1112. {
  1113. if (UrlPostParmsCheck("ctid"))
  1114. {
  1115. string ctid = GetPostString("ctid");
  1116. string name = GetPostString("name");
  1117. int UserID = GetPostInt("UserID");
  1118. int memoopt = GetPostInt("memoopt");
  1119. CeErpTradeCell entity = null;
  1120. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1121. if (entity != null)
  1122. {
  1123. string stropt = "";
  1124. if (memoopt == 1)
  1125. {
  1126. stropt = "“改稿”";
  1127. }
  1128. else if (memoopt == 2)
  1129. {
  1130. stropt = "“定稿”";
  1131. }
  1132. entity.MemoOpt = memoopt;
  1133. entity.Update();
  1134. LogHelper.addLog(entity.ctid, UserID, name + "标记:" + stropt, entity.OrderState, 1);
  1135. returnSuccessMsg("操作成功!");
  1136. return;
  1137. }
  1138. returnErrorMsg("找不到记录");
  1139. return;
  1140. }
  1141. returnErrorMsg("缺少必要的参数ctid");
  1142. }
  1143. public void save_othermemo()
  1144. {
  1145. if (UrlPostParmsCheck("ctid"))
  1146. {
  1147. string ctid = GetPostString("ctid");
  1148. string name = GetPostString("name");
  1149. int UserID = GetPostInt("UserID");
  1150. CeErpTradeCell entity = null;
  1151. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1152. if (entity != null)
  1153. {
  1154. entity.OtherMemo = GetPostString("otherMemo");
  1155. entity.Update();
  1156. returnSuccessMsg("保存成功!");
  1157. LogHelper.addLog(entity.ctid, UserID, name + "额外:" + entity.OtherMemo, entity.OrderState);
  1158. return;
  1159. }
  1160. returnErrorMsg("找不到记录");
  1161. return;
  1162. }
  1163. returnErrorMsg("缺少必要的参数ctid");
  1164. }
  1165. public void save_customermemo()
  1166. {
  1167. if (UrlPostParmsCheck("ctid"))
  1168. {
  1169. string ctid = GetPostString("ctid");
  1170. CeErpTradeCell entity = null;
  1171. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1172. if (entity != null)
  1173. {
  1174. entity.CustomerMemo = GetPostString("CustomerMemo");
  1175. entity.Update();
  1176. ApiVo apiVo = new ApiVo();
  1177. apiVo.orderNumber = entity.ctid;
  1178. apiVo.actionName = "followRemarks";
  1179. apiVo.orderRemarks = entity.CustomerMemo;
  1180. designHelper.API_WorkCore(apiVo);//followRemarks
  1181. returnSuccessMsg("保存成功!");
  1182. return;
  1183. }
  1184. returnErrorMsg("找不到记录");
  1185. }
  1186. }
  1187. public void create_order()
  1188. {
  1189. if (UrlPostParmsCheck("data"))
  1190. {
  1191. string data = GetPostString("data");
  1192. Api_trade_info info = null;
  1193. try
  1194. {
  1195. info = JsonConvert.DeserializeObject<Api_trade_info>(data);
  1196. }
  1197. catch (Exception ex)
  1198. {
  1199. XLog.SaveLog(0, "create_order|1|" + ex.Message);
  1200. returnErrorMsg(ex.Message);
  1201. return;
  1202. }
  1203. if (info == null)
  1204. {
  1205. XLog.SaveLog(0, "Api_trade_info isNull");
  1206. return;
  1207. }
  1208. BizOrder bizOrder = info.bizOrder;
  1209. if (bizOrder == null)
  1210. {
  1211. returnErrorMsg("接口对象处理错误bizOrder=null");
  1212. return;
  1213. }
  1214. bool isCreate = false;
  1215. CeErpTrade trade = null;
  1216. trade = CeErpTrade.Get(bizOrder.thirdOrderId);
  1217. if (trade == null)
  1218. {
  1219. isCreate = true;
  1220. }
  1221. List<tempResponse> callResult = null;
  1222. try
  1223. {
  1224. trade = createTradeOrder(bizOrder, trade, isCreate);
  1225. List<Api_trade_info.TradeItemOrder> orderList = bizOrder.bizOrderItems;
  1226. createItemOrder(orderList, trade);
  1227. List<Api_trade_info.bizOrderSplit> bizOrderSplit = bizOrder.bizOrderSplits;
  1228. callResult = createCellOrder(bizOrderSplit, trade, isCreate);
  1229. }
  1230. catch (Exception ex)
  1231. {
  1232. XLog.SaveLog(0, "create_order|2|" + ex);
  1233. returnErrorMsg(ex.Message);
  1234. return;
  1235. }
  1236. returnSuccessMsg(JsonConvert.SerializeObject(callResult));
  1237. return;
  1238. }
  1239. returnErrorMsg("缺少必要的参数data");
  1240. }
  1241. public void refundOrder()
  1242. {
  1243. if (UrlPostParmsCheck("data"))
  1244. {
  1245. string data = GetPostString("data");
  1246. Api_refund_info info = null;
  1247. try
  1248. {
  1249. info = JsonConvert.DeserializeObject<Api_refund_info>(data);
  1250. }
  1251. catch (Exception ex)
  1252. {
  1253. XLog.SaveLog(0, "refundOrder|4|" + ex.Message);
  1254. returnErrorMsg(ex.Message);
  1255. return;
  1256. }
  1257. if (info == null)
  1258. {
  1259. XLog.SaveLog(0, "Api_refund_info isNull");
  1260. returnErrorMsg("接口对象处理错误RefundOrder=null1");
  1261. return;
  1262. }
  1263. RefundOrder refundOrder = info.refundOrder;
  1264. if (refundOrder == null)
  1265. {
  1266. returnErrorMsg("接口对象处理错误RefundOrder=null2");
  1267. return;
  1268. }
  1269. CeErpTrade trade = CeErpTrade.Get(refundOrder.tid);
  1270. if (trade != null)
  1271. {
  1272. CeErpTradeRefund refund = CeErpTradeRefund.GetByOidAndReId(refundOrder.ctid, refundOrder.orderSn);
  1273. LogHelper.addLog(refundOrder.ctid, 0, "客户退款", 0);
  1274. if (refund == null)
  1275. {
  1276. refund = new CeErpTradeRefund();
  1277. refund.refund_id = refundOrder.orderSn;
  1278. refund.tid = refundOrder.tid;
  1279. refund.oid = refundOrder.ctid;
  1280. if (refundOrder.createTime != null && refundOrder.createTime.Length > 0)
  1281. {
  1282. refund.created = Convert.ToDateTime(refundOrder.createTime);
  1283. }
  1284. if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
  1285. {
  1286. refund.modified = Convert.ToDateTime(refundOrder.updateTime);
  1287. }
  1288. refund.status = refundOrder.status;
  1289. refund.order_status = refundOrder.orderStatus;
  1290. refund.payment = refundOrder.payment.ToString();
  1291. refund.refund_fee = refundOrder.refundFee;//退款金额
  1292. refund.buyer_nick = GetNull_tostring(refundOrder.openBuyerNick);
  1293. refund.seller_nick = refundOrder.seller_nick;
  1294. refund.total_fee = refundOrder.totalFee;
  1295. refund.RefundState = 1;
  1296. refund.reason = refundOrder.reason;
  1297. refund.refundDesc = refundOrder.desc;
  1298. refund.IsPartRefund = refundOrder.isPartRefund;
  1299. refund.Create();
  1300. try
  1301. {
  1302. StringBuilder CeErpTradeCellSql = new StringBuilder();
  1303. CeErpTradeCellSql.AppendFormat("select * from CE_ErpTradeCell where ctid='{0}';", refundOrder.ctid);
  1304. DataSet cell = DbHelper.DbConn.ExecuteDataset(CeErpTradeCellSql.ToString());
  1305. DataTable datatable = cell.Tables[0];
  1306. if (datatable.Rows.Count > 0)
  1307. {
  1308. foreach (DataRow dr in datatable.Rows)
  1309. {
  1310. int DesignUserId = Convert.ToInt32(dr["DesignUserId"]);
  1311. int OrderState = Convert.ToInt32(dr["OrderState"]);
  1312. int CustomerUserId = Convert.ToInt32(dr["CustomerUserId"]);
  1313. if (DesignUserId > 0 && OrderState == 4)
  1314. {
  1315. createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, DesignUserId, 1);
  1316. }
  1317. if (CustomerUserId > 0)
  1318. {
  1319. createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, CustomerUserId, 1);
  1320. }
  1321. }
  1322. }
  1323. }
  1324. catch (Exception ex)
  1325. {
  1326. XLog.SaveLog(0, "退款推送通知创建失败!!" + ex);
  1327. }
  1328. int rstate = commonHelper.getRefundTagByState(refundOrder.status);
  1329. StringBuilder sql = new StringBuilder();
  1330. if (refund.IsPartRefund == 1)
  1331. {
  1332. double paylast = Convert.ToDouble(refundOrder.payment) - Convert.ToDouble(refund.refund_fee);
  1333. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1},payment={2} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 3, paylast);
  1334. }
  1335. else
  1336. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, rstate);
  1337. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1338. string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
  1339. //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  1340. StringBuilder sqls = new StringBuilder();
  1341. sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
  1342. CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
  1343. LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
  1344. }
  1345. else
  1346. {
  1347. if (refund.status != refundOrder.status)
  1348. {
  1349. refund.modified = DateTime.Now;
  1350. if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
  1351. {
  1352. refund.modified = Convert.ToDateTime(refundOrder.updateTime);
  1353. }
  1354. refund.order_status = refundOrder.orderStatus;
  1355. refund.status = refundOrder.status;
  1356. refund.Update();
  1357. int rstate = commonHelper.getRefundTagByState(refundOrder.status);
  1358. string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
  1359. StringBuilder sql = new StringBuilder();
  1360. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={0} where ctid='{1}' and isAfterSaleOrder=0;", rstate, refundOrder.ctid);
  1361. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1362. //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  1363. LogHelper.addLog(refundOrder.tid, 0, "更新退款状态:" + rstateWord, (int)OrderState.交易关闭);
  1364. // 取消设计费
  1365. StringBuilder sqls = new StringBuilder();
  1366. sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
  1367. CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
  1368. LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
  1369. }
  1370. }
  1371. List<RefundItemOrder> goodsItems = refundOrder.goodsItems;
  1372. foreach (RefundItemOrder item in goodsItems)
  1373. {
  1374. CeErpTradeOrder goods = CeErpTradeOrder.GetByOid(item.refOlId);
  1375. if (goods != null)
  1376. {
  1377. goods.refund_status = item.refundStatus;
  1378. goods.Update();
  1379. }
  1380. }
  1381. if (refundOrder.status == "WAIT_SELLER_AGREE")
  1382. {
  1383. StringBuilder sql = new StringBuilder();
  1384. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 1);
  1385. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1386. designHelper.API_refundOrder(refundOrder.tid, "refundIng", refundOrder.reason);
  1387. LogHelper.addLog(refundOrder.tid, 0, "申请退款中", 0);
  1388. }
  1389. else if (refundOrder.status == "CLOSED")
  1390. {
  1391. StringBuilder sql = new StringBuilder();
  1392. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 0);
  1393. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1394. designHelper.API_refundOrder(refundOrder.tid, "refundCancel", refundOrder.reason);
  1395. LogHelper.addLog(refundOrder.tid, 0, "关闭申请退款中", 0);
  1396. }
  1397. else if (refundOrder.status == "REFUNDED" || refundOrder.status == "SUCCESS")
  1398. {
  1399. designHelper.API_refundOrder(refundOrder.tid, "refundEd", refundOrder.reason);
  1400. }
  1401. }
  1402. else
  1403. {
  1404. }
  1405. }
  1406. returnErrorMsg("缺少必要的参数data");
  1407. }
  1408. public void createRefundMessage(string ctid, MessageState messageState, int userId, int type)
  1409. {
  1410. CeErpMessageTip ceErpMessageTip = new CeErpMessageTip();
  1411. ceErpMessageTip.tid = ctid;
  1412. ceErpMessageTip.type = Convert.ToInt32(messageState);
  1413. ceErpMessageTip.userId = userId;
  1414. ceErpMessageTip.isVisit = false;
  1415. ceErpMessageTip.content = "订单" + ctid + "申请了退款!";
  1416. ceErpMessageTip.Create();
  1417. StringBuilder sqlTip = new StringBuilder();
  1418. if (type == 1)
  1419. {
  1420. sqlTip.AppendFormat(" select top 1 B.id from view_ErpUser A JOIN view_ErpUser b ON a.OrgID = B.OrgID and b.PostName Like '设计主管%' WHERE A.ID = '{0}';", userId);
  1421. }
  1422. if (type == 2)
  1423. {
  1424. sqlTip.AppendFormat(" select top 1 B.id from view_ErpUser A JOIN view_ErpUser b ON a.OrgID = B.OrgID and b.PostName Like '店长%' WHERE A.ID = '{0}';", userId);
  1425. }
  1426. DataTable dth = DbHelper.DbConn.ExecuteDataset(sqlTip.ToString()).Tables[0];
  1427. if (dth.Rows.Count > 0)
  1428. {
  1429. foreach (DataRow dthdr in dth.Rows)
  1430. {
  1431. int Bid = Convert.ToInt32(dthdr["id"]);
  1432. if (Bid > 0)
  1433. {
  1434. CeErpMessageTip ceErpMessageTipB = new CeErpMessageTip();
  1435. ceErpMessageTipB.tid = ctid;
  1436. ceErpMessageTipB.type = Convert.ToInt32(messageState);
  1437. ceErpMessageTipB.userId = Bid;
  1438. ceErpMessageTipB.isVisit = false;
  1439. ceErpMessageTipB.content = "订单" + ctid + "申请了退款!";
  1440. ceErpMessageTipB.Create();
  1441. }
  1442. }
  1443. }
  1444. }
  1445. public List<tempResponse> createCellOrder(List<Api_trade_info.bizOrderSplit> bizOrderSplit, CeErpTrade trade, bool isCreate)
  1446. {
  1447. List<tempResponse> tempResponses = new List<tempResponse>();
  1448. CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
  1449. foreach (Api_trade_info.bizOrderSplit item in bizOrderSplit)
  1450. {
  1451. bool create = false;
  1452. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(item.splitNo);
  1453. if (entity == null)
  1454. {
  1455. entity = new CeErpTradeCell();
  1456. create = true;
  1457. entity.tid = trade.tid;
  1458. entity.pay_time = trade.pay_time;
  1459. }
  1460. if (entity.OrderState > 4)
  1461. {
  1462. continue;
  1463. }
  1464. entity.ctid = item.splitNo;
  1465. entity.seller_memo = item.systemRemark;
  1466. if (!string.IsNullOrEmpty(item.splitAmount))
  1467. {
  1468. entity.payment = Convert.ToDouble(item.splitAmount);
  1469. }
  1470. if (!string.IsNullOrEmpty(item.splitAmount))
  1471. {
  1472. entity.AfterSalePayment = Convert.ToDouble(item.splitAmount);
  1473. }
  1474. if (!string.IsNullOrEmpty(item.sfMark))
  1475. {
  1476. entity.IsSF = Convert.ToInt32(item.sfMark);
  1477. }
  1478. entity.ProductSize = item.size;
  1479. entity.Material = item.material;
  1480. entity.CustomerUserId = item.erpCustomerServiceId;
  1481. //entity.Craft = item.craft;
  1482. entity.ProductCount = item.productQuantity;
  1483. entity.ProductId = tmcHelper.getProductIdByName(item.cate3Id);
  1484. if (!string.IsNullOrEmpty(item.internalStatus))
  1485. {
  1486. entity.OrderState = Convert.ToInt32(item.internalStatus);
  1487. }
  1488. entity.IsUrgency = item.isUrgent;
  1489. entity.ptid = item.ptid;
  1490. entity.SplitTag = item.splitInfoNo;
  1491. if (!string.IsNullOrEmpty(item.paymentFile))
  1492. {
  1493. entity.PayProofImg = item.paymentFile;
  1494. }
  1495. if (item.shippingTime != null && item.shippingTime.Length > 0)
  1496. {
  1497. entity.UnusualTime = Convert.ToDateTime(item.shippingTime);
  1498. entity.UrgencyTime = Convert.ToDateTime(item.shippingTime);
  1499. }
  1500. if (!string.IsNullOrEmpty(item.sendGiftMark))
  1501. {
  1502. entity.IsSendGift = Convert.ToInt32(item.sendGiftMark);
  1503. }
  1504. entity.OtherMemo = item.otherRemark;
  1505. entity.IsOldCustomer = item.isRepurchase ? 1 : 0;
  1506. entity.IsOldCustomerMore = item.isOldCustomerMore;
  1507. entity.MemoOpt = item.memoOpt;
  1508. entity.isDianziOrder = item.isDianziOrder;
  1509. if (item.isPreShipping != null && item.isPreShipping.Length > 0)
  1510. {
  1511. entity.IsPreDelivery = Convert.ToInt32(item.isPreShipping);
  1512. }
  1513. if (item.checkOrderTime != null && item.checkOrderTime.Length > 0)
  1514. {
  1515. entity.CheckOrderTime = Convert.ToDateTime(item.checkOrderTime);
  1516. }
  1517. int shopId = 0;
  1518. if (nShop != null)
  1519. {
  1520. shopId = nShop.ID;
  1521. }
  1522. entity.ShopId = shopId;
  1523. entity.OrderSn = item.OrderSn;
  1524. entity.ParentSplitNo = item.parentSplitNo;
  1525. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1526. if (ceErpTradeCellExtend == null)
  1527. {
  1528. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  1529. ceErpTradeCellExtend.ctid = entity.ctid;
  1530. }
  1531. ceErpTradeCellExtend.cate1 = item.cate1;
  1532. ceErpTradeCellExtend.cate2 = item.cate2;
  1533. ceErpTradeCellExtend.scene = item.scene;
  1534. ceErpTradeCellExtend.material = item.material;
  1535. ceErpTradeCellExtend.offerAmount = item.offerAmount;
  1536. ceErpTradeCellExtend.numbers = item.numbers;
  1537. ceErpTradeCellExtend.typeScene = item.typeScene;
  1538. ceErpTradeCellExtend.opScene = item.opScene;
  1539. ceErpTradeCellExtend.craft = item.craft;
  1540. ceErpTradeCellExtend.numberType = item.numberType;
  1541. ceErpTradeCellExtend.cate1Id = item.cate1Id;
  1542. ceErpTradeCellExtend.cate2Id = item.cate2Id;
  1543. ceErpTradeCellExtend.cate3Id = item.cate3Id;
  1544. ceErpTradeCellExtend.sceneId = item.sceneId;
  1545. ceErpTradeCellExtend.typeSceneId = item.typeSceneId;
  1546. ceErpTradeCellExtend.opSceneId = item.opSceneId;
  1547. ceErpTradeCellExtend.materialId = item.materialId;
  1548. ceErpTradeCellExtend.width = item.width;
  1549. ceErpTradeCellExtend.height = item.height;
  1550. ceErpTradeCellExtend.length = item.length;
  1551. ceErpTradeCellExtend.recSize = item.recSize;
  1552. ceErpTradeCellExtend.sizeUnit = item.sizeUnit;
  1553. ceErpTradeCellExtend.numberUnit = item.numberUnit;
  1554. ceErpTradeCellExtend.orderFrom = 30;
  1555. ceErpTradeCellExtend.spu_id = item.spuId;
  1556. ceErpTradeCellExtend.quantity = item.quantity;
  1557. ceErpTradeCellExtend.discountAmount = item.discountAmount;
  1558. ceErpTradeCellExtend.differentAmount = item.compensateAmount;
  1559. ceErpTradeCellExtend.differentSplitNo = item.compensateSplitOrderUniqueNo;
  1560. ceErpTradeCellExtend.orderType = item.orderType;
  1561. ceErpTradeCellExtend.parentOrderSn = item.parentSplitNo;
  1562. if (ceErpTradeCellExtend.ID > 0)
  1563. {
  1564. ceErpTradeCellExtend.Update();
  1565. }
  1566. else
  1567. {
  1568. ceErpTradeCellExtend.Create();
  1569. }
  1570. if (item.isGift == 1)
  1571. {
  1572. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  1573. entity.IsXianHuo = 1;
  1574. entity.IsGift = 1;
  1575. entity.FinishPlaceTime = trade.pay_time;
  1576. if (entity.OrderState < 6)
  1577. {
  1578. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1579. }
  1580. }
  1581. if (item.isSpot)
  1582. {
  1583. if (entity.OrderState < 6)
  1584. {
  1585. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1586. }
  1587. entity.seller_memo = item.systemRemark;
  1588. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1589. entity.IsXianHuo = 1;
  1590. entity.FinishPlaceTime = entity.pay_time;
  1591. if (item.systemRemark.IndexOf("封酒贴") != -1)
  1592. {
  1593. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  1594. if (trade.buyer_memo != "")
  1595. {
  1596. entity.OrderState = 2;
  1597. entity.ProductId = 1;
  1598. entity.IsXianHuo = 0;
  1599. item.systemRemark = item.systemRemark.Replace("现货", "");
  1600. item.systemRemark = item.systemRemark.Replace(" ", "");
  1601. entity.seller_memo = item.systemRemark;
  1602. if (entity.ShopId != 0)
  1603. {
  1604. entity.OrderState = orderAudit(entity.ShopId);
  1605. }
  1606. }
  1607. }
  1608. else if (item.systemRemark.IndexOf("#") != -1)
  1609. {
  1610. entity.SupplierId = 87;
  1611. }
  1612. else if (item.systemRemark.IndexOf("喜字贴") != -1)
  1613. {
  1614. entity.SupplierId = 70;
  1615. }
  1616. else if (item.systemRemark.IndexOf("兔团团") != -1)
  1617. {
  1618. entity.SupplierId = 101;
  1619. }
  1620. else if (item.systemRemark.IndexOf("手拉旗") != -1)
  1621. {
  1622. entity.SupplierId = 108;
  1623. }
  1624. try
  1625. {
  1626. string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
  1627. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  1628. List<Dictionary<string, string>> material_list = new List<Dictionary<string, string>>();
  1629. List<Dictionary<string, string>> name_list = new List<Dictionary<string, string>>();
  1630. foreach (DataRow dr in goodsDt.Rows)
  1631. {
  1632. string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
  1633. List<string> xianhuo = sqlMemo.Split(',').ToList();
  1634. foreach (var val in xianhuo)
  1635. {
  1636. if (string.IsNullOrEmpty(val)) continue;
  1637. Dictionary<string, string> material_map = new Dictionary<string, string>();//材质
  1638. Dictionary<string, string> name_map = new Dictionary<string, string>();//特殊名称
  1639. if (val.IndexOf('-') > -1)
  1640. {
  1641. List<string> list = val.Split('-').ToList();
  1642. material_map.Add(dr["id"].ToString(), list[0]);
  1643. name_map.Add(dr["id"].ToString(), list[1]);
  1644. }
  1645. else
  1646. {
  1647. material_map.Add(dr["id"].ToString(), val);
  1648. }
  1649. material_list.Add(material_map);
  1650. name_list.Add(name_map);
  1651. }
  1652. }
  1653. List<string> materials = new List<string>();
  1654. List<string> names = new List<string>();
  1655. List<string> result = new List<string>();
  1656. for (int i = 0; i < material_list.Count; i++)
  1657. {
  1658. Dictionary<string, string> map = material_list[i];
  1659. foreach (var val in map)
  1660. {
  1661. if (item.systemRemark.IndexOf(val.Value) > -1)
  1662. {
  1663. Dictionary<string, string> map2 = name_list[i];
  1664. if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
  1665. {
  1666. foreach (var item1 in map2)
  1667. {
  1668. if (item.systemRemark.IndexOf(item1.Value) > -1)
  1669. {
  1670. names.Add(item1.Key);
  1671. materials.Add(val.Key);
  1672. }
  1673. }
  1674. }
  1675. else
  1676. {
  1677. materials.Add(val.Key);
  1678. }
  1679. }
  1680. }
  1681. }
  1682. if (names.Count > 0)//特殊名称有只先在特殊名称里选择
  1683. {
  1684. result = names.Distinct().ToList();
  1685. }
  1686. else
  1687. {
  1688. result = materials.Distinct().ToList();
  1689. }
  1690. if (result.Count > 0)
  1691. {
  1692. Random rnd = new Random();
  1693. int index = rnd.Next(result.Count);
  1694. entity.SupplierId = int.Parse(result[index]);
  1695. }
  1696. }
  1697. catch (Exception e)
  1698. {
  1699. XLog.SaveLog(0, "|现货匹配|" + e.Message);
  1700. }
  1701. }
  1702. if (isCreate)
  1703. {
  1704. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  1705. if (oldRes > 0)
  1706. {
  1707. //entity.IsOldCustomer = 1;
  1708. //if (oldRes == 2) entity.IsOldCustomerMore = 1;
  1709. }
  1710. }
  1711. if (item.sampleMark == "1")
  1712. {
  1713. entity.IsSample = 1;
  1714. entity.OrderState = 6;
  1715. entity.FinishPlaceTime = DateTime.Now;
  1716. entity.IsOldCustomer = 0;
  1717. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1718. }
  1719. if (item.sampleMark == "3")
  1720. {
  1721. entity.IsSample = 3;
  1722. entity.OrderState = 6;
  1723. entity.FinishPlaceTime = DateTime.Now;
  1724. entity.IsOldCustomer = 0;
  1725. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1726. }
  1727. if (item.sampleMark == "2" && !string.IsNullOrEmpty(item.parentSplitNo))
  1728. {
  1729. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(item.parentSplitNo);
  1730. if (ceErpTradeCell != null)
  1731. {
  1732. entity.CustomerUserId = ceErpTradeCell.CustomerUserId;
  1733. entity.DesignUserId = ceErpTradeCell.DesignUserId;
  1734. entity.SupplierId = ceErpTradeCell.SupplierId;
  1735. entity.IsSample = 2;
  1736. entity.WaitDesignTime = ceErpTradeCell.WaitDesignTime;
  1737. entity.StartDesignTime = ceErpTradeCell.StartDesignTime;
  1738. entity.FinishDesignTime = ceErpTradeCell.FinishDesignTime;
  1739. entity.FinishPlaceTime = ceErpTradeCell.FinishPlaceTime;
  1740. }
  1741. CeErpTradeCellExtend parentCell = CeErpTradeCellExtend.getByTid(item.parentSplitNo);
  1742. if (parentCell == null)
  1743. {
  1744. parentCell = new CeErpTradeCellExtend();
  1745. parentCell.ctid = item.parentSplitNo;
  1746. }
  1747. if (!string.IsNullOrEmpty(item.splitAmount))
  1748. {
  1749. parentCell.differentAmount += Convert.ToDouble(item.splitAmount);
  1750. }
  1751. if (parentCell.ID > 0)
  1752. {
  1753. parentCell.Update();
  1754. }
  1755. else
  1756. {
  1757. parentCell.Create();
  1758. }
  1759. ApiVo apiVo = new ApiVo();
  1760. apiVo.orderNumber = entity.ptid;
  1761. apiVo.payment = entity.payment;
  1762. apiVo.actionName = "repairDesign";
  1763. designHelper.API_WorkCore(apiVo);//repairDesign
  1764. }
  1765. bool isCopyFile = false;
  1766. //老客户
  1767. if (item.isRepurchase)
  1768. {
  1769. if (item.isOldCustomer == 1)
  1770. {
  1771. tmcHelper.dealOldCustomerEntityTag(ref entity, trade);
  1772. }
  1773. if (item.isOldCustomer == 3)
  1774. {
  1775. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  1776. entity.WaitDesignTime = DateTime.Now;
  1777. isCopyFile = true;
  1778. }
  1779. if (item.isOldCustomer == 2)
  1780. {
  1781. entity.OrderState = 3;
  1782. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  1783. entity.WaitDesignTime = DateTime.Now;
  1784. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  1785. }
  1786. }
  1787. if (create)
  1788. {
  1789. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "创建推送生成:" + entity.seller_memo, entity.OrderState);
  1790. entity.Create();
  1791. }
  1792. else
  1793. {
  1794. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "更新推送生成:" + entity.seller_memo, entity.OrderState);
  1795. designHelper.API_update_order(entity);
  1796. entity.Update();
  1797. }
  1798. if (isCopyFile)
  1799. {
  1800. apiUploaderResponse upResult = CopyDesignFile(entity.ctid, item.oldOrderSn, entity.CustomerUserId);
  1801. if (upResult == null || "error".Equals(upResult.type))
  1802. {
  1803. tempResponse response = new tempResponse();
  1804. response.flag = "1";
  1805. response.flagData = entity.ctid;
  1806. response.flagMsg = upResult == null ? "复制文件出错!" : upResult.result;
  1807. }
  1808. }
  1809. }
  1810. return tempResponses;
  1811. }
  1812. public void createItemOrder(List<Api_trade_info.TradeItemOrder> orderList, CeErpTrade trade)
  1813. {
  1814. foreach (Api_trade_info.TradeItemOrder item in orderList)
  1815. {
  1816. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.thirdOrderItemId);
  1817. bool isCreateOrder = false;
  1818. if (order == null)
  1819. {
  1820. order = new CeErpTradeOrder();
  1821. isCreateOrder = true;
  1822. order.oid = item.thirdOrderItemId;
  1823. order.tid = trade.tid;
  1824. order.buyer_nick = trade.buyer_nick;
  1825. }
  1826. order.refund_status = item.refundStatus;
  1827. order.status = trade.status;
  1828. order.title = item.title;
  1829. if (!string.IsNullOrEmpty(item.price))
  1830. {
  1831. order.price = Convert.ToDouble(item.price);
  1832. }
  1833. if (item.picUrl != null)
  1834. {
  1835. order.pic_path = item.picUrl;
  1836. }
  1837. if (!string.IsNullOrEmpty(item.num))
  1838. {
  1839. order.num = Convert.ToDouble(item.num);
  1840. }
  1841. if (!string.IsNullOrEmpty(item.totalAmount))
  1842. {
  1843. order.payment = Convert.ToDouble(item.totalAmount);
  1844. }
  1845. if (!string.IsNullOrEmpty(item.totalSellPrice))
  1846. {
  1847. order.total_fee = Convert.ToDouble(item.totalSellPrice);
  1848. }
  1849. //order.adjust_fee = Convert.ToDouble(item.price);
  1850. if (item.thirdSkuId != null && item.thirdSkuId != "")
  1851. {
  1852. order.sku_id = item.thirdSkuId;
  1853. }
  1854. if (item.specification != null && item.specification != "")
  1855. {
  1856. order.sku_properties_name = item.specification;
  1857. }
  1858. if (item.thirdSpuId != null && item.thirdSpuId != "")
  1859. {
  1860. order.spu_id = item.thirdSpuId;
  1861. }
  1862. if (isCreateOrder)
  1863. {
  1864. order.Create();
  1865. }
  1866. else
  1867. {
  1868. order.Update();
  1869. }
  1870. }
  1871. }
  1872. public CeErpTrade createTradeOrder(BizOrder bizOrder, CeErpTrade trade, bool isCreate)
  1873. {
  1874. if (trade == null)
  1875. { //新生成订单的
  1876. isCreate = true;
  1877. trade = new CeErpTrade();
  1878. trade.tid = bizOrder.thirdOrderId;
  1879. trade.type = bizOrder.orderPlatform;
  1880. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1881. {
  1882. trade.price = Convert.ToDouble(bizOrder.payAmount);
  1883. }
  1884. trade.discount_fee = 0;
  1885. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1886. {
  1887. trade.total_fee = Convert.ToDouble(bizOrder.payAmount);
  1888. }
  1889. if (bizOrder.orderTime != null && bizOrder.orderTime.Length > 0)
  1890. {
  1891. trade.created = Convert.ToDateTime(bizOrder.orderTime);
  1892. }
  1893. if (bizOrder.payTime != null && bizOrder.payTime.Length > 0)
  1894. {
  1895. trade.pay_time = Convert.ToDateTime(bizOrder.payTime);
  1896. }
  1897. trade.seller_nick = GetNull_tostring(bizOrder.openSellerNick);
  1898. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1899. {
  1900. trade.payment = Convert.ToDouble(bizOrder.payAmount);
  1901. }
  1902. }
  1903. trade.buyer_nick = GetNull_tostring(bizOrder.openBuyerNick);
  1904. trade.receiver_state = bizOrder.province;
  1905. if (!string.IsNullOrEmpty(bizOrder.num))
  1906. {
  1907. trade.num = Convert.ToDouble(bizOrder.num);
  1908. }
  1909. trade.receiver_city = bizOrder.city;
  1910. trade.receiver_address = GetNoNullValue_string(bizOrder.address);
  1911. trade.receiver_town = GetNoNullValue_string(bizOrder.receiverTown);
  1912. trade.receiver_district = GetNoNullValue_string(bizOrder.area);
  1913. trade.seller_flag = bizOrder.thirdFlag;
  1914. trade.orderType = bizOrder.orderType;
  1915. trade.orderFrom = 30;
  1916. trade.unrefundedAmount = bizOrder.unrefundedAmount;
  1917. if (bizOrder.modifyTime != null && bizOrder.modifyTime.Length > 0)
  1918. {
  1919. trade.modified = Convert.ToDateTime(bizOrder.modifyTime);
  1920. }
  1921. if (bizOrder.finishTime != null && bizOrder.finishTime.Length > 0)
  1922. {
  1923. trade.end_time = Convert.ToDateTime(bizOrder.finishTime);
  1924. }
  1925. if (bizOrder.shippingTime != null && bizOrder.shippingTime.Length > 0)
  1926. {
  1927. trade.delivery_time = Convert.ToDateTime(bizOrder.shippingTime);
  1928. }
  1929. if (bizOrder.confirmTime != null && bizOrder.confirmTime.Length > 0)
  1930. {
  1931. trade.confirmTime = Convert.ToDateTime(bizOrder.confirmTime);
  1932. }
  1933. trade.buyer_memo = GetNoNullValue_string(bizOrder.buyerRemark);
  1934. bool isSellerMemoChange = false;
  1935. //备注修改
  1936. bizOrder.sellerRemark = GetNoNullValue_string(bizOrder.sellerRemark);
  1937. if (trade.seller_memo != bizOrder.sellerRemark || trade.seller_memo.Length != bizOrder.sellerRemark.Length)
  1938. {
  1939. isSellerMemoChange = true;
  1940. }
  1941. trade.status = bizOrder.status;
  1942. trade.seller_memo = bizOrder.sellerRemark;
  1943. trade.buyer_id = bizOrder.openBuyerId;
  1944. trade.posCode = bizOrder.shopCode;
  1945. if (isCreate)
  1946. {
  1947. trade.Create();
  1948. }
  1949. else
  1950. {
  1951. if (bizOrder.status == "CLOSE")
  1952. {
  1953. trade.consign_time = DateTime.Now;
  1954. }
  1955. trade.Update();
  1956. }
  1957. try
  1958. {
  1959. if (bizOrder.status == "CLOSE" || bizOrder.status == "CANCEL")
  1960. {
  1961. StringBuilder sql = new StringBuilder();
  1962. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, bizOrder.thirdOrderId);
  1963. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1964. ApiVo apiVo = new ApiVo();
  1965. apiVo.actionName = "closeDesign";
  1966. apiVo.orderNumber = bizOrder.thirdOrderId;
  1967. //designHelper.API_WorkCore(apiVo);//closeDesign
  1968. LogHelper.addLog(bizOrder.thirdOrderId, 0, "交易关闭", (int)OrderState.交易关闭);
  1969. // commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
  1970. // removeOldCustomerInfo(trade);
  1971. }
  1972. else if (bizOrder.status == "COMPLETE")
  1973. {
  1974. StringBuilder sql = new StringBuilder();
  1975. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, bizOrder.thirdOrderId);
  1976. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1977. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
  1978. }
  1979. else if (bizOrder.status == "SHIPPED")//已发货
  1980. {
  1981. StringBuilder sql = new StringBuilder();
  1982. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, bizOrder.thirdOrderId);
  1983. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1984. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
  1985. }
  1986. }
  1987. catch (Exception ex)
  1988. {
  1989. XLog.SaveLog(0, bizOrder.thirdOrderId + "shipped:" + ex.Message);
  1990. throw ex;
  1991. }
  1992. return trade;
  1993. }
  1994. public static apiUploaderResponse CopyDesignFile(string ctid, string oldCtid, int userId)
  1995. {
  1996. string post_url = "http://183.250.143.56:8088/autocopy.aspx";
  1997. WebClient wc = new WebClient();
  1998. wc.Encoding = Encoding.GetEncoding("utf-8");
  1999. //json参数
  2000. NameValueCollection PostVars = new NameValueCollection();
  2001. PostVars.Add("hexdata", oldCtid + "," + ctid);
  2002. PostVars.Add("userid", userId.ToString());
  2003. apiUploaderResponse result = null;
  2004. try
  2005. {
  2006. byte[] ret = wc.UploadValues(post_url, "POST", PostVars);
  2007. string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret);
  2008. result = JsonConvert.DeserializeObject<apiUploaderResponse>(remoteInfo);
  2009. }
  2010. catch (Exception ex)
  2011. {
  2012. XLog.SaveLog(0, "CopyDesignFile:" + ex.Message);
  2013. }
  2014. return result;
  2015. }
  2016. public static DateTime StampToDateTime(string timeStamp)
  2017. {
  2018. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  2019. long lTime = long.Parse(timeStamp + "0000");
  2020. TimeSpan toNow = new TimeSpan(lTime);
  2021. return dateTimeStart.Add(toNow);
  2022. }
  2023. public static string GetNull_tostring(object value)
  2024. {
  2025. if (value == null)
  2026. {
  2027. return "";
  2028. }
  2029. return value.ToString();
  2030. }
  2031. public static string GetNoNullValue_string(string value)
  2032. {
  2033. if (value == null)
  2034. {
  2035. return "";
  2036. }
  2037. value = value.Replace("\n", " ");
  2038. value = value.Replace("\r", " ");
  2039. return value;
  2040. }
  2041. public static string getShopNameByECode(string code)
  2042. {
  2043. string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
  2044. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  2045. if (dt != null && dt.Rows.Count > 0)
  2046. {
  2047. return dt.Rows[0]["ShopName"].ToString();
  2048. }
  2049. return "";
  2050. }
  2051. public static int orderAudit(int shopId)
  2052. {
  2053. try
  2054. {
  2055. CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
  2056. if (ceErpShop == null) return 2;
  2057. if (!ceErpShop.orderAudit) return 2;
  2058. return -1;
  2059. }
  2060. catch (Exception ex)
  2061. {
  2062. return 2;
  2063. }
  2064. }
  2065. public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
  2066. {
  2067. if (father.seller_nick == "") return 0;
  2068. CeErpCustomer cus = null;
  2069. cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
  2070. if (cus == null)
  2071. {
  2072. cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
  2073. }
  2074. int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
  2075. if (cus != null)
  2076. {
  2077. if (cus.lastbuy_time.ToString() == "") return 0;
  2078. if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
  2079. cus.buyer_id = father.buyer_id;
  2080. if (cus.lastTid == father.tid)
  2081. {
  2082. if (pcount != cus.product_count)
  2083. {
  2084. cus.product_count = pcount;
  2085. cus.Update();
  2086. }
  2087. }
  2088. else
  2089. {
  2090. int returnNum = 0;
  2091. TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
  2092. cus.buy_day = Convert.ToInt32(tsday.TotalDays);
  2093. cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
  2094. cus.buy_count = cus.buy_count + 1;
  2095. cus.lastbuy_time2 = cus.lastbuy_time;
  2096. cus.buyer_id = father.buyer_id;
  2097. cus.lastbuy_time = father.pay_time;
  2098. int lastpCount = cus.product_count;
  2099. cus.product_count = pcount;
  2100. cus.lastTid2 = cus.lastTid;
  2101. cus.lastTid = father.tid;
  2102. if (cus.buy_day > 1)
  2103. {
  2104. if (pcount > lastpCount && cus.product_count != 0)
  2105. {
  2106. cus.isMore = 1;
  2107. returnNum = 2;
  2108. }
  2109. else
  2110. returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
  2111. }
  2112. else
  2113. returnNum = 0;
  2114. cus.Update();
  2115. return returnNum;
  2116. }
  2117. }
  2118. else
  2119. {
  2120. try
  2121. {
  2122. cus = new CeErpCustomer();
  2123. cus.buyer_nick = father.buyer_nick;
  2124. cus.seller_nick = father.seller_nick;
  2125. cus.buyer_id = father.buyer_id;
  2126. cus.buy_day = 0;
  2127. cus.buy_count = 1;
  2128. cus.lastbuy_time = father.pay_time;
  2129. cus.lastTid = father.tid;
  2130. cus.total_fee = Convert.ToDouble(father.payment);
  2131. cus.product_count = pcount;
  2132. cus.Create();
  2133. return 0;
  2134. }
  2135. catch (Exception ex)
  2136. {
  2137. XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
  2138. }
  2139. }
  2140. return 0;
  2141. }
  2142. }
  2143. }