preSalesHelper.cs 114 KB

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