preSalesHelper.cs 89 KB

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