preSalesHelper.cs 107 KB

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