preSalesHelper.cs 100 KB

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