preSalesHelper.cs 118 KB

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