preSalesHelper.cs 119 KB

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