preSalesHelper.cs 114 KB

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