preSalesHelper.cs 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607
  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. }
  1511. catch (Exception ex)
  1512. {
  1513. XLog.SaveLog(0, "dealMessageInfo|2|" + ex);
  1514. return;
  1515. }
  1516. return;
  1517. }
  1518. public void refundOrder()
  1519. {
  1520. if (UrlPostParmsCheck("data"))
  1521. {
  1522. string data = GetPostString("data");
  1523. Api_refund_info info = null;
  1524. try
  1525. {
  1526. info = JsonConvert.DeserializeObject<Api_refund_info>(data);
  1527. }
  1528. catch (Exception ex)
  1529. {
  1530. XLog.SaveLog(0, "refundOrder|4|" + ex.Message);
  1531. returnErrorMsg(ex.Message);
  1532. return;
  1533. }
  1534. if (info == null)
  1535. {
  1536. XLog.SaveLog(0, "Api_refund_info isNull");
  1537. returnErrorMsg("接口对象处理错误RefundOrder=null1");
  1538. return;
  1539. }
  1540. RefundOrder refundOrder = info.refundOrder;
  1541. if (refundOrder == null)
  1542. {
  1543. returnErrorMsg("接口对象处理错误RefundOrder=null2");
  1544. return;
  1545. }
  1546. CeErpTrade trade = CeErpTrade.Get(refundOrder.tid);
  1547. if (trade != null)
  1548. {
  1549. CeErpTradeRefund refund = CeErpTradeRefund.GetByOidAndReId(refundOrder.ctid, refundOrder.orderSn);
  1550. LogHelper.addLog(refundOrder.ctid, 0, "客户退款", 0);
  1551. if (refund == null)
  1552. {
  1553. refund = new CeErpTradeRefund();
  1554. refund.refund_id = refundOrder.orderSn;
  1555. refund.tid = refundOrder.tid;
  1556. refund.oid = refundOrder.ctid;
  1557. if (refundOrder.createTime != null && refundOrder.createTime.Length > 0)
  1558. {
  1559. refund.created = Convert.ToDateTime(refundOrder.createTime);
  1560. }
  1561. if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
  1562. {
  1563. refund.modified = Convert.ToDateTime(refundOrder.updateTime);
  1564. }
  1565. refund.status = refundOrder.status;
  1566. refund.order_status = refundOrder.orderStatus;
  1567. refund.payment = refundOrder.payment.ToString();
  1568. refund.refund_fee = refundOrder.refundFee;//退款金额
  1569. refund.buyer_nick = GetNull_tostring(refundOrder.openBuyerNick);
  1570. refund.seller_nick = refundOrder.seller_nick;
  1571. refund.total_fee = refundOrder.totalFee;
  1572. refund.RefundState = 1;
  1573. refund.reason = refundOrder.reason;
  1574. refund.refundDesc = refundOrder.desc;
  1575. refund.IsPartRefund = refundOrder.isPartRefund;
  1576. refund.Create();
  1577. try
  1578. {
  1579. StringBuilder CeErpTradeCellSql = new StringBuilder();
  1580. CeErpTradeCellSql.AppendFormat("select * from CE_ErpTradeCell where ctid='{0}';", refundOrder.ctid);
  1581. DataSet cell = DbHelper.DbConn.ExecuteDataset(CeErpTradeCellSql.ToString());
  1582. DataTable datatable = cell.Tables[0];
  1583. if (datatable.Rows.Count > 0)
  1584. {
  1585. foreach (DataRow dr in datatable.Rows)
  1586. {
  1587. int DesignUserId = Convert.ToInt32(dr["DesignUserId"]);
  1588. int OrderState = Convert.ToInt32(dr["OrderState"]);
  1589. int CustomerUserId = Convert.ToInt32(dr["CustomerUserId"]);
  1590. if (DesignUserId > 0 && OrderState == 4)
  1591. {
  1592. createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, DesignUserId, 1);
  1593. }
  1594. if (CustomerUserId > 0)
  1595. {
  1596. createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, CustomerUserId, 1);
  1597. }
  1598. }
  1599. }
  1600. }
  1601. catch (Exception ex)
  1602. {
  1603. XLog.SaveLog(0, "退款推送通知创建失败!!" + ex);
  1604. }
  1605. int rstate = commonHelper.getRefundTagByState(refundOrder.status);
  1606. StringBuilder sql = new StringBuilder();
  1607. if (refund.IsPartRefund == 1)
  1608. {
  1609. double paylast = Convert.ToDouble(refundOrder.payment) - Convert.ToDouble(refund.refund_fee);
  1610. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1},payment={2} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 3, paylast);
  1611. }
  1612. else
  1613. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, rstate);
  1614. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1615. string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
  1616. //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  1617. StringBuilder sqls = new StringBuilder();
  1618. sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
  1619. CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
  1620. LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
  1621. }
  1622. else
  1623. {
  1624. if (refund.status != refundOrder.status)
  1625. {
  1626. refund.modified = DateTime.Now;
  1627. if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
  1628. {
  1629. refund.modified = Convert.ToDateTime(refundOrder.updateTime);
  1630. }
  1631. refund.order_status = refundOrder.orderStatus;
  1632. refund.status = refundOrder.status;
  1633. refund.Update();
  1634. int rstate = commonHelper.getRefundTagByState(refundOrder.status);
  1635. string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
  1636. StringBuilder sql = new StringBuilder();
  1637. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={0} where ctid='{1}' and isAfterSaleOrder=0;", rstate, refundOrder.ctid);
  1638. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1639. //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  1640. LogHelper.addLog(refundOrder.tid, 0, "更新退款状态:" + rstateWord, (int)OrderState.交易关闭);
  1641. // 取消设计费
  1642. StringBuilder sqls = new StringBuilder();
  1643. sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
  1644. CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
  1645. LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
  1646. }
  1647. }
  1648. List<RefundItemOrder> goodsItems = refundOrder.goodsItems;
  1649. foreach (RefundItemOrder item in goodsItems)
  1650. {
  1651. CeErpTradeOrder goods = CeErpTradeOrder.GetByOid(item.refOlId);
  1652. if (goods != null)
  1653. {
  1654. goods.refund_status = item.refundStatus;
  1655. goods.Update();
  1656. }
  1657. }
  1658. if (refundOrder.status == "WAIT_SELLER_AGREE")
  1659. {
  1660. StringBuilder sql = new StringBuilder();
  1661. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 1);
  1662. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1663. designHelper.API_refundOrder(refundOrder.tid, "refundIng", refundOrder.reason);
  1664. LogHelper.addLog(refundOrder.tid, 0, "申请退款中", 0);
  1665. }
  1666. else if (refundOrder.status == "CLOSED")
  1667. {
  1668. StringBuilder sql = new StringBuilder();
  1669. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 0);
  1670. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1671. designHelper.API_refundOrder(refundOrder.tid, "refundCancel", refundOrder.reason);
  1672. LogHelper.addLog(refundOrder.tid, 0, "关闭申请退款中", 0);
  1673. }
  1674. else if (refundOrder.status == "REFUNDED" || refundOrder.status == "SUCCESS")
  1675. {
  1676. designHelper.API_refundOrder(refundOrder.tid, "refundEd", refundOrder.reason);
  1677. }
  1678. }
  1679. else
  1680. {
  1681. }
  1682. }
  1683. returnErrorMsg("缺少必要的参数data");
  1684. }
  1685. public void createRefundMessage(string ctid, MessageState messageState, int userId, int type)
  1686. {
  1687. CeErpMessageTip ceErpMessageTip = new CeErpMessageTip();
  1688. ceErpMessageTip.tid = ctid;
  1689. ceErpMessageTip.type = Convert.ToInt32(messageState);
  1690. ceErpMessageTip.userId = userId;
  1691. ceErpMessageTip.isVisit = false;
  1692. ceErpMessageTip.content = "订单" + ctid + "申请了退款!";
  1693. ceErpMessageTip.Create();
  1694. StringBuilder sqlTip = new StringBuilder();
  1695. if (type == 1)
  1696. {
  1697. 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);
  1698. }
  1699. if (type == 2)
  1700. {
  1701. 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);
  1702. }
  1703. DataTable dth = DbHelper.DbConn.ExecuteDataset(sqlTip.ToString()).Tables[0];
  1704. if (dth.Rows.Count > 0)
  1705. {
  1706. foreach (DataRow dthdr in dth.Rows)
  1707. {
  1708. int Bid = Convert.ToInt32(dthdr["id"]);
  1709. if (Bid > 0)
  1710. {
  1711. CeErpMessageTip ceErpMessageTipB = new CeErpMessageTip();
  1712. ceErpMessageTipB.tid = ctid;
  1713. ceErpMessageTipB.type = Convert.ToInt32(messageState);
  1714. ceErpMessageTipB.userId = Bid;
  1715. ceErpMessageTipB.isVisit = false;
  1716. ceErpMessageTipB.content = "订单" + ctid + "申请了退款!";
  1717. ceErpMessageTipB.Create();
  1718. }
  1719. }
  1720. }
  1721. }
  1722. public static List<tempResponse> createCellOrder(List<Api_trade_info.bizOrderSplit> bizOrderSplit, CeErpTrade trade, bool isCreate)
  1723. {
  1724. List<tempResponse> tempResponses = new List<tempResponse>();
  1725. CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
  1726. foreach (Api_trade_info.bizOrderSplit item in bizOrderSplit)
  1727. {
  1728. bool create = false;
  1729. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(item.splitNo);
  1730. if (entity == null)
  1731. {
  1732. entity = new CeErpTradeCell();
  1733. create = true;
  1734. entity.tid = trade.tid;
  1735. entity.pay_time = trade.pay_time;
  1736. }
  1737. if (entity.OrderState > 4)
  1738. {
  1739. continue;
  1740. }
  1741. entity.ctid = item.splitNo;
  1742. entity.seller_memo = item.systemRemark;
  1743. if (!string.IsNullOrEmpty(item.splitAmount))
  1744. {
  1745. entity.payment = Convert.ToDouble(item.splitAmount);
  1746. }
  1747. if (!string.IsNullOrEmpty(item.splitAmount))
  1748. {
  1749. entity.AfterSalePayment = Convert.ToDouble(item.splitAmount);
  1750. }
  1751. if (!string.IsNullOrEmpty(item.sfMark))
  1752. {
  1753. entity.IsSF = Convert.ToInt32(item.sfMark);
  1754. }
  1755. entity.ProductSize = item.size;
  1756. entity.Material = item.material;
  1757. entity.CustomerUserId = item.erpCustomerServiceId;
  1758. //entity.Craft = item.craftText;
  1759. entity.ProductCount = item.productQuantity;
  1760. entity.ProductId = tmcHelper.getProductIdByName(item.cate3Id);
  1761. if (!string.IsNullOrEmpty(item.internalStatus))
  1762. {
  1763. entity.OrderState = Convert.ToInt32(item.internalStatus);
  1764. }
  1765. entity.IsUrgency = item.isUrgent;
  1766. entity.ptid = item.ptid;
  1767. entity.SplitTag = item.splitInfoNo;
  1768. entity.UpdateTime = DateTime.Now;
  1769. if (!string.IsNullOrEmpty(item.paymentFile))
  1770. {
  1771. entity.PayProofImg = item.paymentFile;
  1772. }
  1773. if (item.shippingTime != null && item.shippingTime.Length > 0)
  1774. {
  1775. entity.UnusualTime = Convert.ToDateTime(item.shippingTime);
  1776. entity.UrgencyTime = Convert.ToDateTime(item.shippingTime);
  1777. }
  1778. if (!string.IsNullOrEmpty(item.sendGiftMark))
  1779. {
  1780. entity.IsSendGift = Convert.ToInt32(item.sendGiftMark);
  1781. }
  1782. entity.OtherMemo = item.otherRemark;
  1783. entity.IsOldCustomer = item.isRepurchase ? 1 : 0;
  1784. entity.IsOldCustomerMore = item.isOldCustomerMore;
  1785. entity.MemoOpt = item.memoOpt;
  1786. entity.isDianziOrder = item.isDianziOrder;
  1787. if (item.isPreShipping != null && item.isPreShipping.Length > 0)
  1788. {
  1789. entity.IsPreDelivery = Convert.ToInt32(item.isPreShipping);
  1790. }
  1791. if (item.checkOrderTime != null && item.checkOrderTime.Length > 0)
  1792. {
  1793. entity.CheckOrderTime = Convert.ToDateTime(item.checkOrderTime);
  1794. }
  1795. int shopId = 0;
  1796. if (nShop != null)
  1797. {
  1798. shopId = nShop.ID;
  1799. }
  1800. entity.ShopId = shopId;
  1801. entity.OrderSn = item.OrderSn;
  1802. entity.ParentSplitNo = item.parentSplitNo;
  1803. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1804. string sql_pay = "";
  1805. if (ceErpTradeCellExtend == null)
  1806. {
  1807. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  1808. ceErpTradeCellExtend.ctid = entity.ctid;
  1809. }
  1810. ceErpTradeCellExtend.cate1 = item.cate1;
  1811. ceErpTradeCellExtend.cate2 = item.cate2;
  1812. ceErpTradeCellExtend.scene = item.scene;
  1813. ceErpTradeCellExtend.material = item.material;
  1814. ceErpTradeCellExtend.offerAmount = item.offerAmount;
  1815. ceErpTradeCellExtend.numbers = item.numbers;
  1816. ceErpTradeCellExtend.typeScene = item.typeScene;
  1817. ceErpTradeCellExtend.opScene = item.opScene;
  1818. ceErpTradeCellExtend.craft = item.craft;
  1819. ceErpTradeCellExtend.numberType = item.numberType;
  1820. ceErpTradeCellExtend.cate1Id = item.cate1Id;
  1821. ceErpTradeCellExtend.cate2Id = item.cate2Id;
  1822. ceErpTradeCellExtend.cate3Id = item.cate3Id;
  1823. ceErpTradeCellExtend.sceneId = item.sceneId;
  1824. ceErpTradeCellExtend.typeSceneId = item.typeSceneId;
  1825. ceErpTradeCellExtend.opSceneId = item.opSceneId;
  1826. ceErpTradeCellExtend.materialId = item.materialId;
  1827. ceErpTradeCellExtend.width = item.width;
  1828. ceErpTradeCellExtend.height = item.height;
  1829. ceErpTradeCellExtend.length = item.length;
  1830. ceErpTradeCellExtend.recSize = item.recSize;
  1831. ceErpTradeCellExtend.sizeUnit = item.sizeUnit;
  1832. ceErpTradeCellExtend.numberUnit = item.numberUnit;
  1833. ceErpTradeCellExtend.orderFrom = 30;
  1834. ceErpTradeCellExtend.spu_id = item.spuId;
  1835. ceErpTradeCellExtend.quantity = item.quantity;
  1836. ceErpTradeCellExtend.discountAmount = item.discountAmount;
  1837. ceErpTradeCellExtend.differentAmount = item.compensateAmount;
  1838. ceErpTradeCellExtend.differentSplitNo = item.compensateSplitOrderUniqueNo;
  1839. ceErpTradeCellExtend.orderType = item.orderType;
  1840. ceErpTradeCellExtend.parentOrderSn = item.parentSplitNo;
  1841. if (ceErpTradeCellExtend.ID > 0)
  1842. {
  1843. ceErpTradeCellExtend.Update();
  1844. }
  1845. else
  1846. {
  1847. ceErpTradeCellExtend.Create();
  1848. }
  1849. if (!string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id))
  1850. {
  1851. ceErpTradeCellExtend = commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  1852. }
  1853. if (item.isGift == 1)
  1854. {
  1855. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  1856. entity.IsXianHuo = 1;
  1857. entity.IsGift = 1;
  1858. entity.FinishPlaceTime = trade.pay_time;
  1859. if (entity.OrderState < 6)
  1860. {
  1861. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1862. }
  1863. }
  1864. if (item.isSpot)
  1865. {
  1866. if (entity.OrderState < 6)
  1867. {
  1868. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1869. }
  1870. entity.seller_memo = item.systemRemark;
  1871. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1872. entity.IsXianHuo = 1;
  1873. entity.FinishPlaceTime = entity.pay_time;
  1874. if (item.systemRemark.IndexOf("封酒贴") != -1)
  1875. {
  1876. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  1877. if (trade.buyer_memo != "")
  1878. {
  1879. entity.OrderState = 2;
  1880. entity.ProductId = 1;
  1881. entity.IsXianHuo = 0;
  1882. item.systemRemark = item.systemRemark.Replace("现货", "");
  1883. item.systemRemark = item.systemRemark.Replace(" ", "");
  1884. entity.seller_memo = item.systemRemark;
  1885. if (entity.ShopId != 0)
  1886. {
  1887. entity.OrderState = orderAudit(entity.ShopId);
  1888. }
  1889. }
  1890. }
  1891. else if (item.systemRemark.IndexOf("#") != -1)
  1892. {
  1893. entity.SupplierId = 87;
  1894. }
  1895. else if (item.systemRemark.IndexOf("喜字贴") != -1)
  1896. {
  1897. entity.SupplierId = 70;
  1898. }
  1899. else if (item.systemRemark.IndexOf("兔团团") != -1)
  1900. {
  1901. entity.SupplierId = 101;
  1902. }
  1903. else if (item.systemRemark.IndexOf("手拉旗") != -1)
  1904. {
  1905. entity.SupplierId = 108;
  1906. }
  1907. try
  1908. {
  1909. string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
  1910. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  1911. List<Dictionary<string, string>> material_list = new List<Dictionary<string, string>>();
  1912. List<Dictionary<string, string>> name_list = new List<Dictionary<string, string>>();
  1913. foreach (DataRow dr in goodsDt.Rows)
  1914. {
  1915. string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
  1916. List<string> xianhuo = sqlMemo.Split(',').ToList();
  1917. foreach (var val in xianhuo)
  1918. {
  1919. if (string.IsNullOrEmpty(val)) continue;
  1920. Dictionary<string, string> material_map = new Dictionary<string, string>();//材质
  1921. Dictionary<string, string> name_map = new Dictionary<string, string>();//特殊名称
  1922. if (val.IndexOf('-') > -1)
  1923. {
  1924. List<string> list = val.Split('-').ToList();
  1925. material_map.Add(dr["id"].ToString(), list[0]);
  1926. name_map.Add(dr["id"].ToString(), list[1]);
  1927. }
  1928. else
  1929. {
  1930. material_map.Add(dr["id"].ToString(), val);
  1931. }
  1932. material_list.Add(material_map);
  1933. name_list.Add(name_map);
  1934. }
  1935. }
  1936. List<string> materials = new List<string>();
  1937. List<string> names = new List<string>();
  1938. List<string> result = new List<string>();
  1939. for (int i = 0; i < material_list.Count; i++)
  1940. {
  1941. Dictionary<string, string> map = material_list[i];
  1942. foreach (var val in map)
  1943. {
  1944. if (item.systemRemark.IndexOf(val.Value) > -1)
  1945. {
  1946. Dictionary<string, string> map2 = name_list[i];
  1947. if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
  1948. {
  1949. foreach (var item1 in map2)
  1950. {
  1951. if (item.systemRemark.IndexOf(item1.Value) > -1)
  1952. {
  1953. names.Add(item1.Key);
  1954. materials.Add(val.Key);
  1955. }
  1956. }
  1957. }
  1958. else
  1959. {
  1960. materials.Add(val.Key);
  1961. }
  1962. }
  1963. }
  1964. }
  1965. if (names.Count > 0)//特殊名称有只先在特殊名称里选择
  1966. {
  1967. result = names.Distinct().ToList();
  1968. }
  1969. else
  1970. {
  1971. result = materials.Distinct().ToList();
  1972. }
  1973. if (result.Count > 0)
  1974. {
  1975. Random rnd = new Random();
  1976. int index = rnd.Next(result.Count);
  1977. entity.SupplierId = int.Parse(result[index]);
  1978. }
  1979. }
  1980. catch (Exception e)
  1981. {
  1982. XLog.SaveLog(0, "|现货匹配|" + e.Message);
  1983. }
  1984. }
  1985. if (isCreate)
  1986. {
  1987. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  1988. if (oldRes > 0)
  1989. {
  1990. //entity.IsOldCustomer = 1;
  1991. //if (oldRes == 2) entity.IsOldCustomerMore = 1;
  1992. }
  1993. }
  1994. if (item.sampleMark == "1")
  1995. {
  1996. entity.IsSample = 1;
  1997. entity.OrderState = 6;
  1998. entity.FinishPlaceTime = DateTime.Now;
  1999. entity.IsOldCustomer = 0;
  2000. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2001. }
  2002. if (item.sampleMark == "3")
  2003. {
  2004. entity.IsSample = 3;
  2005. entity.OrderState = 6;
  2006. entity.FinishPlaceTime = DateTime.Now;
  2007. entity.IsOldCustomer = 0;
  2008. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2009. }
  2010. if (item.sampleMark == "2" && !string.IsNullOrEmpty(item.parentSplitNo))
  2011. {
  2012. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(item.parentSplitNo);
  2013. if (ceErpTradeCell != null)
  2014. {
  2015. entity.CustomerUserId = ceErpTradeCell.CustomerUserId;
  2016. entity.DesignUserId = ceErpTradeCell.DesignUserId;
  2017. entity.SupplierId = ceErpTradeCell.SupplierId;
  2018. entity.IsSample = 2;
  2019. entity.WaitDesignTime = ceErpTradeCell.WaitDesignTime;
  2020. entity.StartDesignTime = ceErpTradeCell.StartDesignTime;
  2021. entity.FinishDesignTime = ceErpTradeCell.FinishDesignTime;
  2022. entity.FinishPlaceTime = ceErpTradeCell.FinishPlaceTime;
  2023. }
  2024. CeErpTradeCellExtend parentCell = CeErpTradeCellExtend.getByTid(item.parentSplitNo);
  2025. if (parentCell == null)
  2026. {
  2027. parentCell = new CeErpTradeCellExtend();
  2028. parentCell.ctid = item.parentSplitNo;
  2029. }
  2030. if (!string.IsNullOrEmpty(item.splitAmount))
  2031. {
  2032. parentCell.differentAmount += Convert.ToDouble(item.splitAmount);
  2033. }
  2034. if (parentCell.ID > 0)
  2035. {
  2036. parentCell.Update();
  2037. }
  2038. else
  2039. {
  2040. parentCell.Create();
  2041. }
  2042. ApiVo apiVo = new ApiVo();
  2043. apiVo.orderNumber = entity.ptid;
  2044. apiVo.payment = entity.payment;
  2045. apiVo.actionName = "repairDesign";
  2046. designHelper.API_WorkCore(apiVo);//repairDesign
  2047. }
  2048. bool isCopyFile = false;
  2049. //老客户
  2050. if (item.isRepurchase)
  2051. {
  2052. if (item.isOldCustomer == 1)
  2053. {
  2054. tmcHelper.dealOldCustomerEntityTag(ref entity, trade);
  2055. }
  2056. if (item.isOldCustomer == 3)
  2057. {
  2058. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  2059. entity.WaitDesignTime = DateTime.Now;
  2060. isCopyFile = true;
  2061. }
  2062. if (item.isOldCustomer == 2)
  2063. {
  2064. entity.OrderState = 3;
  2065. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  2066. entity.WaitDesignTime = DateTime.Now;
  2067. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  2068. }
  2069. }
  2070. if (create)
  2071. {
  2072. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "创建推送生成:" + entity.seller_memo, entity.OrderState);
  2073. entity.Create();
  2074. }
  2075. else
  2076. {
  2077. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "更新推送生成:" + entity.seller_memo, entity.OrderState);
  2078. designHelper.API_update_renewOrder(entity);
  2079. entity.Update();
  2080. }
  2081. if (!string.IsNullOrEmpty(sql_pay))
  2082. {
  2083. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2084. }
  2085. if (isCopyFile)
  2086. {
  2087. apiUploaderResponse upResult = CopyDesignFile(entity.ctid, item.oldOrderSn, entity.CustomerUserId);
  2088. if (upResult == null || "error".Equals(upResult.type))
  2089. {
  2090. tempResponse response = new tempResponse();
  2091. response.flag = "1";
  2092. response.flagData = entity.ctid;
  2093. response.flagMsg = upResult == null ? "复制文件出错!" : upResult.result;
  2094. tempResponses.Add(response);
  2095. }
  2096. }
  2097. }
  2098. return tempResponses;
  2099. }
  2100. public static void createItemOrder(List<Api_trade_info.TradeItemOrder> orderList, CeErpTrade trade)
  2101. {
  2102. foreach (Api_trade_info.TradeItemOrder item in orderList)
  2103. {
  2104. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.thirdOrderItemId);
  2105. bool isCreateOrder = false;
  2106. if (order == null)
  2107. {
  2108. order = new CeErpTradeOrder();
  2109. isCreateOrder = true;
  2110. order.oid = item.thirdOrderItemId;
  2111. order.tid = trade.tid;
  2112. order.buyer_nick = trade.buyer_nick;
  2113. }
  2114. order.refund_status = item.refundStatus;
  2115. order.status = trade.status;
  2116. order.title = item.title;
  2117. if (!string.IsNullOrEmpty(item.price))
  2118. {
  2119. order.price = Convert.ToDouble(item.price);
  2120. }
  2121. if (item.picUrl != null)
  2122. {
  2123. order.pic_path = item.picUrl;
  2124. }
  2125. if (!string.IsNullOrEmpty(item.num))
  2126. {
  2127. order.num = Convert.ToDouble(item.num);
  2128. }
  2129. if (!string.IsNullOrEmpty(item.totalAmount))
  2130. {
  2131. order.payment = Convert.ToDouble(item.totalAmount);
  2132. }
  2133. if (!string.IsNullOrEmpty(item.totalSellPrice))
  2134. {
  2135. order.total_fee = Convert.ToDouble(item.totalSellPrice);
  2136. }
  2137. //order.adjust_fee = Convert.ToDouble(item.price);
  2138. if (item.thirdSkuId != null && item.thirdSkuId != "")
  2139. {
  2140. order.sku_id = item.thirdSkuId;
  2141. }
  2142. if (item.specification != null && item.specification != "")
  2143. {
  2144. order.sku_properties_name = item.specification;
  2145. }
  2146. if (item.thirdSpuId != null && item.thirdSpuId != "")
  2147. {
  2148. order.spu_id = item.thirdSpuId;
  2149. }
  2150. if (isCreateOrder)
  2151. {
  2152. order.Create();
  2153. }
  2154. else
  2155. {
  2156. order.Update();
  2157. }
  2158. }
  2159. }
  2160. public static CeErpTrade createTradeOrder(BizOrder bizOrder, CeErpTrade trade, bool isCreate)
  2161. {
  2162. if (trade == null)
  2163. { //新生成订单的
  2164. isCreate = true;
  2165. trade = new CeErpTrade();
  2166. trade.tid = bizOrder.thirdOrderId;
  2167. trade.type = bizOrder.orderPlatform;
  2168. trade.receiverId = bizOrder.receiverId;
  2169. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  2170. {
  2171. trade.price = Convert.ToDouble(bizOrder.payAmount);
  2172. }
  2173. trade.discount_fee = 0;
  2174. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  2175. {
  2176. trade.total_fee = Convert.ToDouble(bizOrder.payAmount);
  2177. }
  2178. if (bizOrder.orderTime != null && bizOrder.orderTime.Length > 0)
  2179. {
  2180. trade.created = Convert.ToDateTime(bizOrder.orderTime);
  2181. }
  2182. if (bizOrder.payTime != null && bizOrder.payTime.Length > 0)
  2183. {
  2184. trade.pay_time = Convert.ToDateTime(bizOrder.payTime);
  2185. }
  2186. trade.seller_nick = GetNull_tostring(bizOrder.openSellerNick);
  2187. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  2188. {
  2189. trade.payment = Convert.ToDouble(bizOrder.payAmount);
  2190. }
  2191. }
  2192. trade.buyer_nick = GetNull_tostring(bizOrder.openBuyerNick);
  2193. trade.receiver_state = bizOrder.province;
  2194. if (!string.IsNullOrEmpty(bizOrder.num))
  2195. {
  2196. trade.num = Convert.ToDouble(bizOrder.num);
  2197. }
  2198. trade.receiver_city = bizOrder.city;
  2199. trade.receiver_address = GetNoNullValue_string(bizOrder.address);
  2200. trade.receiver_town = GetNoNullValue_string(bizOrder.receiverTown);
  2201. trade.receiver_district = GetNoNullValue_string(bizOrder.area);
  2202. trade.seller_flag = bizOrder.thirdFlag;
  2203. trade.orderType = bizOrder.orderType;
  2204. trade.orderFrom = 30;
  2205. trade.unrefundedAmount = bizOrder.unrefundedAmount;
  2206. if (bizOrder.modifyTime != null && bizOrder.modifyTime.Length > 0)
  2207. {
  2208. trade.modified = Convert.ToDateTime(bizOrder.modifyTime);
  2209. }
  2210. if (bizOrder.finishTime != null && bizOrder.finishTime.Length > 0)
  2211. {
  2212. trade.end_time = Convert.ToDateTime(bizOrder.finishTime);
  2213. }
  2214. if (bizOrder.shippingTime != null && bizOrder.shippingTime.Length > 0)
  2215. {
  2216. trade.delivery_time = Convert.ToDateTime(bizOrder.shippingTime);
  2217. }
  2218. if (bizOrder.confirmTime != null && bizOrder.confirmTime.Length > 0)
  2219. {
  2220. trade.confirmTime = Convert.ToDateTime(bizOrder.confirmTime);
  2221. }
  2222. trade.buyer_memo = GetNoNullValue_string(bizOrder.buyerRemark);
  2223. bool isSellerMemoChange = false;
  2224. //备注修改
  2225. bizOrder.sellerRemark = GetNoNullValue_string(bizOrder.sellerRemark);
  2226. if (trade.seller_memo != bizOrder.sellerRemark || trade.seller_memo.Length != bizOrder.sellerRemark.Length)
  2227. {
  2228. isSellerMemoChange = true;
  2229. }
  2230. trade.status = bizOrder.status;
  2231. trade.seller_memo = bizOrder.sellerRemark;
  2232. trade.buyer_id = bizOrder.openBuyerId;
  2233. trade.posCode = bizOrder.shopCode;
  2234. if (isCreate)
  2235. {
  2236. trade.IsNew = bizOrder.IsNew;
  2237. trade.Create();
  2238. }
  2239. else
  2240. {
  2241. if (bizOrder.status == "CLOSE")
  2242. {
  2243. trade.consign_time = DateTime.Now;
  2244. }
  2245. trade.Update();
  2246. }
  2247. CeErpTradeCell.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set UpdateTime = getdate() where tid = '{0}'", trade.tid));
  2248. try
  2249. {
  2250. if (bizOrder.status == "CLOSE" || bizOrder.status == "CANCEL")
  2251. {
  2252. StringBuilder sql = new StringBuilder();
  2253. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, bizOrder.thirdOrderId);
  2254. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  2255. ApiVo apiVo = new ApiVo();
  2256. apiVo.actionName = "closeDesign";
  2257. apiVo.orderNumber = bizOrder.thirdOrderId;
  2258. //designHelper.API_WorkCore(apiVo);//closeDesign
  2259. LogHelper.addLog(bizOrder.thirdOrderId, 0, "交易关闭", (int)OrderState.交易关闭);
  2260. // commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
  2261. // removeOldCustomerInfo(trade);
  2262. }
  2263. else if (bizOrder.status == "COMPLETE")
  2264. {
  2265. StringBuilder sql = new StringBuilder();
  2266. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, bizOrder.thirdOrderId);
  2267. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  2268. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
  2269. }
  2270. else if (bizOrder.status == "SHIPPED")//已发货
  2271. {
  2272. StringBuilder sql = new StringBuilder();
  2273. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, bizOrder.thirdOrderId);
  2274. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  2275. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
  2276. }
  2277. }
  2278. catch (Exception ex)
  2279. {
  2280. XLog.SaveLog(0, bizOrder.thirdOrderId + "shipped:" + ex.Message);
  2281. throw ex;
  2282. }
  2283. return trade;
  2284. }
  2285. public void checkOrderToWh()
  2286. {
  2287. string orderNumber = GetPostString("orderNumber");
  2288. string spuId = GetPostString("spuId");
  2289. string seller_memo = GetPostString("seller_memo");
  2290. string otherMemo = GetPostString("otherMemo");
  2291. string shopName = GetPostString("shopName");
  2292. string productId = GetPostString("productId");
  2293. CeErpProduct ceErpProduct = CeErpProduct.GetByName(productId);
  2294. CeErpShop ceErpShop = CeErpShop.GetShopIdByName(shopName);
  2295. if (ceErpProduct == null || ceErpShop == null)
  2296. {
  2297. returnErrorMsg("商品id或者店铺id不全");
  2298. return;
  2299. }
  2300. int isDianziOrder = GetPostInt("isDianziOrder");
  2301. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2302. CeErpTradeCellExtend ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2303. ceErpTradeCell.ctid = orderNumber;
  2304. ceErpTradeCell.seller_memo = seller_memo;
  2305. ceErpTradeCell.OtherMemo = otherMemo;
  2306. ceErpTradeCell.ShopId = ceErpShop.ID;
  2307. ceErpTradeCell.ProductId = ceErpProduct.ID;
  2308. ceErpTradeCell.isDianziOrder = isDianziOrder;
  2309. ceErpTradeCellExtend.spu_id = spuId;
  2310. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  2311. returnSuccess("\"" + ceErpTradeCellExtend.ToType + "\"");
  2312. return;
  2313. }
  2314. public static apiUploaderResponse CopyDesignFile(string ctid, string oldCtid, int userId)
  2315. {
  2316. string post_url = "http://183.250.143.56:8088/autocopy.aspx";
  2317. WebClient wc = new WebClient();
  2318. wc.Encoding = Encoding.GetEncoding("utf-8");
  2319. //json参数
  2320. NameValueCollection PostVars = new NameValueCollection();
  2321. PostVars.Add("hexdata", oldCtid + "," + ctid);
  2322. PostVars.Add("userid", userId.ToString());
  2323. apiUploaderResponse result = null;
  2324. try
  2325. {
  2326. byte[] ret = wc.UploadValues(post_url, "POST", PostVars);
  2327. string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret);
  2328. result = JsonConvert.DeserializeObject<apiUploaderResponse>(remoteInfo);
  2329. }
  2330. catch (Exception ex)
  2331. {
  2332. XLog.SaveLog(0, "CopyDesignFile:" + ex.Message);
  2333. }
  2334. return result;
  2335. }
  2336. public static DateTime StampToDateTime(string timeStamp)
  2337. {
  2338. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  2339. long lTime = long.Parse(timeStamp + "0000");
  2340. TimeSpan toNow = new TimeSpan(lTime);
  2341. return dateTimeStart.Add(toNow);
  2342. }
  2343. public static string GetNull_tostring(object value)
  2344. {
  2345. if (value == null)
  2346. {
  2347. return "";
  2348. }
  2349. return value.ToString();
  2350. }
  2351. public static string GetNoNullValue_string(string value)
  2352. {
  2353. if (value == null)
  2354. {
  2355. return "";
  2356. }
  2357. value = value.Replace("\n", " ");
  2358. value = value.Replace("\r", " ");
  2359. return value;
  2360. }
  2361. public static string getShopNameByECode(string code)
  2362. {
  2363. string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
  2364. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  2365. if (dt != null && dt.Rows.Count > 0)
  2366. {
  2367. return dt.Rows[0]["ShopName"].ToString();
  2368. }
  2369. return "";
  2370. }
  2371. public static int orderAudit(int shopId)
  2372. {
  2373. try
  2374. {
  2375. CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
  2376. if (ceErpShop == null) return 2;
  2377. if (!ceErpShop.orderAudit) return 2;
  2378. return -1;
  2379. }
  2380. catch (Exception ex)
  2381. {
  2382. return 2;
  2383. }
  2384. }
  2385. public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
  2386. {
  2387. if (father.seller_nick == "") return 0;
  2388. CeErpCustomer cus = null;
  2389. cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
  2390. if (cus == null)
  2391. {
  2392. cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
  2393. }
  2394. int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
  2395. if (cus != null)
  2396. {
  2397. if (cus.lastbuy_time.ToString() == "") return 0;
  2398. if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
  2399. cus.buyer_id = father.buyer_id;
  2400. if (cus.lastTid == father.tid)
  2401. {
  2402. if (pcount != cus.product_count)
  2403. {
  2404. cus.product_count = pcount;
  2405. cus.Update();
  2406. }
  2407. }
  2408. else
  2409. {
  2410. int returnNum = 0;
  2411. TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
  2412. cus.buy_day = Convert.ToInt32(tsday.TotalDays);
  2413. cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
  2414. cus.buy_count = cus.buy_count + 1;
  2415. cus.lastbuy_time2 = cus.lastbuy_time;
  2416. cus.buyer_id = father.buyer_id;
  2417. cus.lastbuy_time = father.pay_time;
  2418. int lastpCount = cus.product_count;
  2419. cus.product_count = pcount;
  2420. cus.lastTid2 = cus.lastTid;
  2421. cus.lastTid = father.tid;
  2422. if (cus.buy_day > 1)
  2423. {
  2424. if (pcount > lastpCount && cus.product_count != 0)
  2425. {
  2426. cus.isMore = 1;
  2427. returnNum = 2;
  2428. }
  2429. else
  2430. returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
  2431. }
  2432. else
  2433. returnNum = 0;
  2434. cus.Update();
  2435. return returnNum;
  2436. }
  2437. }
  2438. else
  2439. {
  2440. try
  2441. {
  2442. cus = new CeErpCustomer();
  2443. cus.buyer_nick = father.buyer_nick;
  2444. cus.seller_nick = father.seller_nick;
  2445. cus.buyer_id = father.buyer_id;
  2446. cus.buy_day = 0;
  2447. cus.buy_count = 1;
  2448. cus.lastbuy_time = father.pay_time;
  2449. cus.lastTid = father.tid;
  2450. cus.total_fee = Convert.ToDouble(father.payment);
  2451. cus.product_count = pcount;
  2452. cus.Create();
  2453. return 0;
  2454. }
  2455. catch (Exception ex)
  2456. {
  2457. XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
  2458. }
  2459. }
  2460. return 0;
  2461. }
  2462. }
  2463. }