preSalesHelper.cs 106 KB

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