preSalesHelper.cs 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649
  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. string ctid = GetPostString("ctid");
  739. string systemRemark = GetPostString("systemRemark");
  740. if (!string.IsNullOrEmpty(tid))
  741. {
  742. if (string.IsNullOrEmpty(atta))
  743. {
  744. returnErrorMsg("文件地址为空");
  745. return;
  746. }
  747. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  748. if (ceErpTrade == null)
  749. {
  750. returnErrorMsg("找不到订单");
  751. return;
  752. }
  753. CeErpTradeCell ceErpTradeCell = null;
  754. if (!string.IsNullOrEmpty(ctid))
  755. {
  756. ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  757. if (ceErpTradeCell == null)
  758. {
  759. returnErrorMsg("找不到订单");
  760. return;
  761. }
  762. if (ceErpTradeCell.OrderState > 5)
  763. {
  764. returnErrorMsg("订单状态不正确");
  765. return;
  766. }
  767. }
  768. if (ceErpTradeCell != null && !string.IsNullOrEmpty(systemRemark))
  769. {
  770. ceErpTradeCell.seller_memo = systemRemark;
  771. LogHelper.addLog(tid, UserID, "上传文件地址修改备注:" + systemRemark, 6);
  772. ceErpTradeCell.Update();
  773. }
  774. ceErpTrade.Attachments = "https://dfdiyfile.oss-cn-fuzhou.aliyuncs.com/" + atta;
  775. ceErpTrade.Update();
  776. LogHelper.addLog(tid, UserID, "上传文件地址:" + ceErpTrade.Attachments, 6);
  777. returnSuccessMsg("上传成功!");
  778. return;
  779. }
  780. returnErrorMsg("找不到订单");
  781. }
  782. /**
  783. * 顺丰到付\顺丰寄付
  784. * ctid
  785. * memotag 顺丰到付、顺丰寄付、撤销顺丰
  786. * name
  787. **/
  788. public void upd_addmemotag()
  789. {
  790. if (UrlPostParmsCheck("ctid"))
  791. {
  792. int UserID = GetPostInt("UserID");
  793. string eid = GetPostString("ctid");
  794. string sfTagstr = GetPostString("memotag");
  795. string name = GetPostString("name");
  796. CeErpTradeCell entity = null;
  797. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  798. if (entity != null)
  799. {
  800. if (entity.OrderState == 0)
  801. {
  802. returnErrorMsg("请先领单");
  803. return;
  804. }
  805. //撤销顺丰
  806. if (sfTagstr == "撤销顺丰")
  807. {
  808. entity.IsSF = 0;
  809. string reMsg = "";
  810. string oldmemo = entity.seller_memo;
  811. if (entity.OrderState < 5)
  812. {
  813. oldmemo = oldmemo.Replace("顺丰到付", "");
  814. oldmemo = oldmemo.Replace("顺丰寄付", "");
  815. entity.seller_memo = oldmemo;
  816. }
  817. else
  818. {
  819. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  820. {
  821. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  822. }
  823. }
  824. entity.Update();
  825. LogHelper.addLog(entity.ctid, UserID, name + "撤销标记顺丰", entity.OrderState, 1);
  826. returnSuccessMsg("撤销成功!" + reMsg);
  827. return;
  828. }
  829. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  830. {
  831. //string oldmemo = entity.seller_memo;
  832. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  833. string sfStr = GetPostString("memotag");
  834. string smemo = entity.seller_memo;
  835. int kindex = smemo.IndexOf(")");
  836. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  837. if (lastoneStr != "-")
  838. {
  839. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  840. }
  841. string prememo = smemo.Substring(0, kindex + 2);
  842. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  843. int lastkindex = lastmemo.IndexOf("(");
  844. string newlastmemo = "";
  845. if (lastkindex == 0)
  846. {
  847. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  848. newlastmemo = "(" + sfStr + "." + useLastmemo;
  849. }
  850. else
  851. {
  852. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  853. }
  854. entity.seller_memo = prememo + newlastmemo;
  855. }
  856. string sfTagMSg = "";
  857. if (sfTagstr == "顺丰寄付")
  858. {
  859. entity.IsSF = 1;
  860. sfTagMSg = "顺丰寄付";
  861. }
  862. else if (sfTagstr == "顺丰到付")
  863. {
  864. entity.IsSF = 2;
  865. sfTagMSg = "顺丰到付";
  866. }
  867. ApiVo apiVo = new ApiVo();
  868. apiVo.orderNumber = entity.ctid;
  869. apiVo.actionName = "orderRemarks";
  870. apiVo.orderRemarks = entity.seller_memo;
  871. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  872. entity.UpdateTime = DateTime.Now;
  873. entity.Update();
  874. LogHelper.addLog(entity.ctid, UserID, name + ":" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  875. returnSuccessMsg("标记成功!");
  876. return;
  877. }
  878. returnErrorMsg("找不到记录");
  879. return;
  880. }
  881. returnErrorMsg("缺少必要的参数ctid");
  882. }
  883. /**
  884. * 微信单
  885. * ctid
  886. * wechattag 1:微信返现 2:推购返现 3:挽回推多 4 :推多 5:推购
  887. * name
  888. **/
  889. public void upd_ordertag()
  890. {
  891. if (UrlPostParmsCheck("ctid"))
  892. {
  893. string name = GetPostString("name");
  894. string eid = GetPostString("ctid");
  895. int UserID = GetPostInt("UserID");
  896. CeErpTradeCell entity = null;
  897. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  898. if (entity != null)
  899. {
  900. int tag = GetPostInt("wechattag");
  901. //if(tag==4 && entity.IsSample == 2)
  902. //{
  903. // returnErrorMsg("补差价单不能标记微信单");
  904. // return;
  905. //}
  906. entity.wechatTag = tag;
  907. entity.Update();
  908. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  909. if (tag == 1)
  910. {
  911. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  912. if (cash == null)
  913. {
  914. CeErpTrade main = CeErpTrade.Get(entity.tid);
  915. cash = new CeErpReturnCash();
  916. cash.tid = entity.tid;
  917. cash.seller_nick = main.seller_nick;
  918. cash.payment = trade.payment;
  919. cash.buyer_nick = main.buyer_nick;
  920. cash.cashstate = 0;
  921. cash.rtype = "微信返现";
  922. cash.returnprice = 0;
  923. cash.created = DateTime.Now;
  924. cash.con = "订单标记微信单";
  925. cash.img = "";
  926. cash.applyuserid = UserID;
  927. cash.Create();
  928. LogHelper.addLog(entity.ctid, UserID, name + "添加:微信返现");
  929. }
  930. else
  931. {
  932. cash.cashstate = 0;
  933. cash.Update();
  934. }
  935. }
  936. else if (tag == 2)
  937. {
  938. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  939. if (cash == null)
  940. {
  941. CeErpTrade main = CeErpTrade.Get(entity.tid);
  942. cash = new CeErpReturnCash();
  943. cash.tid = entity.tid;
  944. cash.seller_nick = main.seller_nick;
  945. cash.payment = trade.payment;
  946. cash.buyer_nick = main.buyer_nick;
  947. cash.cashstate = 0;
  948. cash.rtype = "推购返现";
  949. cash.returnprice = 5;
  950. cash.created = DateTime.Now;
  951. cash.con = "订单标记推购单";
  952. cash.img = "";
  953. cash.applyuserid = UserID;
  954. cash.Create();
  955. LogHelper.addLog(entity.ctid, UserID, name + "添加:推购返现");
  956. }
  957. else
  958. {
  959. cash.cashstate = 0;
  960. cash.Update();
  961. }
  962. }
  963. else if (tag == 3)
  964. {
  965. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  966. if (pers == null)
  967. {
  968. pers = new CeErpPersuade();
  969. pers.ctid = entity.ctid;
  970. pers.pstate = 0;
  971. pers.created = DateTime.Now;
  972. pers.applyuserid = UserID;
  973. pers.Create();
  974. LogHelper.addLog(entity.ctid, UserID, name + "添加:挽回推多");
  975. }
  976. else
  977. {
  978. pers.pstate = 0;
  979. pers.Update();
  980. }
  981. }
  982. else if (tag == 4 || tag == 5)
  983. {
  984. CeErpTrade main = CeErpTrade.Get(entity.tid);
  985. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  986. if (pers == null)
  987. {
  988. pers = new CeErpStayGoods();
  989. pers.t_id = entity.tid;
  990. pers.status = "待审核";
  991. pers.audit_type = 0;
  992. if (tag == 4)
  993. {
  994. pers.stay_type = "微信推购";
  995. }
  996. else
  997. {
  998. pers.stay_type = "旺旺推购";
  999. }
  1000. if (entity.IsXianHuo == 0)
  1001. {
  1002. pers.product_id = entity.ProductId;
  1003. }
  1004. pers.wangwang = main.buyer_nick;
  1005. pers.shop_name = main.seller_nick;
  1006. pers.creata_time = DateTime.Now;
  1007. pers.create_u_id = UserID;
  1008. pers.create_u_name = name;
  1009. pers.Create();
  1010. LogHelper.addLog(entity.ctid, UserID, name + "添加:推多推购");
  1011. }
  1012. else
  1013. {
  1014. pers.audit_type = 0;
  1015. pers.Update();
  1016. }
  1017. }
  1018. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1019. returnSuccessMsg("标记成功!");
  1020. return;
  1021. }
  1022. returnErrorMsg("找不到记录");
  1023. return;
  1024. }
  1025. returnErrorMsg("缺少必要的参数ctid");
  1026. }
  1027. /**
  1028. * 小礼物
  1029. * ctid
  1030. * name
  1031. **/
  1032. public void upd_sendXlw()
  1033. {
  1034. if (UrlPostParmsCheck("ctid"))
  1035. {
  1036. string name = GetPostString("name");
  1037. string eid = GetPostString("ctid");
  1038. int UserID = GetPostInt("UserID");
  1039. CeErpTradeCell entity = null;
  1040. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1041. if (entity != null)
  1042. {
  1043. if (entity.IsSendGift == 1)
  1044. {
  1045. returnErrorMsg("请勿重复标记");
  1046. return;
  1047. }
  1048. entity.UpdateTime = DateTime.Now;
  1049. entity.IsSendGift = 1;
  1050. entity.Update();
  1051. LogHelper.addLog(eid, UserID, name + "送小礼物");
  1052. returnSuccessMsg("操作成功!");
  1053. return;
  1054. }
  1055. returnErrorMsg("找不到记录");
  1056. return;
  1057. }
  1058. returnErrorMsg("缺少必要的参数ctid");
  1059. }
  1060. /**
  1061. * 添加微信
  1062. * ctid
  1063. * name
  1064. **/
  1065. public void upd_addweichattag()
  1066. {
  1067. if (UrlPostParmsCheck("ctid"))
  1068. {
  1069. string name = GetPostString("name");
  1070. string eid = GetPostString("ctid");
  1071. int UserID = GetPostInt("UserID");
  1072. CeErpTradeCell entity = null;
  1073. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1074. if (entity != null)
  1075. {
  1076. if (entity.IsAddWechat > 0)
  1077. {
  1078. returnErrorMsg("此单已经标记过了");
  1079. return;
  1080. }
  1081. 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);
  1082. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1083. if (dt.Rows.Count > 0)
  1084. {
  1085. entity.IsAddWechat = 2;
  1086. }
  1087. else
  1088. {
  1089. entity.IsAddWechat = 1;
  1090. }
  1091. entity.UpdateTime = DateTime.Now;
  1092. entity.Update();
  1093. LogHelper.addLog(entity.ctid, UserID, name + "标记已添加微信", entity.OrderState, 1);
  1094. returnSuccessMsg("标记成功!");
  1095. return;
  1096. }
  1097. returnErrorMsg("找不到记录");
  1098. return;
  1099. }
  1100. returnErrorMsg("缺少必要的参数ctid");
  1101. }
  1102. /**
  1103. * 售后
  1104. *
  1105. * id 售后单id
  1106. * afterstate 1认可0不认可
  1107. * supmemo 理由
  1108. * image 图片
  1109. **/
  1110. public void upd_personaftersale()
  1111. {
  1112. if (UrlPostParmsCheck("id"))
  1113. {
  1114. string id = GetPostString("id");
  1115. int UserID = GetPostInt("UserID");
  1116. int st = GetPostInt("afterstate");
  1117. string afmemo = GetPostString("supmemo");
  1118. string image = GetPostString("image");
  1119. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  1120. if (ceErpTradeResponsible != null)
  1121. {
  1122. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  1123. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  1124. ceErpTradeResponsible.Update();
  1125. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  1126. if (entity != null)
  1127. {
  1128. entity.AfterSaleSupplierMemo = afmemo;
  1129. if (st == 1)
  1130. {
  1131. bool isAll = commonHelper.tradeResponsibleAll(entity);
  1132. if (isAll)
  1133. {
  1134. entity.AfterSaleState = 4;
  1135. entity.FinishAfterSaleTime = DateTime.Now;
  1136. if (entity.AfterSaleResSupId > 0)
  1137. {
  1138. entity.AfterSaleSupplierState = 1;
  1139. }
  1140. }
  1141. }
  1142. else
  1143. {
  1144. CeErpTradeResponsible.dateByTid(entity.ctid);
  1145. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  1146. if (ceErpTradeAfterSaleExtend != null)
  1147. {
  1148. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  1149. ceErpTradeAfterSaleExtend.Update();
  1150. }
  1151. else
  1152. {
  1153. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  1154. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  1155. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  1156. ceErpTradeAfterSaleExtend.Create();
  1157. }
  1158. //退回到主管
  1159. //entity.AfterSaleState = 2;
  1160. }
  1161. if (entity.AfterSaleState == 4)
  1162. {
  1163. ApiVo apiVo = new ApiVo();
  1164. apiVo.orderNumber = entity.ctid;
  1165. apiVo.actionName = "afterOver";
  1166. designHelper.API_WorkCore(apiVo); //afterOver
  1167. }
  1168. entity.UpdateTime = DateTime.Now;
  1169. entity.Update();
  1170. returnSuccessMsg("操作成功!");
  1171. LogHelper.addLog(entity.ctid, UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  1172. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), UserID, st == 1 ? 0 : 1, afmemo, image);
  1173. return;
  1174. }
  1175. }
  1176. returnErrorMsg("找不到订单记录");
  1177. return;
  1178. }
  1179. returnErrorMsg("缺少必要的参数id");
  1180. }
  1181. public void upd_erp_masteraftersale()
  1182. {
  1183. if (UrlPostParmsCheck("id"))
  1184. {
  1185. string id = GetPostString("id");
  1186. int st = GetPostInt("afterstate");
  1187. string afmemo = GetPostString("supmemo");
  1188. string image = GetPostString("image");
  1189. string textResult = GetPostString("textResult");
  1190. int UserID = GetPostInt("UserID");
  1191. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  1192. if (ceErpTradeResponsible != null)
  1193. {
  1194. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  1195. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  1196. ceErpTradeResponsible.Update();
  1197. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  1198. if (entity != null)
  1199. {
  1200. entity.AfterSaleSupplierState = st;
  1201. entity.AfterSaleSupplierMemo = afmemo;
  1202. if (st == 1)
  1203. {
  1204. }
  1205. else
  1206. {
  1207. CeErpTradeResponsible.dateByTid(entity.ctid);
  1208. //退回到售后
  1209. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  1210. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  1211. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  1212. if (num <= 1)
  1213. {
  1214. entity.AfterSaleState = 1;
  1215. }
  1216. else
  1217. {
  1218. entity.AfterSaleState = 5;
  1219. }
  1220. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  1221. if (ceErpTradeAfterSaleExtend != null)
  1222. {
  1223. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  1224. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  1225. ceErpTradeAfterSaleExtend.Update();
  1226. }
  1227. else
  1228. {
  1229. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  1230. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  1231. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  1232. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  1233. ceErpTradeAfterSaleExtend.Create();
  1234. }
  1235. }
  1236. entity.UpdateTime = DateTime.Now;
  1237. entity.Update();
  1238. returnSuccessMsg("操作成功!");
  1239. LogHelper.addLog(entity.ctid, UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  1240. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), UserID, st == 1 ? 0 : 1, afmemo, image);
  1241. return;
  1242. }
  1243. }
  1244. returnErrorMsg("找不到订单记录");
  1245. }
  1246. }
  1247. public void save_erp_billinfo()
  1248. {
  1249. if (UrlPostParmsCheck("ctid"))
  1250. {
  1251. string eid = GetPostString("ctid");
  1252. CeErpTradeCell entity = null;
  1253. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1254. if (entity != null)
  1255. {
  1256. CeErpBill bill = CeErpBill.GetByTid(eid);
  1257. bool isHave = false;
  1258. if (bill != null)
  1259. {
  1260. isHave = true;
  1261. if (bill.state != 4)
  1262. {
  1263. returnErrorMsg("此单已经申请过发票了");
  1264. return;
  1265. }
  1266. }
  1267. if (entity.IsNeedBill == 0)
  1268. {
  1269. entity.IsNeedBill = 1;
  1270. }
  1271. entity.Update();
  1272. string errjson = "";
  1273. try
  1274. {
  1275. CeErpBill bill_entity = new CeErpBill();
  1276. bill_entity.tid = entity.tid;
  1277. bill_entity.title = GetPostString("title");
  1278. string taxstr = GetPostString("tax");
  1279. taxstr = taxstr.Replace(" ", "");
  1280. bill_entity.tax = taxstr;
  1281. bill_entity.bank = GetPostString("bank");
  1282. string bankacstr = GetPostString("bankac");
  1283. bankacstr = bankacstr.Replace(" ", "");
  1284. bill_entity.bankac = bankacstr;
  1285. bill_entity.address = GetPostString("address");
  1286. bill_entity.phone = GetPostString("phone");
  1287. bill_entity.price = GetPostString("price");
  1288. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1289. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1290. {
  1291. billCount += 1;
  1292. }
  1293. string prebill = "ltb";
  1294. for (int idx = 1; idx <= billCount; idx++)
  1295. {
  1296. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1297. string billoid = prebill + idx + dtstr;
  1298. bill_entity.billOrderId += billoid;
  1299. if (idx < billCount)
  1300. {
  1301. bill_entity.billOrderId += ",";
  1302. }
  1303. }
  1304. bill_entity.productId = GetPostInt("ProductName");
  1305. bill_entity.num = GetPostInt("num");
  1306. bill_entity.unit = GetPostString("unit");
  1307. bill_entity.type = GetPostString("type");
  1308. bill_entity.sendType = GetPostString("SendType");
  1309. bill_entity.email = GetPostString("email");
  1310. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1311. bill_entity.shopName = GetPostString("ShopName");
  1312. bill_entity.applymemo = GetPostString("applyMemo");
  1313. bill_entity.createTime = DateTime.Now;
  1314. bill_entity.state = 0;
  1315. bill_entity.userId = 11;
  1316. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1317. bill_entity.Create();
  1318. }
  1319. catch (Exception ex)
  1320. {
  1321. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1322. returnErrorMsg("创建发票出错!");
  1323. return;
  1324. }
  1325. LogHelper.addLog(entity.ctid, 11, "申请发票", entity.OrderState, 1);
  1326. returnSuccessMsg("发票申请成功!");
  1327. return;
  1328. }
  1329. returnErrorMsg("找不到记录");
  1330. }
  1331. }
  1332. /**
  1333. * 查货
  1334. * ctid
  1335. * name
  1336. **/
  1337. public void ins_checkorder()
  1338. {
  1339. if (UrlPostParmsCheck("ctid"))
  1340. {
  1341. string ctid = GetPostString("ctid");
  1342. string name = GetPostString("name");
  1343. int UserID = GetPostInt("UserID");
  1344. CeErpTradeCell entity = null;
  1345. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1346. if (entity != null)
  1347. {
  1348. if (entity.OrderState < 6)
  1349. {
  1350. returnErrorMsg("下单完成后才可查货");
  1351. return;
  1352. }
  1353. if (entity.OrderState > 6)
  1354. {
  1355. returnErrorMsg("订单已发货");
  1356. return;
  1357. }
  1358. if (entity.FinishPlaceTime != null)
  1359. {
  1360. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  1361. {
  1362. returnErrorMsg("下单时间不足,无法查货");
  1363. return;
  1364. }
  1365. }
  1366. entity.MemoOpt = 3;
  1367. entity.UpdateTime = DateTime.Now;
  1368. entity.CheckOrderTime = DateTime.Now;
  1369. entity.Update();
  1370. LogHelper.addLog(entity.ctid, UserID, name + "标记:查货", entity.OrderState, 1);
  1371. returnSuccessMsg("操作成功!");
  1372. return;
  1373. }
  1374. returnErrorMsg("找不到记录");
  1375. return;
  1376. }
  1377. returnErrorMsg("缺少必要的参数ctid");
  1378. }
  1379. public void ins_checkdesign()
  1380. {
  1381. if (UrlPostParmsCheck("ctid"))
  1382. {
  1383. string ctid = GetPostString("ctid");
  1384. string name = GetPostString("name");
  1385. int UserID = GetPostInt("UserID");
  1386. int memoopt = GetPostInt("memoopt");
  1387. CeErpTradeCell entity = null;
  1388. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1389. if (entity != null)
  1390. {
  1391. string stropt = "";
  1392. if (memoopt == 1)
  1393. {
  1394. stropt = "“改稿”";
  1395. }
  1396. else if (memoopt == 2)
  1397. {
  1398. stropt = "“定稿”";
  1399. }
  1400. entity.MemoOpt = memoopt;
  1401. entity.UpdateTime = DateTime.Now;
  1402. entity.Update();
  1403. LogHelper.addLog(entity.ctid, UserID, name + "标记:" + stropt, entity.OrderState, 1);
  1404. returnSuccessMsg("操作成功!");
  1405. return;
  1406. }
  1407. returnErrorMsg("找不到记录");
  1408. return;
  1409. }
  1410. returnErrorMsg("缺少必要的参数ctid");
  1411. }
  1412. public void save_othermemo()
  1413. {
  1414. if (UrlPostParmsCheck("ctid"))
  1415. {
  1416. string ctid = GetPostString("ctid");
  1417. string name = GetPostString("name");
  1418. int UserID = GetPostInt("UserID");
  1419. CeErpTradeCell entity = null;
  1420. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1421. if (entity != null)
  1422. {
  1423. entity.OtherMemo = GetPostString("otherMemo");
  1424. entity.UpdateTime = DateTime.Now;
  1425. entity.Update();
  1426. returnSuccessMsg("保存成功!");
  1427. LogHelper.addLog(entity.ctid, UserID, name + "额外:" + entity.OtherMemo, entity.OrderState);
  1428. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  1429. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  1430. return;
  1431. }
  1432. returnErrorMsg("找不到记录");
  1433. return;
  1434. }
  1435. returnErrorMsg("缺少必要的参数ctid");
  1436. }
  1437. public void save_customermemo()
  1438. {
  1439. if (UrlPostParmsCheck("ctid"))
  1440. {
  1441. string ctid = GetPostString("ctid");
  1442. CeErpTradeCell entity = null;
  1443. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1444. if (entity != null)
  1445. {
  1446. entity.CustomerMemo = GetPostString("CustomerMemo");
  1447. entity.Update();
  1448. ApiVo apiVo = new ApiVo();
  1449. apiVo.orderNumber = entity.ctid;
  1450. apiVo.actionName = "followRemarks";
  1451. apiVo.orderRemarks = entity.CustomerMemo;
  1452. designHelper.API_WorkCore(apiVo);//followRemarks
  1453. returnSuccessMsg("保存成功!");
  1454. return;
  1455. }
  1456. returnErrorMsg("找不到记录");
  1457. }
  1458. }
  1459. public void create_order()
  1460. {
  1461. if (UrlPostParmsCheck("data"))
  1462. {
  1463. string data = GetPostString("data");
  1464. string tempStr = data;
  1465. Api_trade_info info = null;
  1466. try
  1467. {
  1468. info = JsonConvert.DeserializeObject<Api_trade_info>(data);
  1469. }
  1470. catch (Exception ex)
  1471. {
  1472. XLog.SaveLog(0, "create_order|1|" + ex.Message);
  1473. returnErrorMsg(ex.Message);
  1474. return;
  1475. }
  1476. if (info == null)
  1477. {
  1478. XLog.SaveLog(0, "Api_trade_info isNull");
  1479. return;
  1480. }
  1481. BizOrder bizOrder = info.bizOrder;
  1482. if (bizOrder == null)
  1483. {
  1484. returnErrorMsg("接口对象处理错误bizOrder=null");
  1485. return;
  1486. }
  1487. string sql = string.Format("insert into CE_ErpPreRequestData(tid,data,createtime) values('{0}','{1}',getdate()) ;" +
  1488. "insert into CE_ErpPreRequestDataBackup(tid,data,createtime) values('{0}','{1}',getdate()) ;",
  1489. bizOrder.thirdOrderId, tempStr);
  1490. XLog.ExecuteNonQuery(sql);
  1491. List<tempResponse> callResult = new List<tempResponse>();
  1492. returnSuccessMsg(JsonConvert.SerializeObject(callResult));
  1493. return;
  1494. }
  1495. returnErrorMsg("缺少必要的参数data");
  1496. }
  1497. public static void dealMessageInfo(string data)
  1498. {
  1499. Api_trade_info info = null;
  1500. try
  1501. {
  1502. info = JsonConvert.DeserializeObject<Api_trade_info>(data);
  1503. }
  1504. catch (Exception ex)
  1505. {
  1506. XLog.SaveLog(0, "dealMessageInfo|1|" + ex.Message);
  1507. return;
  1508. }
  1509. if (info == null)
  1510. {
  1511. XLog.SaveLog(0, "dealMessageInfo Api_trade_info isNull");
  1512. return;
  1513. }
  1514. BizOrder bizOrder = info.bizOrder;
  1515. if (bizOrder == null)
  1516. {
  1517. XLog.SaveLog(0, "dealMessageInfo 接口对象处理错误bizOrder=null");
  1518. return;
  1519. }
  1520. bool isCreate = false;
  1521. CeErpTrade trade = null;
  1522. trade = CeErpTrade.Get(bizOrder.thirdOrderId);
  1523. if (trade == null)
  1524. {
  1525. isCreate = true;
  1526. }
  1527. List<tempResponse> callResult = null;
  1528. try
  1529. {
  1530. trade = createTradeOrder(bizOrder, trade, isCreate);
  1531. List<Api_trade_info.TradeItemOrder> orderList = bizOrder.bizOrderItems;
  1532. createItemOrder(orderList, trade);
  1533. List<Api_trade_info.bizOrderSplit> bizOrderSplit = bizOrder.bizOrderSplits;
  1534. callResult = createCellOrder(bizOrderSplit, trade, isCreate);
  1535. if (!string.IsNullOrEmpty(bizOrder.weChatId) && !string.IsNullOrEmpty(bizOrder.phone))
  1536. {
  1537. string content = "[{\"title\":\"logo文件上传/模板截图/设计素材上传等等~\",\"type\":\"upload\",\"content\":" + bizOrder.designPics + "},{\"title\":\"需要设计的内容\",\"type\":\"input\",\"content\":\"" + bizOrder.designContent + "\"},{\"title\":\"手机号\",\"type\":\"input\",\"content\":\"" + bizOrder.phone + "\"},{\"title\":\"微信号\",\"type\":\"input\",\"content\":\"" + bizOrder.weChatId + "\"},{\"title\":\"请上传微信二维码\",\"type\":\"upload\",\"content\":" + bizOrder.weChatQrPics + "}]";
  1538. foreach (bizOrderSplit item in bizOrderSplit)
  1539. {
  1540. try
  1541. {
  1542. commonHelper.setFromDataInfo(item.splitNo, content, 0);
  1543. }
  1544. catch (Exception e) { }
  1545. }
  1546. }
  1547. }
  1548. catch (Exception ex)
  1549. {
  1550. XLog.SaveLog(0, "dealMessageInfo|2|" + ex);
  1551. return;
  1552. }
  1553. return;
  1554. }
  1555. public void refundOrder()
  1556. {
  1557. if (UrlPostParmsCheck("data"))
  1558. {
  1559. string data = GetPostString("data");
  1560. Api_refund_info info = null;
  1561. try
  1562. {
  1563. info = JsonConvert.DeserializeObject<Api_refund_info>(data);
  1564. }
  1565. catch (Exception ex)
  1566. {
  1567. XLog.SaveLog(0, "refundOrder|4|" + ex.Message);
  1568. returnErrorMsg(ex.Message);
  1569. return;
  1570. }
  1571. if (info == null)
  1572. {
  1573. XLog.SaveLog(0, "Api_refund_info isNull");
  1574. returnErrorMsg("接口对象处理错误RefundOrder=null1");
  1575. return;
  1576. }
  1577. RefundOrder refundOrder = info.refundOrder;
  1578. if (refundOrder == null)
  1579. {
  1580. returnErrorMsg("接口对象处理错误RefundOrder=null2");
  1581. return;
  1582. }
  1583. CeErpTrade trade = CeErpTrade.Get(refundOrder.tid);
  1584. if (trade != null)
  1585. {
  1586. CeErpTradeRefund refund = CeErpTradeRefund.GetByOidAndReId(refundOrder.ctid, refundOrder.orderSn);
  1587. LogHelper.addLog(refundOrder.ctid, 0, "客户退款", 0);
  1588. if (refund == null)
  1589. {
  1590. refund = new CeErpTradeRefund();
  1591. refund.refund_id = refundOrder.orderSn;
  1592. refund.tid = refundOrder.tid;
  1593. refund.oid = refundOrder.ctid;
  1594. if (refundOrder.createTime != null && refundOrder.createTime.Length > 0)
  1595. {
  1596. refund.created = Convert.ToDateTime(refundOrder.createTime);
  1597. }
  1598. if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
  1599. {
  1600. refund.modified = Convert.ToDateTime(refundOrder.updateTime);
  1601. }
  1602. refund.status = refundOrder.status;
  1603. refund.order_status = refundOrder.orderStatus;
  1604. refund.payment = refundOrder.payment.ToString();
  1605. refund.refund_fee = refundOrder.refundFee;//退款金额
  1606. refund.buyer_nick = GetNull_tostring(refundOrder.openBuyerNick);
  1607. refund.seller_nick = refundOrder.seller_nick;
  1608. refund.total_fee = refundOrder.totalFee;
  1609. refund.RefundState = 1;
  1610. refund.reason = refundOrder.reason;
  1611. refund.refundDesc = refundOrder.desc;
  1612. refund.IsPartRefund = refundOrder.isPartRefund;
  1613. refund.Create();
  1614. try
  1615. {
  1616. StringBuilder CeErpTradeCellSql = new StringBuilder();
  1617. CeErpTradeCellSql.AppendFormat("select * from CE_ErpTradeCell where ctid='{0}';", refundOrder.ctid);
  1618. DataSet cell = DbHelper.DbConn.ExecuteDataset(CeErpTradeCellSql.ToString());
  1619. DataTable datatable = cell.Tables[0];
  1620. if (datatable.Rows.Count > 0)
  1621. {
  1622. foreach (DataRow dr in datatable.Rows)
  1623. {
  1624. int DesignUserId = Convert.ToInt32(dr["DesignUserId"]);
  1625. int OrderState = Convert.ToInt32(dr["OrderState"]);
  1626. int CustomerUserId = Convert.ToInt32(dr["CustomerUserId"]);
  1627. if (DesignUserId > 0 && OrderState == 4)
  1628. {
  1629. createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, DesignUserId, 1);
  1630. }
  1631. if (CustomerUserId > 0)
  1632. {
  1633. createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, CustomerUserId, 1);
  1634. }
  1635. }
  1636. }
  1637. }
  1638. catch (Exception ex)
  1639. {
  1640. XLog.SaveLog(0, "退款推送通知创建失败!!" + ex);
  1641. }
  1642. int rstate = commonHelper.getRefundTagByState(refundOrder.status);
  1643. StringBuilder sql = new StringBuilder();
  1644. if (refund.IsPartRefund == 1)
  1645. {
  1646. double paylast = Convert.ToDouble(refundOrder.payment) - Convert.ToDouble(refund.refund_fee);
  1647. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1},payment={2} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 3, paylast);
  1648. }
  1649. else
  1650. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, rstate);
  1651. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1652. string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
  1653. //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  1654. StringBuilder sqls = new StringBuilder();
  1655. sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
  1656. CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
  1657. LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
  1658. }
  1659. else
  1660. {
  1661. if (refund.status != refundOrder.status)
  1662. {
  1663. refund.modified = DateTime.Now;
  1664. if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
  1665. {
  1666. refund.modified = Convert.ToDateTime(refundOrder.updateTime);
  1667. }
  1668. refund.order_status = refundOrder.orderStatus;
  1669. refund.status = refundOrder.status;
  1670. refund.Update();
  1671. int rstate = commonHelper.getRefundTagByState(refundOrder.status);
  1672. string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
  1673. StringBuilder sql = new StringBuilder();
  1674. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={0} where ctid='{1}' and isAfterSaleOrder=0;", rstate, refundOrder.ctid);
  1675. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1676. //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  1677. LogHelper.addLog(refundOrder.tid, 0, "更新退款状态:" + rstateWord, (int)OrderState.交易关闭);
  1678. // 取消设计费
  1679. StringBuilder sqls = new StringBuilder();
  1680. sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
  1681. CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
  1682. LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
  1683. }
  1684. }
  1685. List<RefundItemOrder> goodsItems = refundOrder.goodsItems;
  1686. foreach (RefundItemOrder item in goodsItems)
  1687. {
  1688. CeErpTradeOrder goods = CeErpTradeOrder.GetByOid(item.refOlId);
  1689. if (goods != null)
  1690. {
  1691. goods.refund_status = item.refundStatus;
  1692. goods.Update();
  1693. }
  1694. }
  1695. if (refundOrder.status == "WAIT_SELLER_AGREE")
  1696. {
  1697. StringBuilder sql = new StringBuilder();
  1698. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 1);
  1699. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1700. designHelper.API_refundOrder(refundOrder.tid, "refundIng", refundOrder.reason);
  1701. LogHelper.addLog(refundOrder.tid, 0, "申请退款中", 0);
  1702. }
  1703. else if (refundOrder.status == "CLOSED")
  1704. {
  1705. StringBuilder sql = new StringBuilder();
  1706. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 0);
  1707. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1708. designHelper.API_refundOrder(refundOrder.tid, "refundCancel", refundOrder.reason);
  1709. LogHelper.addLog(refundOrder.tid, 0, "关闭申请退款中", 0);
  1710. }
  1711. else if (refundOrder.status == "REFUNDED" || refundOrder.status == "SUCCESS")
  1712. {
  1713. designHelper.API_refundOrder(refundOrder.tid, "refundEd", refundOrder.reason);
  1714. }
  1715. }
  1716. else
  1717. {
  1718. }
  1719. }
  1720. returnErrorMsg("缺少必要的参数data");
  1721. }
  1722. public void createRefundMessage(string ctid, MessageState messageState, int userId, int type)
  1723. {
  1724. CeErpMessageTip ceErpMessageTip = new CeErpMessageTip();
  1725. ceErpMessageTip.tid = ctid;
  1726. ceErpMessageTip.type = Convert.ToInt32(messageState);
  1727. ceErpMessageTip.userId = userId;
  1728. ceErpMessageTip.isVisit = false;
  1729. ceErpMessageTip.content = "订单" + ctid + "申请了退款!";
  1730. ceErpMessageTip.Create();
  1731. StringBuilder sqlTip = new StringBuilder();
  1732. if (type == 1)
  1733. {
  1734. 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);
  1735. }
  1736. if (type == 2)
  1737. {
  1738. 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);
  1739. }
  1740. DataTable dth = DbHelper.DbConn.ExecuteDataset(sqlTip.ToString()).Tables[0];
  1741. if (dth.Rows.Count > 0)
  1742. {
  1743. foreach (DataRow dthdr in dth.Rows)
  1744. {
  1745. int Bid = Convert.ToInt32(dthdr["id"]);
  1746. if (Bid > 0)
  1747. {
  1748. CeErpMessageTip ceErpMessageTipB = new CeErpMessageTip();
  1749. ceErpMessageTipB.tid = ctid;
  1750. ceErpMessageTipB.type = Convert.ToInt32(messageState);
  1751. ceErpMessageTipB.userId = Bid;
  1752. ceErpMessageTipB.isVisit = false;
  1753. ceErpMessageTipB.content = "订单" + ctid + "申请了退款!";
  1754. ceErpMessageTipB.Create();
  1755. }
  1756. }
  1757. }
  1758. }
  1759. public static List<tempResponse> createCellOrder(List<Api_trade_info.bizOrderSplit> bizOrderSplit, CeErpTrade trade, bool isCreate)
  1760. {
  1761. List<tempResponse> tempResponses = new List<tempResponse>();
  1762. CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
  1763. foreach (Api_trade_info.bizOrderSplit item in bizOrderSplit)
  1764. {
  1765. bool create = false;
  1766. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(item.splitNo);
  1767. if (entity == null)
  1768. {
  1769. entity = new CeErpTradeCell();
  1770. create = true;
  1771. entity.tid = trade.tid;
  1772. entity.pay_time = trade.pay_time;
  1773. }
  1774. if (entity.OrderState > 4)
  1775. {
  1776. continue;
  1777. }
  1778. entity.ctid = item.splitNo;
  1779. entity.seller_memo = item.systemRemark;
  1780. if (!string.IsNullOrEmpty(item.splitAmount))
  1781. {
  1782. entity.payment = Convert.ToDouble(item.splitAmount);
  1783. }
  1784. if (!string.IsNullOrEmpty(item.splitAmount))
  1785. {
  1786. entity.AfterSalePayment = Convert.ToDouble(item.splitAmount);
  1787. }
  1788. if (!string.IsNullOrEmpty(item.sfMark))
  1789. {
  1790. entity.IsSF = Convert.ToInt32(item.sfMark);
  1791. }
  1792. entity.ProductSize = item.size;
  1793. entity.Material = item.material;
  1794. entity.CustomerUserId = item.erpCustomerServiceId;
  1795. //entity.Craft = item.craftText;
  1796. entity.ProductCount = item.productQuantity;
  1797. entity.ProductId = tmcHelper.getProductIdByName(item.cate3Id);
  1798. if (!string.IsNullOrEmpty(item.internalStatus))
  1799. {
  1800. entity.OrderState = Convert.ToInt32(item.internalStatus);
  1801. }
  1802. entity.IsUrgency = item.isUrgent;
  1803. entity.ptid = item.ptid;
  1804. entity.SplitTag = item.splitInfoNo;
  1805. entity.UpdateTime = DateTime.Now;
  1806. if (!string.IsNullOrEmpty(item.paymentFile))
  1807. {
  1808. entity.PayProofImg = item.paymentFile;
  1809. }
  1810. if (item.shippingTime != null && item.shippingTime.Length > 0)
  1811. {
  1812. entity.UnusualTime = Convert.ToDateTime(item.shippingTime);
  1813. entity.UrgencyTime = Convert.ToDateTime(item.shippingTime);
  1814. }
  1815. if (!string.IsNullOrEmpty(item.sendGiftMark))
  1816. {
  1817. entity.IsSendGift = Convert.ToInt32(item.sendGiftMark);
  1818. }
  1819. entity.OtherMemo = item.otherRemark;
  1820. entity.IsOldCustomer = item.isRepurchase ? 1 : 0;
  1821. entity.IsOldCustomerMore = item.isOldCustomerMore;
  1822. entity.MemoOpt = item.memoOpt;
  1823. entity.isDianziOrder = item.isDianziOrder;
  1824. if (item.isPreShipping != null && item.isPreShipping.Length > 0)
  1825. {
  1826. entity.IsPreDelivery = Convert.ToInt32(item.isPreShipping);
  1827. }
  1828. if (item.checkOrderTime != null && item.checkOrderTime.Length > 0)
  1829. {
  1830. entity.CheckOrderTime = Convert.ToDateTime(item.checkOrderTime);
  1831. }
  1832. int shopId = 0;
  1833. if (nShop != null)
  1834. {
  1835. shopId = nShop.ID;
  1836. }
  1837. entity.ShopId = shopId;
  1838. entity.OrderSn = item.OrderSn;
  1839. entity.ParentSplitNo = item.parentSplitNo;
  1840. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1841. string sql_pay = "";
  1842. if (ceErpTradeCellExtend == null)
  1843. {
  1844. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  1845. ceErpTradeCellExtend.ctid = entity.ctid;
  1846. }
  1847. ceErpTradeCellExtend.cate1 = item.cate1;
  1848. ceErpTradeCellExtend.cate2 = item.cate2;
  1849. ceErpTradeCellExtend.scene = item.scene;
  1850. ceErpTradeCellExtend.material = item.material;
  1851. ceErpTradeCellExtend.offerAmount = item.offerAmount;
  1852. ceErpTradeCellExtend.numbers = item.numbers;
  1853. ceErpTradeCellExtend.typeScene = item.typeScene;
  1854. ceErpTradeCellExtend.opScene = item.opScene;
  1855. ceErpTradeCellExtend.craft = item.craft;
  1856. ceErpTradeCellExtend.numberType = item.numberType;
  1857. ceErpTradeCellExtend.cate1Id = item.cate1Id;
  1858. ceErpTradeCellExtend.cate2Id = item.cate2Id;
  1859. ceErpTradeCellExtend.cate3Id = item.cate3Id;
  1860. ceErpTradeCellExtend.sceneId = item.sceneId;
  1861. ceErpTradeCellExtend.typeSceneId = item.typeSceneId;
  1862. ceErpTradeCellExtend.opSceneId = item.opSceneId;
  1863. ceErpTradeCellExtend.materialId = item.materialId;
  1864. ceErpTradeCellExtend.width = item.width;
  1865. ceErpTradeCellExtend.height = item.height;
  1866. ceErpTradeCellExtend.length = item.length;
  1867. ceErpTradeCellExtend.recSize = item.recSize;
  1868. ceErpTradeCellExtend.sizeUnit = item.sizeUnit;
  1869. ceErpTradeCellExtend.numberUnit = item.numberUnit;
  1870. ceErpTradeCellExtend.orderFrom = 30;
  1871. ceErpTradeCellExtend.spu_id = item.spuId;
  1872. ceErpTradeCellExtend.quantity = item.quantity;
  1873. ceErpTradeCellExtend.discountAmount = item.discountAmount;
  1874. ceErpTradeCellExtend.differentAmount = item.compensateAmount;
  1875. ceErpTradeCellExtend.differentSplitNo = item.compensateSplitOrderUniqueNo;
  1876. ceErpTradeCellExtend.orderType = item.orderType;
  1877. ceErpTradeCellExtend.parentOrderSn = item.parentSplitNo;
  1878. if (ceErpTradeCellExtend.ID > 0)
  1879. {
  1880. ceErpTradeCellExtend.Update();
  1881. }
  1882. else
  1883. {
  1884. ceErpTradeCellExtend.Create();
  1885. }
  1886. if (!string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id))
  1887. {
  1888. ceErpTradeCellExtend = commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  1889. }
  1890. if (item.isGift == 1)
  1891. {
  1892. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  1893. entity.IsXianHuo = 1;
  1894. entity.IsGift = 1;
  1895. entity.FinishPlaceTime = trade.pay_time;
  1896. if (entity.OrderState < 6)
  1897. {
  1898. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1899. }
  1900. }
  1901. if (item.isSpot)
  1902. {
  1903. if (entity.OrderState < 6)
  1904. {
  1905. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1906. }
  1907. entity.seller_memo = item.systemRemark;
  1908. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1909. entity.IsXianHuo = 1;
  1910. entity.FinishPlaceTime = entity.pay_time;
  1911. if (item.systemRemark.IndexOf("封酒贴") != -1)
  1912. {
  1913. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  1914. if (trade.buyer_memo != "")
  1915. {
  1916. entity.OrderState = 2;
  1917. entity.ProductId = 1;
  1918. entity.IsXianHuo = 0;
  1919. item.systemRemark = item.systemRemark.Replace("现货", "");
  1920. item.systemRemark = item.systemRemark.Replace(" ", "");
  1921. entity.seller_memo = item.systemRemark;
  1922. if (entity.ShopId != 0)
  1923. {
  1924. entity.OrderState = orderAudit(entity.ShopId);
  1925. }
  1926. }
  1927. }
  1928. else if (item.systemRemark.IndexOf("#") != -1)
  1929. {
  1930. entity.SupplierId = 87;
  1931. }
  1932. else if (item.systemRemark.IndexOf("喜字贴") != -1)
  1933. {
  1934. entity.SupplierId = 70;
  1935. }
  1936. else if (item.systemRemark.IndexOf("兔团团") != -1)
  1937. {
  1938. entity.SupplierId = 101;
  1939. }
  1940. else if (item.systemRemark.IndexOf("手拉旗") != -1)
  1941. {
  1942. entity.SupplierId = 108;
  1943. }
  1944. try
  1945. {
  1946. string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
  1947. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  1948. List<Dictionary<string, string>> material_list = new List<Dictionary<string, string>>();
  1949. List<Dictionary<string, string>> name_list = new List<Dictionary<string, string>>();
  1950. foreach (DataRow dr in goodsDt.Rows)
  1951. {
  1952. string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
  1953. List<string> xianhuo = sqlMemo.Split(',').ToList();
  1954. foreach (var val in xianhuo)
  1955. {
  1956. if (string.IsNullOrEmpty(val)) continue;
  1957. Dictionary<string, string> material_map = new Dictionary<string, string>();//材质
  1958. Dictionary<string, string> name_map = new Dictionary<string, string>();//特殊名称
  1959. if (val.IndexOf('-') > -1)
  1960. {
  1961. List<string> list = val.Split('-').ToList();
  1962. material_map.Add(dr["id"].ToString(), list[0]);
  1963. name_map.Add(dr["id"].ToString(), list[1]);
  1964. }
  1965. else
  1966. {
  1967. material_map.Add(dr["id"].ToString(), val);
  1968. }
  1969. material_list.Add(material_map);
  1970. name_list.Add(name_map);
  1971. }
  1972. }
  1973. List<string> materials = new List<string>();
  1974. List<string> names = new List<string>();
  1975. List<string> result = new List<string>();
  1976. for (int i = 0; i < material_list.Count; i++)
  1977. {
  1978. Dictionary<string, string> map = material_list[i];
  1979. foreach (var val in map)
  1980. {
  1981. if (item.systemRemark.IndexOf(val.Value) > -1)
  1982. {
  1983. Dictionary<string, string> map2 = name_list[i];
  1984. if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
  1985. {
  1986. foreach (var item1 in map2)
  1987. {
  1988. if (item.systemRemark.IndexOf(item1.Value) > -1)
  1989. {
  1990. names.Add(item1.Key);
  1991. materials.Add(val.Key);
  1992. }
  1993. }
  1994. }
  1995. else
  1996. {
  1997. materials.Add(val.Key);
  1998. }
  1999. }
  2000. }
  2001. }
  2002. if (names.Count > 0)//特殊名称有只先在特殊名称里选择
  2003. {
  2004. result = names.Distinct().ToList();
  2005. }
  2006. else
  2007. {
  2008. result = materials.Distinct().ToList();
  2009. }
  2010. if (result.Count > 0)
  2011. {
  2012. Random rnd = new Random();
  2013. int index = rnd.Next(result.Count);
  2014. entity.SupplierId = int.Parse(result[index]);
  2015. }
  2016. }
  2017. catch (Exception e)
  2018. {
  2019. XLog.SaveLog(0, "|现货匹配|" + e.Message);
  2020. }
  2021. }
  2022. if (isCreate)
  2023. {
  2024. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  2025. if (oldRes > 0)
  2026. {
  2027. //entity.IsOldCustomer = 1;
  2028. //if (oldRes == 2) entity.IsOldCustomerMore = 1;
  2029. }
  2030. }
  2031. if (item.sampleMark == "1")
  2032. {
  2033. entity.IsSample = 1;
  2034. entity.OrderState = 6;
  2035. entity.FinishPlaceTime = DateTime.Now;
  2036. entity.IsOldCustomer = 0;
  2037. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2038. }
  2039. if (item.sampleMark == "3")
  2040. {
  2041. entity.IsSample = 3;
  2042. entity.OrderState = 6;
  2043. entity.FinishPlaceTime = DateTime.Now;
  2044. entity.IsOldCustomer = 0;
  2045. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2046. }
  2047. if (item.sampleMark == "2" && !string.IsNullOrEmpty(item.parentSplitNo))
  2048. {
  2049. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(item.parentSplitNo);
  2050. if (ceErpTradeCell != null)
  2051. {
  2052. entity.CustomerUserId = ceErpTradeCell.CustomerUserId;
  2053. entity.DesignUserId = ceErpTradeCell.DesignUserId;
  2054. entity.SupplierId = ceErpTradeCell.SupplierId;
  2055. entity.IsSample = 2;
  2056. entity.WaitDesignTime = ceErpTradeCell.WaitDesignTime;
  2057. entity.StartDesignTime = ceErpTradeCell.StartDesignTime;
  2058. entity.FinishDesignTime = ceErpTradeCell.FinishDesignTime;
  2059. entity.FinishPlaceTime = ceErpTradeCell.FinishPlaceTime;
  2060. }
  2061. CeErpTradeCellExtend parentCell = CeErpTradeCellExtend.getByTid(item.parentSplitNo);
  2062. if (parentCell == null)
  2063. {
  2064. parentCell = new CeErpTradeCellExtend();
  2065. parentCell.ctid = item.parentSplitNo;
  2066. }
  2067. if (!string.IsNullOrEmpty(item.splitAmount))
  2068. {
  2069. parentCell.differentAmount += Convert.ToDouble(item.splitAmount);
  2070. }
  2071. if (parentCell.ID > 0)
  2072. {
  2073. parentCell.Update();
  2074. }
  2075. else
  2076. {
  2077. parentCell.Create();
  2078. }
  2079. ApiVo apiVo = new ApiVo();
  2080. apiVo.orderNumber = entity.ptid;
  2081. apiVo.payment = entity.payment;
  2082. apiVo.actionName = "repairDesign";
  2083. designHelper.API_WorkCore(apiVo);//repairDesign
  2084. }
  2085. bool isCopyFile = false;
  2086. //老客户
  2087. if (item.isRepurchase)
  2088. {
  2089. if (item.isOldCustomer == 1)
  2090. {
  2091. tmcHelper.dealOldCustomerEntityTag(ref entity, trade);
  2092. }
  2093. if (item.isOldCustomer == 3)
  2094. {
  2095. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  2096. entity.WaitDesignTime = DateTime.Now;
  2097. isCopyFile = true;
  2098. }
  2099. if (item.isOldCustomer == 2)
  2100. {
  2101. entity.OrderState = 3;
  2102. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  2103. entity.WaitDesignTime = DateTime.Now;
  2104. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  2105. }
  2106. }
  2107. if (create)
  2108. {
  2109. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "创建推送生成:" + entity.seller_memo, entity.OrderState);
  2110. entity.Create();
  2111. }
  2112. else
  2113. {
  2114. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "更新推送生成:" + entity.seller_memo, entity.OrderState);
  2115. designHelper.API_update_renewOrder(entity);
  2116. entity.Update();
  2117. }
  2118. if (!string.IsNullOrEmpty(sql_pay))
  2119. {
  2120. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2121. }
  2122. if (isCopyFile)
  2123. {
  2124. apiUploaderResponse upResult = CopyDesignFile(entity.ctid, item.oldOrderSn, entity.CustomerUserId);
  2125. if (upResult == null || "error".Equals(upResult.type))
  2126. {
  2127. tempResponse response = new tempResponse();
  2128. response.flag = "1";
  2129. response.flagData = entity.ctid;
  2130. response.flagMsg = upResult == null ? "复制文件出错!" : upResult.result;
  2131. tempResponses.Add(response);
  2132. }
  2133. }
  2134. }
  2135. return tempResponses;
  2136. }
  2137. public static void createItemOrder(List<Api_trade_info.TradeItemOrder> orderList, CeErpTrade trade)
  2138. {
  2139. foreach (Api_trade_info.TradeItemOrder item in orderList)
  2140. {
  2141. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.thirdOrderItemId);
  2142. bool isCreateOrder = false;
  2143. if (order == null)
  2144. {
  2145. order = new CeErpTradeOrder();
  2146. isCreateOrder = true;
  2147. order.oid = item.thirdOrderItemId;
  2148. order.tid = trade.tid;
  2149. order.buyer_nick = trade.buyer_nick;
  2150. }
  2151. order.refund_status = item.refundStatus;
  2152. order.status = trade.status;
  2153. order.title = item.title;
  2154. if (!string.IsNullOrEmpty(item.price))
  2155. {
  2156. order.price = Convert.ToDouble(item.price);
  2157. }
  2158. if (item.picUrl != null)
  2159. {
  2160. order.pic_path = item.picUrl;
  2161. }
  2162. if (!string.IsNullOrEmpty(item.num))
  2163. {
  2164. order.num = Convert.ToDouble(item.num);
  2165. }
  2166. if (!string.IsNullOrEmpty(item.totalAmount))
  2167. {
  2168. order.payment = Convert.ToDouble(item.totalAmount);
  2169. }
  2170. if (!string.IsNullOrEmpty(item.totalSellPrice))
  2171. {
  2172. order.total_fee = Convert.ToDouble(item.totalSellPrice);
  2173. }
  2174. //order.adjust_fee = Convert.ToDouble(item.price);
  2175. if (item.thirdSkuId != null && item.thirdSkuId != "")
  2176. {
  2177. order.sku_id = item.thirdSkuId;
  2178. }
  2179. if (item.specification != null && item.specification != "")
  2180. {
  2181. order.sku_properties_name = item.specification;
  2182. }
  2183. if (item.thirdSpuId != null && item.thirdSpuId != "")
  2184. {
  2185. order.spu_id = item.thirdSpuId;
  2186. }
  2187. if (isCreateOrder)
  2188. {
  2189. order.Create();
  2190. }
  2191. else
  2192. {
  2193. order.Update();
  2194. }
  2195. }
  2196. }
  2197. public static CeErpTrade createTradeOrder(BizOrder bizOrder, CeErpTrade trade, bool isCreate)
  2198. {
  2199. if (trade == null)
  2200. { //新生成订单的
  2201. isCreate = true;
  2202. trade = new CeErpTrade();
  2203. trade.tid = bizOrder.thirdOrderId;
  2204. trade.type = bizOrder.orderPlatform;
  2205. trade.receiverId = bizOrder.receiverId;
  2206. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  2207. {
  2208. trade.price = Convert.ToDouble(bizOrder.payAmount);
  2209. }
  2210. trade.discount_fee = 0;
  2211. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  2212. {
  2213. trade.total_fee = Convert.ToDouble(bizOrder.payAmount);
  2214. }
  2215. if (bizOrder.orderTime != null && bizOrder.orderTime.Length > 0)
  2216. {
  2217. trade.created = Convert.ToDateTime(bizOrder.orderTime);
  2218. }
  2219. if (bizOrder.payTime != null && bizOrder.payTime.Length > 0)
  2220. {
  2221. trade.pay_time = Convert.ToDateTime(bizOrder.payTime);
  2222. }
  2223. trade.seller_nick = GetNull_tostring(bizOrder.openSellerNick);
  2224. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  2225. {
  2226. trade.payment = Convert.ToDouble(bizOrder.payAmount);
  2227. }
  2228. }
  2229. trade.buyer_nick = GetNull_tostring(bizOrder.openBuyerNick);
  2230. trade.receiver_state = bizOrder.province;
  2231. if (!string.IsNullOrEmpty(bizOrder.num))
  2232. {
  2233. trade.num = Convert.ToDouble(bizOrder.num);
  2234. }
  2235. trade.receiver_city = bizOrder.city;
  2236. trade.receiver_address = GetNoNullValue_string(bizOrder.address);
  2237. trade.receiver_town = GetNoNullValue_string(bizOrder.receiverTown);
  2238. trade.receiver_district = GetNoNullValue_string(bizOrder.area);
  2239. trade.seller_flag = bizOrder.thirdFlag;
  2240. trade.orderType = bizOrder.orderType;
  2241. trade.orderFrom = 30;
  2242. trade.unrefundedAmount = bizOrder.unrefundedAmount;
  2243. if (bizOrder.modifyTime != null && bizOrder.modifyTime.Length > 0)
  2244. {
  2245. trade.modified = Convert.ToDateTime(bizOrder.modifyTime);
  2246. }
  2247. if (bizOrder.finishTime != null && bizOrder.finishTime.Length > 0)
  2248. {
  2249. trade.end_time = Convert.ToDateTime(bizOrder.finishTime);
  2250. }
  2251. if (bizOrder.shippingTime != null && bizOrder.shippingTime.Length > 0)
  2252. {
  2253. trade.delivery_time = Convert.ToDateTime(bizOrder.shippingTime);
  2254. }
  2255. if (bizOrder.confirmTime != null && bizOrder.confirmTime.Length > 0)
  2256. {
  2257. trade.confirmTime = Convert.ToDateTime(bizOrder.confirmTime);
  2258. }
  2259. trade.buyer_memo = GetNoNullValue_string(bizOrder.buyerRemark);
  2260. bool isSellerMemoChange = false;
  2261. //备注修改
  2262. bizOrder.sellerRemark = GetNoNullValue_string(bizOrder.sellerRemark);
  2263. if (trade.seller_memo != bizOrder.sellerRemark || trade.seller_memo.Length != bizOrder.sellerRemark.Length)
  2264. {
  2265. isSellerMemoChange = true;
  2266. }
  2267. trade.status = bizOrder.status;
  2268. trade.seller_memo = bizOrder.sellerRemark;
  2269. trade.buyer_id = bizOrder.openBuyerId;
  2270. trade.posCode = bizOrder.shopCode;
  2271. if (!string.IsNullOrEmpty(bizOrder.addressFileUrl))
  2272. {
  2273. trade.Attachments = "https://dfdiyfile.oss-cn-fuzhou.aliyuncs.com/" + bizOrder.addressFileUrl;
  2274. }
  2275. if (isCreate)
  2276. {
  2277. trade.IsNew = bizOrder.IsNew;
  2278. trade.Create();
  2279. }
  2280. else
  2281. {
  2282. if (bizOrder.status == "CLOSE")
  2283. {
  2284. trade.consign_time = DateTime.Now;
  2285. }
  2286. trade.Update();
  2287. }
  2288. CeErpTradeCell.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set UpdateTime = getdate() where tid = '{0}'", trade.tid));
  2289. try
  2290. {
  2291. if (bizOrder.status == "CLOSE" || bizOrder.status == "CANCEL")
  2292. {
  2293. StringBuilder sql = new StringBuilder();
  2294. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, bizOrder.thirdOrderId);
  2295. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  2296. ApiVo apiVo = new ApiVo();
  2297. apiVo.actionName = "closeDesign";
  2298. apiVo.orderNumber = bizOrder.thirdOrderId;
  2299. //designHelper.API_WorkCore(apiVo);//closeDesign
  2300. LogHelper.addLog(bizOrder.thirdOrderId, 0, "交易关闭", (int)OrderState.交易关闭);
  2301. // commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
  2302. // removeOldCustomerInfo(trade);
  2303. }
  2304. else if (bizOrder.status == "COMPLETE")
  2305. {
  2306. StringBuilder sql = new StringBuilder();
  2307. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, bizOrder.thirdOrderId);
  2308. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  2309. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
  2310. }
  2311. else if (bizOrder.status == "SHIPPED")//已发货
  2312. {
  2313. StringBuilder sql = new StringBuilder();
  2314. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, bizOrder.thirdOrderId);
  2315. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  2316. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
  2317. }
  2318. }
  2319. catch (Exception ex)
  2320. {
  2321. XLog.SaveLog(0, bizOrder.thirdOrderId + "shipped:" + ex.Message);
  2322. throw ex;
  2323. }
  2324. return trade;
  2325. }
  2326. public void checkOrderToWh()
  2327. {
  2328. string orderNumber = GetPostString("orderNumber");
  2329. string spuId = GetPostString("spuId");
  2330. string seller_memo = GetPostString("seller_memo");
  2331. string otherMemo = GetPostString("otherMemo");
  2332. string shopName = GetPostString("shopName");
  2333. string productId = GetPostString("productId");
  2334. CeErpProduct ceErpProduct = CeErpProduct.GetByName(productId);
  2335. CeErpShop ceErpShop = CeErpShop.GetShopIdByName(shopName);
  2336. if (ceErpProduct == null || ceErpShop == null)
  2337. {
  2338. returnErrorMsg("商品id或者店铺id不全");
  2339. return;
  2340. }
  2341. int isDianziOrder = GetPostInt("isDianziOrder");
  2342. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2343. CeErpTradeCellExtend ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2344. ceErpTradeCell.ctid = orderNumber;
  2345. ceErpTradeCell.seller_memo = seller_memo;
  2346. ceErpTradeCell.OtherMemo = otherMemo;
  2347. ceErpTradeCell.ShopId = ceErpShop.ID;
  2348. ceErpTradeCell.ProductId = ceErpProduct.ID;
  2349. ceErpTradeCell.isDianziOrder = isDianziOrder;
  2350. ceErpTradeCellExtend.spu_id = spuId;
  2351. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  2352. returnSuccess("\"" + ceErpTradeCellExtend.ToType + "\"");
  2353. return;
  2354. }
  2355. public static apiUploaderResponse CopyDesignFile(string ctid, string oldCtid, int userId)
  2356. {
  2357. string post_url = "http://183.250.143.56:8088/autocopy.aspx";
  2358. WebClient wc = new WebClient();
  2359. wc.Encoding = Encoding.GetEncoding("utf-8");
  2360. //json参数
  2361. NameValueCollection PostVars = new NameValueCollection();
  2362. PostVars.Add("hexdata", oldCtid + "," + ctid);
  2363. PostVars.Add("userid", userId.ToString());
  2364. apiUploaderResponse result = null;
  2365. try
  2366. {
  2367. byte[] ret = wc.UploadValues(post_url, "POST", PostVars);
  2368. string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret);
  2369. result = JsonConvert.DeserializeObject<apiUploaderResponse>(remoteInfo);
  2370. }
  2371. catch (Exception ex)
  2372. {
  2373. XLog.SaveLog(0, "CopyDesignFile:" + ex.Message);
  2374. }
  2375. return result;
  2376. }
  2377. public static DateTime StampToDateTime(string timeStamp)
  2378. {
  2379. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  2380. long lTime = long.Parse(timeStamp + "0000");
  2381. TimeSpan toNow = new TimeSpan(lTime);
  2382. return dateTimeStart.Add(toNow);
  2383. }
  2384. public static string GetNull_tostring(object value)
  2385. {
  2386. if (value == null)
  2387. {
  2388. return "";
  2389. }
  2390. return value.ToString();
  2391. }
  2392. public static string GetNoNullValue_string(string value)
  2393. {
  2394. if (value == null)
  2395. {
  2396. return "";
  2397. }
  2398. value = value.Replace("\n", " ");
  2399. value = value.Replace("\r", " ");
  2400. return value;
  2401. }
  2402. public static string getShopNameByECode(string code)
  2403. {
  2404. string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
  2405. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  2406. if (dt != null && dt.Rows.Count > 0)
  2407. {
  2408. return dt.Rows[0]["ShopName"].ToString();
  2409. }
  2410. return "";
  2411. }
  2412. public static int orderAudit(int shopId)
  2413. {
  2414. try
  2415. {
  2416. CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
  2417. if (ceErpShop == null) return 2;
  2418. if (!ceErpShop.orderAudit) return 2;
  2419. return -1;
  2420. }
  2421. catch (Exception ex)
  2422. {
  2423. return 2;
  2424. }
  2425. }
  2426. public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
  2427. {
  2428. if (father.seller_nick == "") return 0;
  2429. CeErpCustomer cus = null;
  2430. cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
  2431. if (cus == null)
  2432. {
  2433. cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
  2434. }
  2435. int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
  2436. if (cus != null)
  2437. {
  2438. if (cus.lastbuy_time.ToString() == "") return 0;
  2439. if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
  2440. cus.buyer_id = father.buyer_id;
  2441. if (cus.lastTid == father.tid)
  2442. {
  2443. if (pcount != cus.product_count)
  2444. {
  2445. cus.product_count = pcount;
  2446. cus.Update();
  2447. }
  2448. }
  2449. else
  2450. {
  2451. int returnNum = 0;
  2452. TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
  2453. cus.buy_day = Convert.ToInt32(tsday.TotalDays);
  2454. cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
  2455. cus.buy_count = cus.buy_count + 1;
  2456. cus.lastbuy_time2 = cus.lastbuy_time;
  2457. cus.buyer_id = father.buyer_id;
  2458. cus.lastbuy_time = father.pay_time;
  2459. int lastpCount = cus.product_count;
  2460. cus.product_count = pcount;
  2461. cus.lastTid2 = cus.lastTid;
  2462. cus.lastTid = father.tid;
  2463. if (cus.buy_day > 1)
  2464. {
  2465. if (pcount > lastpCount && cus.product_count != 0)
  2466. {
  2467. cus.isMore = 1;
  2468. returnNum = 2;
  2469. }
  2470. else
  2471. returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
  2472. }
  2473. else
  2474. returnNum = 0;
  2475. cus.Update();
  2476. return returnNum;
  2477. }
  2478. }
  2479. else
  2480. {
  2481. try
  2482. {
  2483. cus = new CeErpCustomer();
  2484. cus.buyer_nick = father.buyer_nick;
  2485. cus.seller_nick = father.seller_nick;
  2486. cus.buyer_id = father.buyer_id;
  2487. cus.buy_day = 0;
  2488. cus.buy_count = 1;
  2489. cus.lastbuy_time = father.pay_time;
  2490. cus.lastTid = father.tid;
  2491. cus.total_fee = Convert.ToDouble(father.payment);
  2492. cus.product_count = pcount;
  2493. cus.Create();
  2494. return 0;
  2495. }
  2496. catch (Exception ex)
  2497. {
  2498. XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
  2499. }
  2500. }
  2501. return 0;
  2502. }
  2503. }
  2504. }