preSalesHelper.cs 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195
  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.status = refundOrder.status;
  1289. refund.Update();
  1290. int rstate = commonHelper.getRefundTagByState(refundOrder.status);
  1291. string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
  1292. StringBuilder sql = new StringBuilder();
  1293. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={0} where ctid='{1}' and isAfterSaleOrder=0;", rstate, refundOrder.ctid);
  1294. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1295. //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  1296. LogHelper.addLog(refundOrder.tid, 0, "更新退款状态:" + rstateWord, (int)OrderState.交易关闭);
  1297. // 取消设计费
  1298. StringBuilder sqls = new StringBuilder();
  1299. sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
  1300. CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
  1301. LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
  1302. }
  1303. }
  1304. List<RefundItemOrder> goodsItems = refundOrder.goodsItems;
  1305. foreach (RefundItemOrder item in goodsItems)
  1306. {
  1307. CeErpTradeOrder goods = CeErpTradeOrder.GetByOid(item.refOlId);
  1308. if (goods != null)
  1309. {
  1310. goods.refund_status = item.refundStatus;
  1311. goods.Update();
  1312. }
  1313. }
  1314. if (refundOrder.status == "WAIT_SELLER_AGREE")
  1315. {
  1316. StringBuilder sql = new StringBuilder();
  1317. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 1);
  1318. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1319. designHelper.API_refundOrder(refundOrder.tid, "refundIng", refundOrder.reason);
  1320. LogHelper.addLog(refundOrder.tid, 0, "申请退款中", 0);
  1321. }
  1322. else if (refundOrder.status == "CLOSED")
  1323. {
  1324. StringBuilder sql = new StringBuilder();
  1325. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 0);
  1326. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1327. designHelper.API_refundOrder(refundOrder.tid, "refundCancel", refundOrder.reason);
  1328. LogHelper.addLog(refundOrder.tid, 0, "关闭申请退款中", 0);
  1329. }
  1330. else if (refundOrder.status == "REFUNDED" || refundOrder.status == "SUCCESS")
  1331. {
  1332. designHelper.API_refundOrder(refundOrder.tid, "refundEd", refundOrder.reason);
  1333. }
  1334. }
  1335. else
  1336. {
  1337. }
  1338. }
  1339. returnErrorMsg("缺少必要的参数data");
  1340. }
  1341. public void createRefundMessage(string ctid, MessageState messageState, int userId, int type)
  1342. {
  1343. CeErpMessageTip ceErpMessageTip = new CeErpMessageTip();
  1344. ceErpMessageTip.tid = ctid;
  1345. ceErpMessageTip.type = Convert.ToInt32(messageState);
  1346. ceErpMessageTip.userId = userId;
  1347. ceErpMessageTip.isVisit = false;
  1348. ceErpMessageTip.content = "订单" + ctid + "申请了退款!";
  1349. ceErpMessageTip.Create();
  1350. StringBuilder sqlTip = new StringBuilder();
  1351. if (type == 1)
  1352. {
  1353. 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);
  1354. }
  1355. if (type == 2)
  1356. {
  1357. 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);
  1358. }
  1359. DataTable dth = DbHelper.DbConn.ExecuteDataset(sqlTip.ToString()).Tables[0];
  1360. if (dth.Rows.Count > 0)
  1361. {
  1362. foreach (DataRow dthdr in dth.Rows)
  1363. {
  1364. int Bid = Convert.ToInt32(dthdr["id"]);
  1365. if (Bid > 0)
  1366. {
  1367. CeErpMessageTip ceErpMessageTipB = new CeErpMessageTip();
  1368. ceErpMessageTipB.tid = ctid;
  1369. ceErpMessageTipB.type = Convert.ToInt32(messageState);
  1370. ceErpMessageTipB.userId = Bid;
  1371. ceErpMessageTipB.isVisit = false;
  1372. ceErpMessageTipB.content = "订单" + ctid + "申请了退款!";
  1373. ceErpMessageTipB.Create();
  1374. }
  1375. }
  1376. }
  1377. }
  1378. public List<tempResponse> createCellOrder(List<Api_trade_info.bizOrderSplit> bizOrderSplit, CeErpTrade trade, bool isCreate)
  1379. {
  1380. List<tempResponse> tempResponses = new List<tempResponse>();
  1381. CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
  1382. foreach (Api_trade_info.bizOrderSplit item in bizOrderSplit)
  1383. {
  1384. bool create = false;
  1385. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(item.splitNo);
  1386. if (entity == null)
  1387. {
  1388. entity = new CeErpTradeCell();
  1389. create = true;
  1390. entity.tid = trade.tid;
  1391. entity.pay_time = trade.pay_time;
  1392. }
  1393. if (entity.OrderState > 4)
  1394. {
  1395. continue;
  1396. }
  1397. entity.ctid = item.splitNo;
  1398. entity.seller_memo = item.systemRemark;
  1399. if (!string.IsNullOrEmpty(item.splitAmount))
  1400. {
  1401. entity.payment = Convert.ToDouble(item.splitAmount);
  1402. }
  1403. if (!string.IsNullOrEmpty(item.splitAmount))
  1404. {
  1405. entity.AfterSalePayment = Convert.ToDouble(item.splitAmount);
  1406. }
  1407. if (!string.IsNullOrEmpty(item.sfMark))
  1408. {
  1409. entity.IsSF = Convert.ToInt32(item.sfMark);
  1410. }
  1411. entity.ProductSize = item.size;
  1412. entity.Material = item.material;
  1413. entity.CustomerUserId = item.erpCustomerServiceId;
  1414. //entity.Craft = item.craft;
  1415. entity.ProductCount = item.productQuantity;
  1416. entity.ProductId = tmcHelper.getProductIdByName(item.cate3Id);
  1417. if (!string.IsNullOrEmpty(item.internalStatus))
  1418. {
  1419. entity.OrderState = Convert.ToInt32(item.internalStatus);
  1420. }
  1421. entity.IsUrgency = item.isUrgent;
  1422. entity.ptid = item.ptid;
  1423. entity.SplitTag = item.splitInfoNo;
  1424. if (!string.IsNullOrEmpty(item.paymentFile))
  1425. {
  1426. entity.PayProofImg = item.paymentFile;
  1427. }
  1428. if (item.shippingTime != null && item.shippingTime.Length > 0)
  1429. {
  1430. entity.UnusualTime = Convert.ToDateTime(item.shippingTime);
  1431. entity.UrgencyTime = Convert.ToDateTime(item.shippingTime);
  1432. }
  1433. if (!string.IsNullOrEmpty(item.sendGiftMark))
  1434. {
  1435. entity.IsSendGift = Convert.ToInt32(item.sendGiftMark);
  1436. }
  1437. entity.OtherMemo = item.otherRemark;
  1438. entity.IsOldCustomer = item.isRepurchase ? 1 : 0;
  1439. entity.IsOldCustomerMore = item.isOldCustomerMore;
  1440. entity.MemoOpt = item.memoOpt;
  1441. entity.isDianziOrder = item.isDianziOrder;
  1442. if (item.isPreShipping != null && item.isPreShipping.Length > 0)
  1443. {
  1444. entity.IsPreDelivery = Convert.ToInt32(item.isPreShipping);
  1445. }
  1446. if (item.checkOrderTime != null && item.checkOrderTime.Length > 0)
  1447. {
  1448. entity.CheckOrderTime = Convert.ToDateTime(item.checkOrderTime);
  1449. }
  1450. int shopId = 0;
  1451. if (nShop != null)
  1452. {
  1453. shopId = nShop.ID;
  1454. }
  1455. entity.ShopId = shopId;
  1456. entity.OrderSn = item.OrderSn;
  1457. entity.ParentSplitNo = item.parentSplitNo;
  1458. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1459. if (ceErpTradeCellExtend == null)
  1460. {
  1461. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  1462. ceErpTradeCellExtend.ctid = entity.ctid;
  1463. }
  1464. ceErpTradeCellExtend.cate1 = item.cate1;
  1465. ceErpTradeCellExtend.cate2 = item.cate2;
  1466. ceErpTradeCellExtend.scene = item.scene;
  1467. ceErpTradeCellExtend.material = item.material;
  1468. ceErpTradeCellExtend.offerAmount = item.offerAmount;
  1469. ceErpTradeCellExtend.numbers = item.numbers;
  1470. ceErpTradeCellExtend.typeScene = item.typeScene;
  1471. ceErpTradeCellExtend.opScene = item.opScene;
  1472. ceErpTradeCellExtend.craft = item.craft;
  1473. ceErpTradeCellExtend.numberType = item.numberType;
  1474. ceErpTradeCellExtend.cate1Id = item.cate1Id;
  1475. ceErpTradeCellExtend.cate2Id = item.cate2Id;
  1476. ceErpTradeCellExtend.cate3Id = item.cate3Id;
  1477. ceErpTradeCellExtend.sceneId = item.sceneId;
  1478. ceErpTradeCellExtend.typeSceneId = item.typeSceneId;
  1479. ceErpTradeCellExtend.opSceneId = item.opSceneId;
  1480. ceErpTradeCellExtend.materialId = item.materialId;
  1481. ceErpTradeCellExtend.width = item.width;
  1482. ceErpTradeCellExtend.height = item.height;
  1483. ceErpTradeCellExtend.length = item.length;
  1484. ceErpTradeCellExtend.recSize = item.recSize;
  1485. ceErpTradeCellExtend.sizeUnit = item.sizeUnit;
  1486. ceErpTradeCellExtend.numberUnit = item.numberUnit;
  1487. ceErpTradeCellExtend.orderFrom = 30;
  1488. ceErpTradeCellExtend.spu_id = item.spuId;
  1489. ceErpTradeCellExtend.quantity = item.quantity;
  1490. ceErpTradeCellExtend.discountAmount = item.discountAmount;
  1491. ceErpTradeCellExtend.differentAmount = item.compensateAmount;
  1492. ceErpTradeCellExtend.differentSplitNo = item.compensateSplitOrderUniqueNo;
  1493. ceErpTradeCellExtend.orderType = item.orderType;
  1494. ceErpTradeCellExtend.parentOrderSn = item.parentSplitNo;
  1495. if (ceErpTradeCellExtend.ID > 0)
  1496. {
  1497. ceErpTradeCellExtend.Update();
  1498. }
  1499. else
  1500. {
  1501. ceErpTradeCellExtend.Create();
  1502. }
  1503. if (item.isGift == 1)
  1504. {
  1505. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  1506. entity.IsXianHuo = 1;
  1507. entity.IsGift = 1;
  1508. entity.FinishPlaceTime = trade.pay_time;
  1509. if (entity.OrderState < 6)
  1510. {
  1511. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1512. }
  1513. }
  1514. if (item.isSpot)
  1515. {
  1516. if (entity.OrderState < 6)
  1517. {
  1518. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1519. }
  1520. entity.seller_memo = item.systemRemark;
  1521. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1522. entity.IsXianHuo = 1;
  1523. entity.FinishPlaceTime = entity.pay_time;
  1524. if (item.systemRemark.IndexOf("封酒贴") != -1)
  1525. {
  1526. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  1527. if (trade.buyer_memo != "")
  1528. {
  1529. entity.OrderState = 2;
  1530. entity.ProductId = 1;
  1531. entity.IsXianHuo = 0;
  1532. item.systemRemark = item.systemRemark.Replace("现货", "");
  1533. item.systemRemark = item.systemRemark.Replace(" ", "");
  1534. entity.seller_memo = item.systemRemark;
  1535. if (entity.ShopId != 0)
  1536. {
  1537. entity.OrderState = orderAudit(entity.ShopId);
  1538. }
  1539. }
  1540. }
  1541. else if (item.systemRemark.IndexOf("#") != -1)
  1542. {
  1543. entity.SupplierId = 87;
  1544. }
  1545. else if (item.systemRemark.IndexOf("喜字贴") != -1)
  1546. {
  1547. entity.SupplierId = 70;
  1548. }
  1549. else if (item.systemRemark.IndexOf("兔团团") != -1)
  1550. {
  1551. entity.SupplierId = 101;
  1552. }
  1553. else if (item.systemRemark.IndexOf("手拉旗") != -1)
  1554. {
  1555. entity.SupplierId = 108;
  1556. }
  1557. try
  1558. {
  1559. string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
  1560. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  1561. List<Dictionary<string, string>> material_list = new List<Dictionary<string, string>>();
  1562. List<Dictionary<string, string>> name_list = new List<Dictionary<string, string>>();
  1563. foreach (DataRow dr in goodsDt.Rows)
  1564. {
  1565. string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
  1566. List<string> xianhuo = sqlMemo.Split(',').ToList();
  1567. foreach (var val in xianhuo)
  1568. {
  1569. if (string.IsNullOrEmpty(val)) continue;
  1570. Dictionary<string, string> material_map = new Dictionary<string, string>();//材质
  1571. Dictionary<string, string> name_map = new Dictionary<string, string>();//特殊名称
  1572. if (val.IndexOf('-') > -1)
  1573. {
  1574. List<string> list = val.Split('-').ToList();
  1575. material_map.Add(dr["id"].ToString(), list[0]);
  1576. name_map.Add(dr["id"].ToString(), list[1]);
  1577. }
  1578. else
  1579. {
  1580. material_map.Add(dr["id"].ToString(), val);
  1581. }
  1582. material_list.Add(material_map);
  1583. name_list.Add(name_map);
  1584. }
  1585. }
  1586. List<string> materials = new List<string>();
  1587. List<string> names = new List<string>();
  1588. List<string> result = new List<string>();
  1589. for (int i = 0; i < material_list.Count; i++)
  1590. {
  1591. Dictionary<string, string> map = material_list[i];
  1592. foreach (var val in map)
  1593. {
  1594. if (item.systemRemark.IndexOf(val.Value) > -1)
  1595. {
  1596. Dictionary<string, string> map2 = name_list[i];
  1597. if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
  1598. {
  1599. foreach (var item1 in map2)
  1600. {
  1601. if (item.systemRemark.IndexOf(item1.Value) > -1)
  1602. {
  1603. names.Add(item1.Key);
  1604. materials.Add(val.Key);
  1605. }
  1606. }
  1607. }
  1608. else
  1609. {
  1610. materials.Add(val.Key);
  1611. }
  1612. }
  1613. }
  1614. }
  1615. if (names.Count > 0)//特殊名称有只先在特殊名称里选择
  1616. {
  1617. result = names.Distinct().ToList();
  1618. }
  1619. else
  1620. {
  1621. result = materials.Distinct().ToList();
  1622. }
  1623. if (result.Count > 0)
  1624. {
  1625. Random rnd = new Random();
  1626. int index = rnd.Next(result.Count);
  1627. entity.SupplierId = int.Parse(result[index]);
  1628. }
  1629. }
  1630. catch (Exception e)
  1631. {
  1632. XLog.SaveLog(0, "|现货匹配|" + e.Message);
  1633. }
  1634. }
  1635. if (isCreate)
  1636. {
  1637. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  1638. if (oldRes > 0)
  1639. {
  1640. //entity.IsOldCustomer = 1;
  1641. //if (oldRes == 2) entity.IsOldCustomerMore = 1;
  1642. }
  1643. }
  1644. if (item.sampleMark == "1")
  1645. {
  1646. entity.IsSample = 1;
  1647. entity.OrderState = 6;
  1648. entity.FinishPlaceTime = DateTime.Now;
  1649. entity.IsOldCustomer = 0;
  1650. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1651. }
  1652. if (item.sampleMark == "3")
  1653. {
  1654. entity.IsSample = 3;
  1655. entity.OrderState = 6;
  1656. entity.FinishPlaceTime = DateTime.Now;
  1657. entity.IsOldCustomer = 0;
  1658. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1659. }
  1660. if (item.sampleMark == "2" && !string.IsNullOrEmpty(item.parentSplitNo))
  1661. {
  1662. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(item.parentSplitNo);
  1663. if (ceErpTradeCell != null)
  1664. {
  1665. entity.CustomerUserId = ceErpTradeCell.CustomerUserId;
  1666. entity.DesignUserId = ceErpTradeCell.DesignUserId;
  1667. entity.SupplierId = ceErpTradeCell.SupplierId;
  1668. entity.IsSample = 2;
  1669. entity.WaitDesignTime = ceErpTradeCell.WaitDesignTime;
  1670. entity.StartDesignTime = ceErpTradeCell.StartDesignTime;
  1671. entity.FinishDesignTime = ceErpTradeCell.FinishDesignTime;
  1672. entity.FinishPlaceTime = ceErpTradeCell.FinishPlaceTime;
  1673. }
  1674. CeErpTradeCellExtend parentCell = CeErpTradeCellExtend.getByTid(item.parentSplitNo);
  1675. if (parentCell == null)
  1676. {
  1677. parentCell = new CeErpTradeCellExtend();
  1678. parentCell.ctid = item.parentSplitNo;
  1679. }
  1680. if (!string.IsNullOrEmpty(item.splitAmount))
  1681. {
  1682. parentCell.differentAmount += Convert.ToDouble(item.splitAmount);
  1683. }
  1684. if (parentCell.ID > 0)
  1685. {
  1686. parentCell.Update();
  1687. }
  1688. else
  1689. {
  1690. parentCell.Create();
  1691. }
  1692. ApiVo apiVo = new ApiVo();
  1693. apiVo.orderNumber = entity.ptid;
  1694. apiVo.payment = entity.payment;
  1695. apiVo.actionName = "repairDesign";
  1696. designHelper.API_WorkCore(apiVo);//repairDesign
  1697. }
  1698. bool isCopyFile = false;
  1699. //老客户
  1700. if (item.isRepurchase)
  1701. {
  1702. if (item.isOldCustomer == 1)
  1703. {
  1704. tmcHelper.dealOldCustomerEntityTag(ref entity, trade);
  1705. }
  1706. if (item.isOldCustomer == 3)
  1707. {
  1708. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  1709. entity.WaitDesignTime = DateTime.Now;
  1710. isCopyFile = true;
  1711. }
  1712. if (item.isOldCustomer == 2)
  1713. {
  1714. entity.OrderState = 3;
  1715. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  1716. entity.WaitDesignTime = DateTime.Now;
  1717. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  1718. }
  1719. }
  1720. if (create)
  1721. {
  1722. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "创建推送生成:" + entity.seller_memo, entity.OrderState);
  1723. entity.Create();
  1724. }
  1725. else
  1726. {
  1727. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "更新推送生成:" + entity.seller_memo, entity.OrderState);
  1728. designHelper.API_update_order(entity);
  1729. entity.Update();
  1730. }
  1731. if (isCopyFile)
  1732. {
  1733. apiUploaderResponse upResult = CopyDesignFile(entity.ctid, item.oldOrderSn, entity.CustomerUserId);
  1734. if (upResult == null || "error".Equals(upResult.type))
  1735. {
  1736. tempResponse response = new tempResponse();
  1737. response.flag = "1";
  1738. response.flagData = entity.ctid;
  1739. response.flagMsg = upResult == null ? "复制文件出错!" : upResult.result;
  1740. }
  1741. }
  1742. }
  1743. return tempResponses;
  1744. }
  1745. public void createItemOrder(List<Api_trade_info.TradeItemOrder> orderList, CeErpTrade trade)
  1746. {
  1747. foreach (Api_trade_info.TradeItemOrder item in orderList)
  1748. {
  1749. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.thirdOrderItemId);
  1750. bool isCreateOrder = false;
  1751. if (order == null)
  1752. {
  1753. order = new CeErpTradeOrder();
  1754. isCreateOrder = true;
  1755. order.oid = item.thirdOrderItemId;
  1756. order.tid = trade.tid;
  1757. order.buyer_nick = trade.buyer_nick;
  1758. }
  1759. order.refund_status = item.refundStatus;
  1760. order.status = trade.status;
  1761. order.title = item.title;
  1762. if (!string.IsNullOrEmpty(item.price))
  1763. {
  1764. order.price = Convert.ToDouble(item.price);
  1765. }
  1766. if (item.picUrl != null)
  1767. {
  1768. order.pic_path = item.picUrl;
  1769. }
  1770. if (!string.IsNullOrEmpty(item.num))
  1771. {
  1772. order.num = Convert.ToDouble(item.num);
  1773. }
  1774. if (!string.IsNullOrEmpty(item.totalAmount))
  1775. {
  1776. order.payment = Convert.ToDouble(item.totalAmount);
  1777. }
  1778. if (!string.IsNullOrEmpty(item.totalSellPrice))
  1779. {
  1780. order.total_fee = Convert.ToDouble(item.totalSellPrice);
  1781. }
  1782. //order.adjust_fee = Convert.ToDouble(item.price);
  1783. if (item.thirdSkuId != null && item.thirdSkuId != "")
  1784. {
  1785. order.sku_id = item.thirdSkuId;
  1786. }
  1787. if (item.specification != null && item.specification != "")
  1788. {
  1789. order.sku_properties_name = item.specification;
  1790. }
  1791. if (item.thirdSpuId != null && item.thirdSpuId != "")
  1792. {
  1793. order.spu_id = item.thirdSpuId;
  1794. }
  1795. if (isCreateOrder)
  1796. {
  1797. order.Create();
  1798. }
  1799. else
  1800. {
  1801. order.Update();
  1802. }
  1803. }
  1804. }
  1805. public CeErpTrade createTradeOrder(BizOrder bizOrder, CeErpTrade trade, bool isCreate)
  1806. {
  1807. if (trade == null)
  1808. { //新生成订单的
  1809. isCreate = true;
  1810. trade = new CeErpTrade();
  1811. trade.tid = bizOrder.thirdOrderId;
  1812. trade.type = bizOrder.orderPlatform;
  1813. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1814. {
  1815. trade.price = Convert.ToDouble(bizOrder.payAmount);
  1816. }
  1817. trade.discount_fee = 0;
  1818. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1819. {
  1820. trade.total_fee = Convert.ToDouble(bizOrder.payAmount);
  1821. }
  1822. if (bizOrder.orderTime != null && bizOrder.orderTime.Length > 0)
  1823. {
  1824. trade.created = Convert.ToDateTime(bizOrder.orderTime);
  1825. }
  1826. if (bizOrder.payTime != null && bizOrder.payTime.Length > 0)
  1827. {
  1828. trade.pay_time = Convert.ToDateTime(bizOrder.payTime);
  1829. }
  1830. trade.seller_nick = GetNull_tostring(bizOrder.openSellerNick);
  1831. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1832. {
  1833. trade.payment = Convert.ToDouble(bizOrder.payAmount);
  1834. }
  1835. }
  1836. trade.buyer_nick = GetNull_tostring(bizOrder.openBuyerNick);
  1837. trade.receiver_state = bizOrder.province;
  1838. if (!string.IsNullOrEmpty(bizOrder.num))
  1839. {
  1840. trade.num = Convert.ToDouble(bizOrder.num);
  1841. }
  1842. trade.receiver_city = bizOrder.city;
  1843. trade.receiver_address = GetNoNullValue_string(bizOrder.address);
  1844. trade.receiver_town = GetNoNullValue_string(bizOrder.receiverTown);
  1845. trade.receiver_district = GetNoNullValue_string(bizOrder.area);
  1846. trade.seller_flag = bizOrder.thirdFlag;
  1847. trade.orderType = bizOrder.orderType;
  1848. trade.orderFrom = 30;
  1849. trade.unrefundedAmount = bizOrder.unrefundedAmount;
  1850. if (bizOrder.modifyTime != null && bizOrder.modifyTime.Length > 0)
  1851. {
  1852. trade.modified = Convert.ToDateTime(bizOrder.modifyTime);
  1853. }
  1854. if (bizOrder.finishTime != null && bizOrder.finishTime.Length > 0)
  1855. {
  1856. trade.end_time = Convert.ToDateTime(bizOrder.finishTime);
  1857. }
  1858. if (bizOrder.shippingTime != null && bizOrder.shippingTime.Length > 0)
  1859. {
  1860. trade.delivery_time = Convert.ToDateTime(bizOrder.shippingTime);
  1861. }
  1862. if (bizOrder.confirmTime != null && bizOrder.confirmTime.Length > 0)
  1863. {
  1864. trade.confirmTime = Convert.ToDateTime(bizOrder.confirmTime);
  1865. }
  1866. trade.buyer_memo = GetNoNullValue_string(bizOrder.buyerRemark);
  1867. bool isSellerMemoChange = false;
  1868. //备注修改
  1869. bizOrder.sellerRemark = GetNoNullValue_string(bizOrder.sellerRemark);
  1870. if (trade.seller_memo != bizOrder.sellerRemark || trade.seller_memo.Length != bizOrder.sellerRemark.Length)
  1871. {
  1872. isSellerMemoChange = true;
  1873. }
  1874. trade.status = bizOrder.status;
  1875. trade.seller_memo = bizOrder.sellerRemark;
  1876. trade.buyer_id = bizOrder.openBuyerId;
  1877. trade.posCode = bizOrder.shopCode;
  1878. if (isCreate)
  1879. {
  1880. trade.Create();
  1881. }
  1882. else
  1883. {
  1884. if (bizOrder.status == "CLOSE")
  1885. {
  1886. trade.consign_time = DateTime.Now;
  1887. }
  1888. trade.Update();
  1889. }
  1890. try
  1891. {
  1892. if (bizOrder.status == "CLOSE" || bizOrder.status == "CANCEL")
  1893. {
  1894. StringBuilder sql = new StringBuilder();
  1895. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, bizOrder.thirdOrderId);
  1896. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1897. ApiVo apiVo = new ApiVo();
  1898. apiVo.actionName = "closeDesign";
  1899. apiVo.orderNumber = bizOrder.thirdOrderId;
  1900. designHelper.API_WorkCore(apiVo);//closeDesign
  1901. LogHelper.addLog(bizOrder.thirdOrderId, 0, "交易关闭", (int)OrderState.交易关闭);
  1902. // commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
  1903. // removeOldCustomerInfo(trade);
  1904. }
  1905. else if (bizOrder.status == "COMPLETE")
  1906. {
  1907. StringBuilder sql = new StringBuilder();
  1908. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, bizOrder.thirdOrderId);
  1909. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1910. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
  1911. }
  1912. else if (bizOrder.status == "SHIPPED")//已发货
  1913. {
  1914. StringBuilder sql = new StringBuilder();
  1915. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, bizOrder.thirdOrderId);
  1916. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1917. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
  1918. }
  1919. }
  1920. catch (Exception ex)
  1921. {
  1922. XLog.SaveLog(0, bizOrder.thirdOrderId + "shipped:" + ex.Message);
  1923. throw ex;
  1924. }
  1925. return trade;
  1926. }
  1927. public static apiUploaderResponse CopyDesignFile(string ctid, string oldCtid, int userId)
  1928. {
  1929. string post_url = "http://183.250.143.56:8088/autocopy.aspx";
  1930. WebClient wc = new WebClient();
  1931. wc.Encoding = Encoding.GetEncoding("utf-8");
  1932. //json参数
  1933. NameValueCollection PostVars = new NameValueCollection();
  1934. PostVars.Add("hexdata", oldCtid + "," + ctid);
  1935. PostVars.Add("userid", userId.ToString());
  1936. apiUploaderResponse result = null;
  1937. try
  1938. {
  1939. byte[] ret = wc.UploadValues(post_url, "POST", PostVars);
  1940. string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret);
  1941. result = JsonConvert.DeserializeObject<apiUploaderResponse>(remoteInfo);
  1942. }
  1943. catch (Exception ex)
  1944. {
  1945. XLog.SaveLog(0, "CopyDesignFile:" + ex.Message);
  1946. }
  1947. return result;
  1948. }
  1949. public static DateTime StampToDateTime(string timeStamp)
  1950. {
  1951. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  1952. long lTime = long.Parse(timeStamp + "0000");
  1953. TimeSpan toNow = new TimeSpan(lTime);
  1954. return dateTimeStart.Add(toNow);
  1955. }
  1956. public static string GetNull_tostring(object value)
  1957. {
  1958. if (value == null)
  1959. {
  1960. return "";
  1961. }
  1962. return value.ToString();
  1963. }
  1964. public static string GetNoNullValue_string(string value)
  1965. {
  1966. if (value == null)
  1967. {
  1968. return "";
  1969. }
  1970. value = value.Replace("\n", " ");
  1971. value = value.Replace("\r", " ");
  1972. return value;
  1973. }
  1974. public static string getShopNameByECode(string code)
  1975. {
  1976. string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
  1977. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  1978. if (dt != null && dt.Rows.Count > 0)
  1979. {
  1980. return dt.Rows[0]["ShopName"].ToString();
  1981. }
  1982. return "";
  1983. }
  1984. public static int orderAudit(int shopId)
  1985. {
  1986. try
  1987. {
  1988. CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
  1989. if (ceErpShop == null) return 2;
  1990. if (!ceErpShop.orderAudit) return 2;
  1991. return -1;
  1992. }
  1993. catch (Exception ex)
  1994. {
  1995. return 2;
  1996. }
  1997. }
  1998. public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
  1999. {
  2000. if (father.seller_nick == "") return 0;
  2001. CeErpCustomer cus = null;
  2002. cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
  2003. if (cus == null)
  2004. {
  2005. cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
  2006. }
  2007. int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
  2008. if (cus != null)
  2009. {
  2010. if (cus.lastbuy_time.ToString() == "") return 0;
  2011. if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
  2012. cus.buyer_id = father.buyer_id;
  2013. if (cus.lastTid == father.tid)
  2014. {
  2015. if (pcount != cus.product_count)
  2016. {
  2017. cus.product_count = pcount;
  2018. cus.Update();
  2019. }
  2020. }
  2021. else
  2022. {
  2023. int returnNum = 0;
  2024. TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
  2025. cus.buy_day = Convert.ToInt32(tsday.TotalDays);
  2026. cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
  2027. cus.buy_count = cus.buy_count + 1;
  2028. cus.lastbuy_time2 = cus.lastbuy_time;
  2029. cus.buyer_id = father.buyer_id;
  2030. cus.lastbuy_time = father.pay_time;
  2031. int lastpCount = cus.product_count;
  2032. cus.product_count = pcount;
  2033. cus.lastTid2 = cus.lastTid;
  2034. cus.lastTid = father.tid;
  2035. if (cus.buy_day > 1)
  2036. {
  2037. if (pcount > lastpCount && cus.product_count != 0)
  2038. {
  2039. cus.isMore = 1;
  2040. returnNum = 2;
  2041. }
  2042. else
  2043. returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
  2044. }
  2045. else
  2046. returnNum = 0;
  2047. cus.Update();
  2048. return returnNum;
  2049. }
  2050. }
  2051. else
  2052. {
  2053. try
  2054. {
  2055. cus = new CeErpCustomer();
  2056. cus.buyer_nick = father.buyer_nick;
  2057. cus.seller_nick = father.seller_nick;
  2058. cus.buyer_id = father.buyer_id;
  2059. cus.buy_day = 0;
  2060. cus.buy_count = 1;
  2061. cus.lastbuy_time = father.pay_time;
  2062. cus.lastTid = father.tid;
  2063. cus.total_fee = Convert.ToDouble(father.payment);
  2064. cus.product_count = pcount;
  2065. cus.Create();
  2066. return 0;
  2067. }
  2068. catch (Exception ex)
  2069. {
  2070. XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
  2071. }
  2072. }
  2073. return 0;
  2074. }
  2075. }
  2076. }