preSalesHelper.cs 97 KB

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