preSalesHelper.cs 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193
  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. public void save_erp_billinfo()
  914. {
  915. if (UrlPostParmsCheck("ctid"))
  916. {
  917. string eid = GetPostString("ctid");
  918. CeErpTradeCell entity = null;
  919. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  920. if (entity != null)
  921. {
  922. CeErpBill bill = CeErpBill.GetByTid(eid);
  923. bool isHave = false;
  924. if (bill != null)
  925. {
  926. isHave = true;
  927. if (bill.state != 4)
  928. {
  929. returnErrorMsg("此单已经申请过发票了");
  930. return;
  931. }
  932. }
  933. if (entity.IsNeedBill == 0)
  934. {
  935. entity.IsNeedBill = 1;
  936. }
  937. entity.Update();
  938. string errjson = "";
  939. try
  940. {
  941. CeErpBill bill_entity = new CeErpBill();
  942. bill_entity.tid = entity.tid;
  943. bill_entity.title = GetPostString("title");
  944. string taxstr = GetPostString("tax");
  945. taxstr = taxstr.Replace(" ", "");
  946. bill_entity.tax = taxstr;
  947. bill_entity.bank = GetPostString("bank");
  948. string bankacstr = GetPostString("bankac");
  949. bankacstr = bankacstr.Replace(" ", "");
  950. bill_entity.bankac = bankacstr;
  951. bill_entity.address = GetPostString("address");
  952. bill_entity.phone = GetPostString("phone");
  953. bill_entity.price = GetPostString("price");
  954. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  955. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  956. {
  957. billCount += 1;
  958. }
  959. string prebill = "ltb";
  960. for (int idx = 1; idx <= billCount; idx++)
  961. {
  962. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  963. string billoid = prebill + idx + dtstr;
  964. bill_entity.billOrderId += billoid;
  965. if (idx < billCount)
  966. {
  967. bill_entity.billOrderId += ",";
  968. }
  969. }
  970. bill_entity.productId = GetPostInt("ProductName");
  971. bill_entity.num = GetPostInt("num");
  972. bill_entity.unit = GetPostString("unit");
  973. bill_entity.type = GetPostString("type");
  974. bill_entity.sendType = GetPostString("SendType");
  975. bill_entity.email = GetPostString("email");
  976. bill_entity.buyer_nick = GetPostString("buyer_nick");
  977. bill_entity.shopName = GetPostString("ShopName");
  978. bill_entity.applymemo = GetPostString("applyMemo");
  979. bill_entity.createTime = DateTime.Now;
  980. bill_entity.state = 0;
  981. bill_entity.userId = 11;
  982. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  983. bill_entity.Create();
  984. }
  985. catch (Exception ex)
  986. {
  987. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  988. returnErrorMsg("创建发票出错!");
  989. return;
  990. }
  991. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  992. returnSuccessMsg("发票申请成功!");
  993. return;
  994. }
  995. returnErrorMsg("找不到记录");
  996. }
  997. }
  998. /**
  999. * 查货
  1000. * ctid
  1001. * name
  1002. **/
  1003. public void ins_checkorder()
  1004. {
  1005. if (UrlPostParmsCheck("ctid"))
  1006. {
  1007. string ctid = GetPostString("ctid");
  1008. string name = GetPostString("name");
  1009. int UserID = GetPostInt("UserID");
  1010. CeErpTradeCell entity = null;
  1011. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1012. if (entity != null)
  1013. {
  1014. if (entity.OrderState < 6)
  1015. {
  1016. returnErrorMsg("下单完成后才可查货");
  1017. return;
  1018. }
  1019. if (entity.OrderState > 6)
  1020. {
  1021. returnErrorMsg("订单已发货");
  1022. return;
  1023. }
  1024. if (entity.FinishPlaceTime != null)
  1025. {
  1026. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  1027. {
  1028. returnErrorMsg("下单时间不足,无法查货");
  1029. return;
  1030. }
  1031. }
  1032. entity.MemoOpt = 3;
  1033. entity.CheckOrderTime = DateTime.Now;
  1034. entity.Update();
  1035. LogHelper.addLog(entity.ctid, UserID, name + "标记:查货", entity.OrderState, 1);
  1036. returnSuccessMsg("操作成功!");
  1037. return;
  1038. }
  1039. returnErrorMsg("找不到记录");
  1040. return;
  1041. }
  1042. returnErrorMsg("缺少必要的参数ctid");
  1043. }
  1044. public void ins_checkdesign()
  1045. {
  1046. if (UrlPostParmsCheck("ctid"))
  1047. {
  1048. string ctid = GetPostString("ctid");
  1049. string name = GetPostString("name");
  1050. int UserID = GetPostInt("UserID");
  1051. int memoopt = GetPostInt("memoopt");
  1052. CeErpTradeCell entity = null;
  1053. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1054. if (entity != null)
  1055. {
  1056. string stropt = "";
  1057. if (memoopt == 1)
  1058. {
  1059. stropt = "“改稿”";
  1060. }
  1061. else if (memoopt == 2)
  1062. {
  1063. stropt = "“定稿”";
  1064. }
  1065. entity.MemoOpt = memoopt;
  1066. entity.Update();
  1067. LogHelper.addLog(entity.ctid, UserID, name + "标记:" + stropt, entity.OrderState, 1);
  1068. returnSuccessMsg("操作成功!");
  1069. return;
  1070. }
  1071. returnErrorMsg("找不到记录");
  1072. return;
  1073. }
  1074. returnErrorMsg("缺少必要的参数ctid");
  1075. }
  1076. public void save_othermemo()
  1077. {
  1078. if (UrlPostParmsCheck("ctid"))
  1079. {
  1080. string ctid = GetPostString("ctid");
  1081. string name = GetPostString("name");
  1082. int UserID = GetPostInt("UserID");
  1083. CeErpTradeCell entity = null;
  1084. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1085. if (entity != null)
  1086. {
  1087. entity.OtherMemo = GetPostString("otherMemo");
  1088. entity.Update();
  1089. returnSuccessMsg("保存成功!");
  1090. LogHelper.addLog(entity.ctid, UserID, name + "额外:" + entity.OtherMemo, entity.OrderState);
  1091. return;
  1092. }
  1093. returnErrorMsg("找不到记录");
  1094. return;
  1095. }
  1096. returnErrorMsg("缺少必要的参数ctid");
  1097. }
  1098. public void save_customermemo()
  1099. {
  1100. if (UrlPostParmsCheck("ctid"))
  1101. {
  1102. string ctid = GetPostString("ctid");
  1103. CeErpTradeCell entity = null;
  1104. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1105. if (entity != null)
  1106. {
  1107. entity.CustomerMemo = GetPostString("CustomerMemo");
  1108. entity.Update();
  1109. ApiVo apiVo = new ApiVo();
  1110. apiVo.orderNumber = entity.ctid;
  1111. apiVo.actionName = "followRemarks";
  1112. apiVo.orderRemarks = entity.CustomerMemo;
  1113. designHelper.API_WorkCore(apiVo);//followRemarks
  1114. returnSuccessMsg("保存成功!");
  1115. return;
  1116. }
  1117. returnErrorMsg("找不到记录");
  1118. }
  1119. }
  1120. public void create_order()
  1121. {
  1122. if (UrlPostParmsCheck("data"))
  1123. {
  1124. string data = GetPostString("data");
  1125. Api_trade_info info = null;
  1126. try
  1127. {
  1128. info = JsonConvert.DeserializeObject<Api_trade_info>(data);
  1129. }
  1130. catch (Exception ex)
  1131. {
  1132. XLog.SaveLog(0, "create_order|1|" + ex.Message);
  1133. returnErrorMsg(ex.Message);
  1134. return;
  1135. }
  1136. if (info == null)
  1137. {
  1138. XLog.SaveLog(0, "Api_trade_info isNull");
  1139. return;
  1140. }
  1141. BizOrder bizOrder = info.bizOrder;
  1142. if (bizOrder == null)
  1143. {
  1144. returnErrorMsg("接口对象处理错误bizOrder=null");
  1145. return;
  1146. }
  1147. bool isCreate = false;
  1148. CeErpTrade trade = null;
  1149. trade = CeErpTrade.Get(bizOrder.thirdOrderId);
  1150. if (trade == null)
  1151. {
  1152. isCreate = true;
  1153. }
  1154. List<tempResponse> callResult = null;
  1155. try
  1156. {
  1157. trade = createTradeOrder(bizOrder, trade, isCreate);
  1158. List<Api_trade_info.TradeItemOrder> orderList = bizOrder.bizOrderItems;
  1159. createItemOrder(orderList, trade);
  1160. List<Api_trade_info.bizOrderSplit> bizOrderSplit = bizOrder.bizOrderSplits;
  1161. callResult = createCellOrder(bizOrderSplit, trade, isCreate);
  1162. }
  1163. catch (Exception ex)
  1164. {
  1165. XLog.SaveLog(0, "create_order|2|" + ex);
  1166. returnErrorMsg(ex.Message);
  1167. return;
  1168. }
  1169. returnSuccessMsg(JsonConvert.SerializeObject(callResult));
  1170. return;
  1171. }
  1172. returnErrorMsg("缺少必要的参数data");
  1173. }
  1174. public void refundOrder()
  1175. {
  1176. if (UrlPostParmsCheck("data"))
  1177. {
  1178. string data = GetPostString("data");
  1179. Api_refund_info info = null;
  1180. try
  1181. {
  1182. info = JsonConvert.DeserializeObject<Api_refund_info>(data);
  1183. }
  1184. catch (Exception ex)
  1185. {
  1186. XLog.SaveLog(0, "refundOrder|4|" + ex.Message);
  1187. returnErrorMsg(ex.Message);
  1188. return;
  1189. }
  1190. if (info == null)
  1191. {
  1192. XLog.SaveLog(0, "Api_refund_info isNull");
  1193. returnErrorMsg("接口对象处理错误RefundOrder=null1");
  1194. return;
  1195. }
  1196. RefundOrder refundOrder = info.refundOrder;
  1197. if (refundOrder == null)
  1198. {
  1199. returnErrorMsg("接口对象处理错误RefundOrder=null2");
  1200. return;
  1201. }
  1202. CeErpTrade trade = CeErpTrade.Get(refundOrder.tid);
  1203. if (trade != null)
  1204. {
  1205. CeErpTradeRefund refund = CeErpTradeRefund.GetByOidAndReId(refundOrder.ctid, refundOrder.orderSn);
  1206. LogHelper.addLog(refundOrder.ctid, 0, "客户退款", 0);
  1207. if (refund == null)
  1208. {
  1209. refund = new CeErpTradeRefund();
  1210. refund.refund_id = refundOrder.orderSn;
  1211. refund.tid = refundOrder.tid;
  1212. refund.oid = refundOrder.ctid;
  1213. if (refundOrder.createTime != null && refundOrder.createTime.Length > 0)
  1214. {
  1215. refund.created = Convert.ToDateTime(refundOrder.createTime);
  1216. }
  1217. if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
  1218. {
  1219. refund.modified = Convert.ToDateTime(refundOrder.updateTime);
  1220. }
  1221. refund.status = refundOrder.status;
  1222. refund.order_status = refundOrder.orderStatus;
  1223. refund.payment = refundOrder.payment.ToString();
  1224. refund.refund_fee = refundOrder.refundFee;//退款金额
  1225. refund.buyer_nick = GetNull_tostring(refundOrder.openBuyerNick);
  1226. refund.seller_nick = refundOrder.seller_nick;
  1227. refund.total_fee = refundOrder.totalFee;
  1228. refund.RefundState = 1;
  1229. refund.reason = refundOrder.reason;
  1230. refund.refundDesc = refundOrder.desc;
  1231. refund.IsPartRefund = refundOrder.isPartRefund;
  1232. refund.Create();
  1233. try
  1234. {
  1235. StringBuilder CeErpTradeCellSql = new StringBuilder();
  1236. CeErpTradeCellSql.AppendFormat("select * from CE_ErpTradeCell where ctid='{0}';", refundOrder.ctid);
  1237. DataSet cell = DbHelper.DbConn.ExecuteDataset(CeErpTradeCellSql.ToString());
  1238. DataTable datatable = cell.Tables[0];
  1239. if (datatable.Rows.Count > 0)
  1240. {
  1241. foreach (DataRow dr in datatable.Rows)
  1242. {
  1243. int DesignUserId = Convert.ToInt32(dr["DesignUserId"]);
  1244. int OrderState = Convert.ToInt32(dr["OrderState"]);
  1245. int CustomerUserId = Convert.ToInt32(dr["CustomerUserId"]);
  1246. if (DesignUserId > 0 && OrderState == 4)
  1247. {
  1248. createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, DesignUserId, 1);
  1249. }
  1250. if (CustomerUserId > 0)
  1251. {
  1252. createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, CustomerUserId, 1);
  1253. }
  1254. }
  1255. }
  1256. }
  1257. catch (Exception ex)
  1258. {
  1259. XLog.SaveLog(0, "退款推送通知创建失败!!" + ex);
  1260. }
  1261. int rstate = commonHelper.getRefundTagByState(refundOrder.status);
  1262. StringBuilder sql = new StringBuilder();
  1263. if (refund.IsPartRefund == 1)
  1264. {
  1265. double paylast = Convert.ToDouble(refundOrder.payment) - Convert.ToDouble(refund.refund_fee);
  1266. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1},payment={2} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 3, paylast);
  1267. }
  1268. else
  1269. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, rstate);
  1270. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1271. string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
  1272. //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  1273. StringBuilder sqls = new StringBuilder();
  1274. sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
  1275. CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
  1276. LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
  1277. }
  1278. else
  1279. {
  1280. if (refund.status != refundOrder.status)
  1281. {
  1282. refund.modified = DateTime.Now;
  1283. if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
  1284. {
  1285. refund.modified = Convert.ToDateTime(refundOrder.updateTime);
  1286. }
  1287. refund.order_status = refundOrder.orderStatus;
  1288. refund.Update();
  1289. int rstate = commonHelper.getRefundTagByState(refundOrder.status);
  1290. string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
  1291. StringBuilder sql = new StringBuilder();
  1292. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={0} where ctid='{1}' and isAfterSaleOrder=0;", rstate, refundOrder.ctid);
  1293. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1294. //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  1295. LogHelper.addLog(refundOrder.tid, 0, "更新退款状态:" + rstateWord, (int)OrderState.交易关闭);
  1296. // 取消设计费
  1297. StringBuilder sqls = new StringBuilder();
  1298. sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
  1299. CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
  1300. LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
  1301. }
  1302. }
  1303. List<RefundItemOrder> goodsItems = refundOrder.goodsItems;
  1304. foreach (RefundItemOrder item in goodsItems)
  1305. {
  1306. CeErpTradeOrder goods = CeErpTradeOrder.GetByOid(item.refOlId);
  1307. if (goods != null)
  1308. {
  1309. goods.refund_status = item.refundStatus;
  1310. goods.Update();
  1311. }
  1312. }
  1313. if (refundOrder.status == "WAIT_SELLER_AGREE")
  1314. {
  1315. StringBuilder sql = new StringBuilder();
  1316. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 1);
  1317. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1318. designHelper.API_refundOrder(refundOrder.tid, "refundIng", refundOrder.reason);
  1319. LogHelper.addLog(refundOrder.tid, 0, "申请退款中", 0);
  1320. }
  1321. else if (refundOrder.status == "CLOSED")
  1322. {
  1323. StringBuilder sql = new StringBuilder();
  1324. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 0);
  1325. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1326. designHelper.API_refundOrder(refundOrder.tid, "refundCancel", refundOrder.reason);
  1327. LogHelper.addLog(refundOrder.tid, 0, "关闭申请退款中", 0);
  1328. }
  1329. else if (refundOrder.status == "REFUNDED" || refundOrder.status == "SUCCESS")
  1330. {
  1331. designHelper.API_refundOrder(refundOrder.tid, "refundEd", refundOrder.reason);
  1332. }
  1333. }
  1334. else
  1335. {
  1336. }
  1337. }
  1338. returnErrorMsg("缺少必要的参数data");
  1339. }
  1340. public void createRefundMessage(string ctid, MessageState messageState, int userId, int type)
  1341. {
  1342. CeErpMessageTip ceErpMessageTip = new CeErpMessageTip();
  1343. ceErpMessageTip.tid = ctid;
  1344. ceErpMessageTip.type = Convert.ToInt32(messageState);
  1345. ceErpMessageTip.userId = userId;
  1346. ceErpMessageTip.isVisit = false;
  1347. ceErpMessageTip.content = "订单" + ctid + "申请了退款!";
  1348. ceErpMessageTip.Create();
  1349. StringBuilder sqlTip = new StringBuilder();
  1350. if (type == 1)
  1351. {
  1352. 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);
  1353. }
  1354. if (type == 2)
  1355. {
  1356. 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);
  1357. }
  1358. DataTable dth = DbHelper.DbConn.ExecuteDataset(sqlTip.ToString()).Tables[0];
  1359. if (dth.Rows.Count > 0)
  1360. {
  1361. foreach (DataRow dthdr in dth.Rows)
  1362. {
  1363. int Bid = Convert.ToInt32(dthdr["id"]);
  1364. if (Bid > 0)
  1365. {
  1366. CeErpMessageTip ceErpMessageTipB = new CeErpMessageTip();
  1367. ceErpMessageTipB.tid = ctid;
  1368. ceErpMessageTipB.type = Convert.ToInt32(messageState);
  1369. ceErpMessageTipB.userId = Bid;
  1370. ceErpMessageTipB.isVisit = false;
  1371. ceErpMessageTipB.content = "订单" + ctid + "申请了退款!";
  1372. ceErpMessageTipB.Create();
  1373. }
  1374. }
  1375. }
  1376. }
  1377. public List<tempResponse> createCellOrder(List<Api_trade_info.bizOrderSplit> bizOrderSplit, CeErpTrade trade, bool isCreate)
  1378. {
  1379. List<tempResponse> tempResponses = new List<tempResponse>();
  1380. CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
  1381. foreach (Api_trade_info.bizOrderSplit item in bizOrderSplit)
  1382. {
  1383. bool create = false;
  1384. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(item.splitNo);
  1385. if (entity == null)
  1386. {
  1387. entity = new CeErpTradeCell();
  1388. create = true;
  1389. entity.tid = trade.tid;
  1390. entity.pay_time = trade.pay_time;
  1391. }
  1392. if (entity.OrderState > 4)
  1393. {
  1394. continue;
  1395. }
  1396. entity.ctid = item.splitNo;
  1397. entity.seller_memo = item.systemRemark;
  1398. if (!string.IsNullOrEmpty(item.splitAmount))
  1399. {
  1400. entity.payment = Convert.ToDouble(item.splitAmount);
  1401. }
  1402. if (!string.IsNullOrEmpty(item.splitAmount))
  1403. {
  1404. entity.AfterSalePayment = Convert.ToDouble(item.splitAmount);
  1405. }
  1406. if (!string.IsNullOrEmpty(item.sfMark))
  1407. {
  1408. entity.IsSF = Convert.ToInt32(item.sfMark);
  1409. }
  1410. entity.ProductSize = item.size;
  1411. entity.Material = item.material;
  1412. entity.CustomerUserId = item.erpCustomerServiceId;
  1413. //entity.Craft = item.craft;
  1414. entity.ProductCount = item.productQuantity;
  1415. entity.ProductId = tmcHelper.getProductIdByName(item.cate3Id);
  1416. if (!string.IsNullOrEmpty(item.internalStatus))
  1417. {
  1418. entity.OrderState = Convert.ToInt32(item.internalStatus);
  1419. }
  1420. entity.IsUrgency = item.isUrgent;
  1421. entity.ptid = item.ptid;
  1422. entity.SplitTag = item.splitInfoNo;
  1423. if (!string.IsNullOrEmpty(item.paymentFile))
  1424. {
  1425. entity.PayProofImg = item.paymentFile;
  1426. }
  1427. if (item.shippingTime != null && item.shippingTime.Length > 0)
  1428. {
  1429. entity.UnusualTime = Convert.ToDateTime(item.shippingTime);
  1430. }
  1431. if (!string.IsNullOrEmpty(item.sendGiftMark))
  1432. {
  1433. entity.IsSendGift = Convert.ToInt32(item.sendGiftMark);
  1434. }
  1435. entity.OtherMemo = item.otherRemark;
  1436. entity.IsOldCustomer = item.isRepurchase ? 1 : 0;
  1437. entity.IsOldCustomerMore = item.isOldCustomerMore;
  1438. entity.MemoOpt = item.memoOpt;
  1439. entity.isDianziOrder = item.isDianziOrder;
  1440. if (item.isPreShipping != null && item.isPreShipping.Length > 0)
  1441. {
  1442. entity.IsPreDelivery = Convert.ToInt32(item.isPreShipping);
  1443. }
  1444. if (item.checkOrderTime != null && item.checkOrderTime.Length > 0)
  1445. {
  1446. entity.CheckOrderTime = Convert.ToDateTime(item.checkOrderTime);
  1447. }
  1448. int shopId = 0;
  1449. if (nShop != null)
  1450. {
  1451. shopId = nShop.ID;
  1452. }
  1453. entity.ShopId = shopId;
  1454. entity.OrderSn = item.OrderSn;
  1455. entity.ParentSplitNo = item.parentSplitNo;
  1456. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1457. if (ceErpTradeCellExtend == null)
  1458. {
  1459. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  1460. ceErpTradeCellExtend.ctid = entity.ctid;
  1461. }
  1462. ceErpTradeCellExtend.cate1 = item.cate1;
  1463. ceErpTradeCellExtend.cate2 = item.cate2;
  1464. ceErpTradeCellExtend.scene = item.scene;
  1465. ceErpTradeCellExtend.material = item.material;
  1466. ceErpTradeCellExtend.offerAmount = item.offerAmount;
  1467. ceErpTradeCellExtend.numbers = item.numbers;
  1468. ceErpTradeCellExtend.typeScene = item.typeScene;
  1469. ceErpTradeCellExtend.opScene = item.opScene;
  1470. ceErpTradeCellExtend.craft = item.craft;
  1471. ceErpTradeCellExtend.numberType = item.numberType;
  1472. ceErpTradeCellExtend.cate1Id = item.cate1Id;
  1473. ceErpTradeCellExtend.cate2Id = item.cate2Id;
  1474. ceErpTradeCellExtend.cate3Id = item.cate3Id;
  1475. ceErpTradeCellExtend.sceneId = item.sceneId;
  1476. ceErpTradeCellExtend.typeSceneId = item.typeSceneId;
  1477. ceErpTradeCellExtend.opSceneId = item.opSceneId;
  1478. ceErpTradeCellExtend.materialId = item.materialId;
  1479. ceErpTradeCellExtend.width = item.width;
  1480. ceErpTradeCellExtend.height = item.height;
  1481. ceErpTradeCellExtend.length = item.length;
  1482. ceErpTradeCellExtend.recSize = item.recSize;
  1483. ceErpTradeCellExtend.sizeUnit = item.sizeUnit;
  1484. ceErpTradeCellExtend.numberUnit = item.numberUnit;
  1485. ceErpTradeCellExtend.orderFrom = 30;
  1486. ceErpTradeCellExtend.spu_id = item.spuId;
  1487. ceErpTradeCellExtend.quantity = item.quantity;
  1488. ceErpTradeCellExtend.discountAmount = item.discountAmount;
  1489. ceErpTradeCellExtend.differentAmount = item.compensateAmount;
  1490. ceErpTradeCellExtend.differentSplitNo = item.compensateSplitOrderUniqueNo;
  1491. ceErpTradeCellExtend.orderType = item.orderType;
  1492. ceErpTradeCellExtend.parentOrderSn = item.parentSplitNo;
  1493. if (ceErpTradeCellExtend.ID > 0)
  1494. {
  1495. ceErpTradeCellExtend.Update();
  1496. }
  1497. else
  1498. {
  1499. ceErpTradeCellExtend.Create();
  1500. }
  1501. if (item.isGift == 1)
  1502. {
  1503. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  1504. entity.IsXianHuo = 1;
  1505. entity.IsGift = 1;
  1506. entity.FinishPlaceTime = trade.pay_time;
  1507. if (entity.OrderState < 6)
  1508. {
  1509. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1510. }
  1511. }
  1512. if (item.isSpot)
  1513. {
  1514. if (entity.OrderState < 6)
  1515. {
  1516. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1517. }
  1518. entity.seller_memo = item.systemRemark;
  1519. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1520. entity.IsXianHuo = 1;
  1521. entity.FinishPlaceTime = entity.pay_time;
  1522. if (item.systemRemark.IndexOf("封酒贴") != -1)
  1523. {
  1524. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  1525. if (trade.buyer_memo != "")
  1526. {
  1527. entity.OrderState = 2;
  1528. entity.ProductId = 1;
  1529. entity.IsXianHuo = 0;
  1530. item.systemRemark = item.systemRemark.Replace("现货", "");
  1531. item.systemRemark = item.systemRemark.Replace(" ", "");
  1532. entity.seller_memo = item.systemRemark;
  1533. if (entity.ShopId != 0)
  1534. {
  1535. entity.OrderState = orderAudit(entity.ShopId);
  1536. }
  1537. }
  1538. }
  1539. else if (item.systemRemark.IndexOf("#") != -1)
  1540. {
  1541. entity.SupplierId = 87;
  1542. }
  1543. else if (item.systemRemark.IndexOf("喜字贴") != -1)
  1544. {
  1545. entity.SupplierId = 70;
  1546. }
  1547. else if (item.systemRemark.IndexOf("兔团团") != -1)
  1548. {
  1549. entity.SupplierId = 101;
  1550. }
  1551. else if (item.systemRemark.IndexOf("手拉旗") != -1)
  1552. {
  1553. entity.SupplierId = 108;
  1554. }
  1555. try
  1556. {
  1557. string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
  1558. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  1559. List<Dictionary<string, string>> material_list = new List<Dictionary<string, string>>();
  1560. List<Dictionary<string, string>> name_list = new List<Dictionary<string, string>>();
  1561. foreach (DataRow dr in goodsDt.Rows)
  1562. {
  1563. string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
  1564. List<string> xianhuo = sqlMemo.Split(',').ToList();
  1565. foreach (var val in xianhuo)
  1566. {
  1567. if (string.IsNullOrEmpty(val)) continue;
  1568. Dictionary<string, string> material_map = new Dictionary<string, string>();//材质
  1569. Dictionary<string, string> name_map = new Dictionary<string, string>();//特殊名称
  1570. if (val.IndexOf('-') > -1)
  1571. {
  1572. List<string> list = val.Split('-').ToList();
  1573. material_map.Add(dr["id"].ToString(), list[0]);
  1574. name_map.Add(dr["id"].ToString(), list[1]);
  1575. }
  1576. else
  1577. {
  1578. material_map.Add(dr["id"].ToString(), val);
  1579. }
  1580. material_list.Add(material_map);
  1581. name_list.Add(name_map);
  1582. }
  1583. }
  1584. List<string> materials = new List<string>();
  1585. List<string> names = new List<string>();
  1586. List<string> result = new List<string>();
  1587. for (int i = 0; i < material_list.Count; i++)
  1588. {
  1589. Dictionary<string, string> map = material_list[i];
  1590. foreach (var val in map)
  1591. {
  1592. if (item.systemRemark.IndexOf(val.Value) > -1)
  1593. {
  1594. Dictionary<string, string> map2 = name_list[i];
  1595. if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
  1596. {
  1597. foreach (var item1 in map2)
  1598. {
  1599. if (item.systemRemark.IndexOf(item1.Value) > -1)
  1600. {
  1601. names.Add(item1.Key);
  1602. materials.Add(val.Key);
  1603. }
  1604. }
  1605. }
  1606. else
  1607. {
  1608. materials.Add(val.Key);
  1609. }
  1610. }
  1611. }
  1612. }
  1613. if (names.Count > 0)//特殊名称有只先在特殊名称里选择
  1614. {
  1615. result = names.Distinct().ToList();
  1616. }
  1617. else
  1618. {
  1619. result = materials.Distinct().ToList();
  1620. }
  1621. if (result.Count > 0)
  1622. {
  1623. Random rnd = new Random();
  1624. int index = rnd.Next(result.Count);
  1625. entity.SupplierId = int.Parse(result[index]);
  1626. }
  1627. }
  1628. catch (Exception e)
  1629. {
  1630. XLog.SaveLog(0, "|现货匹配|" + e.Message);
  1631. }
  1632. }
  1633. if (isCreate)
  1634. {
  1635. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  1636. if (oldRes > 0)
  1637. {
  1638. //entity.IsOldCustomer = 1;
  1639. //if (oldRes == 2) entity.IsOldCustomerMore = 1;
  1640. }
  1641. }
  1642. if (item.sampleMark == "1")
  1643. {
  1644. entity.IsSample = 1;
  1645. entity.OrderState = 6;
  1646. entity.FinishPlaceTime = DateTime.Now;
  1647. entity.IsOldCustomer = 0;
  1648. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1649. }
  1650. if (item.sampleMark == "3")
  1651. {
  1652. entity.IsSample = 3;
  1653. entity.OrderState = 6;
  1654. entity.FinishPlaceTime = DateTime.Now;
  1655. entity.IsOldCustomer = 0;
  1656. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1657. }
  1658. if (item.sampleMark == "2" && !string.IsNullOrEmpty(item.parentSplitNo))
  1659. {
  1660. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(item.parentSplitNo);
  1661. if (ceErpTradeCell != null)
  1662. {
  1663. entity.CustomerUserId = ceErpTradeCell.CustomerUserId;
  1664. entity.DesignUserId = ceErpTradeCell.DesignUserId;
  1665. entity.SupplierId = ceErpTradeCell.SupplierId;
  1666. entity.IsSample = 2;
  1667. entity.WaitDesignTime = ceErpTradeCell.WaitDesignTime;
  1668. entity.StartDesignTime = ceErpTradeCell.StartDesignTime;
  1669. entity.FinishDesignTime = ceErpTradeCell.FinishDesignTime;
  1670. entity.FinishPlaceTime = ceErpTradeCell.FinishPlaceTime;
  1671. }
  1672. CeErpTradeCellExtend parentCell = CeErpTradeCellExtend.getByTid(item.parentSplitNo);
  1673. if (parentCell == null)
  1674. {
  1675. parentCell = new CeErpTradeCellExtend();
  1676. parentCell.ctid = item.parentSplitNo;
  1677. }
  1678. if (!string.IsNullOrEmpty(item.splitAmount))
  1679. {
  1680. parentCell.differentAmount += Convert.ToDouble(item.splitAmount);
  1681. }
  1682. if (parentCell.ID > 0)
  1683. {
  1684. parentCell.Update();
  1685. }
  1686. else
  1687. {
  1688. parentCell.Create();
  1689. }
  1690. ApiVo apiVo = new ApiVo();
  1691. apiVo.orderNumber = entity.ptid;
  1692. apiVo.payment = entity.payment;
  1693. apiVo.actionName = "repairDesign";
  1694. designHelper.API_WorkCore(apiVo);//repairDesign
  1695. }
  1696. bool isCopyFile = false;
  1697. //老客户
  1698. if (item.isRepurchase)
  1699. {
  1700. if (item.isOldCustomer == 1)
  1701. {
  1702. tmcHelper.dealOldCustomerEntityTag(ref entity, trade);
  1703. }
  1704. if (item.isOldCustomer == 3)
  1705. {
  1706. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  1707. entity.WaitDesignTime = DateTime.Now;
  1708. isCopyFile = true;
  1709. }
  1710. if (item.isOldCustomer == 2)
  1711. {
  1712. entity.OrderState = 3;
  1713. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  1714. entity.WaitDesignTime = DateTime.Now;
  1715. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  1716. }
  1717. }
  1718. if (create)
  1719. {
  1720. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "创建推送生成:" + entity.seller_memo, entity.OrderState);
  1721. entity.Create();
  1722. }
  1723. else
  1724. {
  1725. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "更新推送生成:" + entity.seller_memo, entity.OrderState);
  1726. designHelper.API_update_order(entity);
  1727. entity.Update();
  1728. }
  1729. if (isCopyFile)
  1730. {
  1731. apiUploaderResponse upResult = CopyDesignFile(entity.ctid, item.oldOrderSn, entity.CustomerUserId);
  1732. if (upResult == null || "error".Equals(upResult.type))
  1733. {
  1734. tempResponse response = new tempResponse();
  1735. response.flag = "1";
  1736. response.flagData = entity.ctid;
  1737. response.flagMsg = upResult == null ? "复制文件出错!" : upResult.result;
  1738. }
  1739. }
  1740. }
  1741. return tempResponses;
  1742. }
  1743. public void createItemOrder(List<Api_trade_info.TradeItemOrder> orderList, CeErpTrade trade)
  1744. {
  1745. foreach (Api_trade_info.TradeItemOrder item in orderList)
  1746. {
  1747. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.thirdOrderItemId);
  1748. bool isCreateOrder = false;
  1749. if (order == null)
  1750. {
  1751. order = new CeErpTradeOrder();
  1752. isCreateOrder = true;
  1753. order.oid = item.thirdOrderItemId;
  1754. order.tid = trade.tid;
  1755. order.buyer_nick = trade.buyer_nick;
  1756. }
  1757. order.refund_status = item.refundStatus;
  1758. order.status = trade.status;
  1759. order.title = item.title;
  1760. if (!string.IsNullOrEmpty(item.price))
  1761. {
  1762. order.price = Convert.ToDouble(item.price);
  1763. }
  1764. if (item.picUrl != null)
  1765. {
  1766. order.pic_path = item.picUrl;
  1767. }
  1768. if (!string.IsNullOrEmpty(item.num))
  1769. {
  1770. order.num = Convert.ToDouble(item.num);
  1771. }
  1772. if (!string.IsNullOrEmpty(item.totalAmount))
  1773. {
  1774. order.payment = Convert.ToDouble(item.totalAmount);
  1775. }
  1776. if (!string.IsNullOrEmpty(item.totalSellPrice))
  1777. {
  1778. order.total_fee = Convert.ToDouble(item.totalSellPrice);
  1779. }
  1780. //order.adjust_fee = Convert.ToDouble(item.price);
  1781. if (item.thirdSkuId != null && item.thirdSkuId != "")
  1782. {
  1783. order.sku_id = item.thirdSkuId;
  1784. }
  1785. if (item.specification != null && item.specification != "")
  1786. {
  1787. order.sku_properties_name = item.specification;
  1788. }
  1789. if (item.thirdSpuId != null && item.thirdSpuId != "")
  1790. {
  1791. order.spu_id = item.thirdSpuId;
  1792. }
  1793. if (isCreateOrder)
  1794. {
  1795. order.Create();
  1796. }
  1797. else
  1798. {
  1799. order.Update();
  1800. }
  1801. }
  1802. }
  1803. public CeErpTrade createTradeOrder(BizOrder bizOrder, CeErpTrade trade, bool isCreate)
  1804. {
  1805. if (trade == null)
  1806. { //新生成订单的
  1807. isCreate = true;
  1808. trade = new CeErpTrade();
  1809. trade.tid = bizOrder.thirdOrderId;
  1810. trade.type = bizOrder.orderPlatform;
  1811. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1812. {
  1813. trade.price = Convert.ToDouble(bizOrder.payAmount);
  1814. }
  1815. trade.discount_fee = 0;
  1816. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1817. {
  1818. trade.total_fee = Convert.ToDouble(bizOrder.payAmount);
  1819. }
  1820. if (bizOrder.orderTime != null && bizOrder.orderTime.Length > 0)
  1821. {
  1822. trade.created = Convert.ToDateTime(bizOrder.orderTime);
  1823. }
  1824. if (bizOrder.payTime != null && bizOrder.payTime.Length > 0)
  1825. {
  1826. trade.pay_time = Convert.ToDateTime(bizOrder.payTime);
  1827. }
  1828. trade.seller_nick = GetNull_tostring(bizOrder.openSellerNick);
  1829. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1830. {
  1831. trade.payment = Convert.ToDouble(bizOrder.payAmount);
  1832. }
  1833. }
  1834. trade.buyer_nick = GetNull_tostring(bizOrder.openBuyerNick);
  1835. trade.receiver_state = bizOrder.province;
  1836. if (!string.IsNullOrEmpty(bizOrder.num))
  1837. {
  1838. trade.num = Convert.ToDouble(bizOrder.num);
  1839. }
  1840. trade.receiver_city = bizOrder.city;
  1841. trade.receiver_address = GetNoNullValue_string(bizOrder.address);
  1842. trade.receiver_town = GetNoNullValue_string(bizOrder.receiverTown);
  1843. trade.receiver_district = GetNoNullValue_string(bizOrder.area);
  1844. trade.seller_flag = bizOrder.thirdFlag;
  1845. trade.orderType = bizOrder.orderType;
  1846. trade.orderFrom = 30;
  1847. trade.unrefundedAmount = bizOrder.unrefundedAmount;
  1848. if (bizOrder.modifyTime != null && bizOrder.modifyTime.Length > 0)
  1849. {
  1850. trade.modified = Convert.ToDateTime(bizOrder.modifyTime);
  1851. }
  1852. if (bizOrder.finishTime != null && bizOrder.finishTime.Length > 0)
  1853. {
  1854. trade.end_time = Convert.ToDateTime(bizOrder.finishTime);
  1855. }
  1856. if (bizOrder.shippingTime != null && bizOrder.shippingTime.Length > 0)
  1857. {
  1858. trade.delivery_time = Convert.ToDateTime(bizOrder.shippingTime);
  1859. }
  1860. if (bizOrder.confirmTime != null && bizOrder.confirmTime.Length > 0)
  1861. {
  1862. trade.confirmTime = Convert.ToDateTime(bizOrder.confirmTime);
  1863. }
  1864. trade.buyer_memo = GetNoNullValue_string(bizOrder.buyerRemark);
  1865. bool isSellerMemoChange = false;
  1866. //备注修改
  1867. bizOrder.sellerRemark = GetNoNullValue_string(bizOrder.sellerRemark);
  1868. if (trade.seller_memo != bizOrder.sellerRemark || trade.seller_memo.Length != bizOrder.sellerRemark.Length)
  1869. {
  1870. isSellerMemoChange = true;
  1871. }
  1872. trade.status = bizOrder.status;
  1873. trade.seller_memo = bizOrder.sellerRemark;
  1874. trade.buyer_id = bizOrder.openBuyerId;
  1875. trade.posCode = bizOrder.shopCode;
  1876. if (isCreate)
  1877. {
  1878. trade.Create();
  1879. }
  1880. else
  1881. {
  1882. if (bizOrder.status == "CLOSE")
  1883. {
  1884. trade.consign_time = DateTime.Now;
  1885. }
  1886. trade.Update();
  1887. }
  1888. try
  1889. {
  1890. if (bizOrder.status == "CLOSE" || bizOrder.status == "CANCEL")
  1891. {
  1892. StringBuilder sql = new StringBuilder();
  1893. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, bizOrder.thirdOrderId);
  1894. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1895. ApiVo apiVo = new ApiVo();
  1896. apiVo.actionName = "closeDesign";
  1897. apiVo.orderNumber = bizOrder.thirdOrderId;
  1898. designHelper.API_WorkCore(apiVo);//closeDesign
  1899. LogHelper.addLog(bizOrder.thirdOrderId, 0, "交易关闭", (int)OrderState.交易关闭);
  1900. // commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
  1901. // removeOldCustomerInfo(trade);
  1902. }
  1903. else if (bizOrder.status == "COMPLETE")
  1904. {
  1905. StringBuilder sql = new StringBuilder();
  1906. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, bizOrder.thirdOrderId);
  1907. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1908. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
  1909. }
  1910. else if (bizOrder.status == "SHIPPED")//已发货
  1911. {
  1912. StringBuilder sql = new StringBuilder();
  1913. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, bizOrder.thirdOrderId);
  1914. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1915. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
  1916. }
  1917. }
  1918. catch (Exception ex)
  1919. {
  1920. XLog.SaveLog(0, bizOrder.thirdOrderId + "shipped:" + ex.Message);
  1921. throw ex;
  1922. }
  1923. return trade;
  1924. }
  1925. public static apiUploaderResponse CopyDesignFile(string ctid, string oldCtid, int userId)
  1926. {
  1927. string post_url = "http://183.250.143.56:8088/autocopy.aspx";
  1928. WebClient wc = new WebClient();
  1929. wc.Encoding = Encoding.GetEncoding("utf-8");
  1930. //json参数
  1931. NameValueCollection PostVars = new NameValueCollection();
  1932. PostVars.Add("hexdata", oldCtid + "," + ctid);
  1933. PostVars.Add("userid", userId.ToString());
  1934. apiUploaderResponse result = null;
  1935. try
  1936. {
  1937. byte[] ret = wc.UploadValues(post_url, "POST", PostVars);
  1938. string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret);
  1939. result = JsonConvert.DeserializeObject<apiUploaderResponse>(remoteInfo);
  1940. }
  1941. catch (Exception ex)
  1942. {
  1943. XLog.SaveLog(0, "CopyDesignFile:" + ex.Message);
  1944. }
  1945. return result;
  1946. }
  1947. public static DateTime StampToDateTime(string timeStamp)
  1948. {
  1949. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  1950. long lTime = long.Parse(timeStamp + "0000");
  1951. TimeSpan toNow = new TimeSpan(lTime);
  1952. return dateTimeStart.Add(toNow);
  1953. }
  1954. public static string GetNull_tostring(object value)
  1955. {
  1956. if (value == null)
  1957. {
  1958. return "";
  1959. }
  1960. return value.ToString();
  1961. }
  1962. public static string GetNoNullValue_string(string value)
  1963. {
  1964. if (value == null)
  1965. {
  1966. return "";
  1967. }
  1968. value = value.Replace("\n", " ");
  1969. value = value.Replace("\r", " ");
  1970. return value;
  1971. }
  1972. public static string getShopNameByECode(string code)
  1973. {
  1974. string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
  1975. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  1976. if (dt != null && dt.Rows.Count > 0)
  1977. {
  1978. return dt.Rows[0]["ShopName"].ToString();
  1979. }
  1980. return "";
  1981. }
  1982. public static int orderAudit(int shopId)
  1983. {
  1984. try
  1985. {
  1986. CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
  1987. if (ceErpShop == null) return 2;
  1988. if (!ceErpShop.orderAudit) return 2;
  1989. return -1;
  1990. }
  1991. catch (Exception ex)
  1992. {
  1993. return 2;
  1994. }
  1995. }
  1996. public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
  1997. {
  1998. if (father.seller_nick == "") return 0;
  1999. CeErpCustomer cus = null;
  2000. cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
  2001. if (cus == null)
  2002. {
  2003. cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
  2004. }
  2005. int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
  2006. if (cus != null)
  2007. {
  2008. if (cus.lastbuy_time.ToString() == "") return 0;
  2009. if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
  2010. cus.buyer_id = father.buyer_id;
  2011. if (cus.lastTid == father.tid)
  2012. {
  2013. if (pcount != cus.product_count)
  2014. {
  2015. cus.product_count = pcount;
  2016. cus.Update();
  2017. }
  2018. }
  2019. else
  2020. {
  2021. int returnNum = 0;
  2022. TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
  2023. cus.buy_day = Convert.ToInt32(tsday.TotalDays);
  2024. cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
  2025. cus.buy_count = cus.buy_count + 1;
  2026. cus.lastbuy_time2 = cus.lastbuy_time;
  2027. cus.buyer_id = father.buyer_id;
  2028. cus.lastbuy_time = father.pay_time;
  2029. int lastpCount = cus.product_count;
  2030. cus.product_count = pcount;
  2031. cus.lastTid2 = cus.lastTid;
  2032. cus.lastTid = father.tid;
  2033. if (cus.buy_day > 1)
  2034. {
  2035. if (pcount > lastpCount && cus.product_count != 0)
  2036. {
  2037. cus.isMore = 1;
  2038. returnNum = 2;
  2039. }
  2040. else
  2041. returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
  2042. }
  2043. else
  2044. returnNum = 0;
  2045. cus.Update();
  2046. return returnNum;
  2047. }
  2048. }
  2049. else
  2050. {
  2051. try
  2052. {
  2053. cus = new CeErpCustomer();
  2054. cus.buyer_nick = father.buyer_nick;
  2055. cus.seller_nick = father.seller_nick;
  2056. cus.buyer_id = father.buyer_id;
  2057. cus.buy_day = 0;
  2058. cus.buy_count = 1;
  2059. cus.lastbuy_time = father.pay_time;
  2060. cus.lastTid = father.tid;
  2061. cus.total_fee = Convert.ToDouble(father.payment);
  2062. cus.product_count = pcount;
  2063. cus.Create();
  2064. return 0;
  2065. }
  2066. catch (Exception ex)
  2067. {
  2068. XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
  2069. }
  2070. }
  2071. return 0;
  2072. }
  2073. }
  2074. }