preSalesHelper.cs 88 KB

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