preSalesHelper.cs 97 KB

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