preSalesHelper.cs 112 KB

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