preSalesHelper.cs 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266
  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. public void upd_erp_masteraftersale()
  914. {
  915. if (UrlPostParmsCheck("id"))
  916. {
  917. string id = GetPostString("id");
  918. int st = GetPostInt("afterstate");
  919. string afmemo = GetPostString("supmemo");
  920. string image = GetPostString("image");
  921. string textResult = GetPostString("textResult");
  922. int UserID = GetPostInt("UserID");
  923. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  924. if (ceErpTradeResponsible != null)
  925. {
  926. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  927. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  928. ceErpTradeResponsible.Update();
  929. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  930. if (entity != null)
  931. {
  932. entity.AfterSaleSupplierState = st;
  933. entity.AfterSaleSupplierMemo = afmemo;
  934. if (st == 1)
  935. {
  936. }
  937. else
  938. {
  939. CeErpTradeResponsible.dateByTid(entity.ctid);
  940. //退回到售后
  941. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  942. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  943. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  944. if (num <= 1)
  945. {
  946. entity.AfterSaleState = 1;
  947. }
  948. else
  949. {
  950. entity.AfterSaleState = 5;
  951. }
  952. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  953. if (ceErpTradeAfterSaleExtend != null)
  954. {
  955. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  956. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  957. ceErpTradeAfterSaleExtend.Update();
  958. }
  959. else
  960. {
  961. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  962. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  963. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  964. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  965. ceErpTradeAfterSaleExtend.Create();
  966. }
  967. }
  968. entity.Update();
  969. returnSuccessMsg("操作成功!");
  970. LogHelper.addLog(entity.ctid, UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  971. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), UserID, st == 1 ? 0 : 1, afmemo, image);
  972. return;
  973. }
  974. }
  975. returnErrorMsg("找不到订单记录");
  976. }
  977. }
  978. public void save_erp_billinfo()
  979. {
  980. if (UrlPostParmsCheck("ctid"))
  981. {
  982. string eid = GetPostString("ctid");
  983. CeErpTradeCell entity = null;
  984. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  985. if (entity != null)
  986. {
  987. CeErpBill bill = CeErpBill.GetByTid(eid);
  988. bool isHave = false;
  989. if (bill != null)
  990. {
  991. isHave = true;
  992. if (bill.state != 4)
  993. {
  994. returnErrorMsg("此单已经申请过发票了");
  995. return;
  996. }
  997. }
  998. if (entity.IsNeedBill == 0)
  999. {
  1000. entity.IsNeedBill = 1;
  1001. }
  1002. entity.Update();
  1003. string errjson = "";
  1004. try
  1005. {
  1006. CeErpBill bill_entity = new CeErpBill();
  1007. bill_entity.tid = entity.tid;
  1008. bill_entity.title = GetPostString("title");
  1009. string taxstr = GetPostString("tax");
  1010. taxstr = taxstr.Replace(" ", "");
  1011. bill_entity.tax = taxstr;
  1012. bill_entity.bank = GetPostString("bank");
  1013. string bankacstr = GetPostString("bankac");
  1014. bankacstr = bankacstr.Replace(" ", "");
  1015. bill_entity.bankac = bankacstr;
  1016. bill_entity.address = GetPostString("address");
  1017. bill_entity.phone = GetPostString("phone");
  1018. bill_entity.price = GetPostString("price");
  1019. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1020. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1021. {
  1022. billCount += 1;
  1023. }
  1024. string prebill = "ltb";
  1025. for (int idx = 1; idx <= billCount; idx++)
  1026. {
  1027. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1028. string billoid = prebill + idx + dtstr;
  1029. bill_entity.billOrderId += billoid;
  1030. if (idx < billCount)
  1031. {
  1032. bill_entity.billOrderId += ",";
  1033. }
  1034. }
  1035. bill_entity.productId = GetPostInt("ProductName");
  1036. bill_entity.num = GetPostInt("num");
  1037. bill_entity.unit = GetPostString("unit");
  1038. bill_entity.type = GetPostString("type");
  1039. bill_entity.sendType = GetPostString("SendType");
  1040. bill_entity.email = GetPostString("email");
  1041. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1042. bill_entity.shopName = GetPostString("ShopName");
  1043. bill_entity.applymemo = GetPostString("applyMemo");
  1044. bill_entity.createTime = DateTime.Now;
  1045. bill_entity.state = 0;
  1046. bill_entity.userId = 11;
  1047. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1048. bill_entity.Create();
  1049. }
  1050. catch (Exception ex)
  1051. {
  1052. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1053. returnErrorMsg("创建发票出错!");
  1054. return;
  1055. }
  1056. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1057. returnSuccessMsg("发票申请成功!");
  1058. return;
  1059. }
  1060. returnErrorMsg("找不到记录");
  1061. }
  1062. }
  1063. /**
  1064. * 查货
  1065. * ctid
  1066. * name
  1067. **/
  1068. public void ins_checkorder()
  1069. {
  1070. if (UrlPostParmsCheck("ctid"))
  1071. {
  1072. string ctid = GetPostString("ctid");
  1073. string name = GetPostString("name");
  1074. int UserID = GetPostInt("UserID");
  1075. CeErpTradeCell entity = null;
  1076. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1077. if (entity != null)
  1078. {
  1079. if (entity.OrderState < 6)
  1080. {
  1081. returnErrorMsg("下单完成后才可查货");
  1082. return;
  1083. }
  1084. if (entity.OrderState > 6)
  1085. {
  1086. returnErrorMsg("订单已发货");
  1087. return;
  1088. }
  1089. if (entity.FinishPlaceTime != null)
  1090. {
  1091. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  1092. {
  1093. returnErrorMsg("下单时间不足,无法查货");
  1094. return;
  1095. }
  1096. }
  1097. entity.MemoOpt = 3;
  1098. entity.CheckOrderTime = DateTime.Now;
  1099. entity.Update();
  1100. LogHelper.addLog(entity.ctid, UserID, name + "标记:查货", entity.OrderState, 1);
  1101. returnSuccessMsg("操作成功!");
  1102. return;
  1103. }
  1104. returnErrorMsg("找不到记录");
  1105. return;
  1106. }
  1107. returnErrorMsg("缺少必要的参数ctid");
  1108. }
  1109. public void ins_checkdesign()
  1110. {
  1111. if (UrlPostParmsCheck("ctid"))
  1112. {
  1113. string ctid = GetPostString("ctid");
  1114. string name = GetPostString("name");
  1115. int UserID = GetPostInt("UserID");
  1116. int memoopt = GetPostInt("memoopt");
  1117. CeErpTradeCell entity = null;
  1118. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1119. if (entity != null)
  1120. {
  1121. string stropt = "";
  1122. if (memoopt == 1)
  1123. {
  1124. stropt = "“改稿”";
  1125. }
  1126. else if (memoopt == 2)
  1127. {
  1128. stropt = "“定稿”";
  1129. }
  1130. entity.MemoOpt = memoopt;
  1131. entity.Update();
  1132. LogHelper.addLog(entity.ctid, UserID, name + "标记:" + stropt, entity.OrderState, 1);
  1133. returnSuccessMsg("操作成功!");
  1134. return;
  1135. }
  1136. returnErrorMsg("找不到记录");
  1137. return;
  1138. }
  1139. returnErrorMsg("缺少必要的参数ctid");
  1140. }
  1141. public void save_othermemo()
  1142. {
  1143. if (UrlPostParmsCheck("ctid"))
  1144. {
  1145. string ctid = GetPostString("ctid");
  1146. string name = GetPostString("name");
  1147. int UserID = GetPostInt("UserID");
  1148. CeErpTradeCell entity = null;
  1149. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1150. if (entity != null)
  1151. {
  1152. entity.OtherMemo = GetPostString("otherMemo");
  1153. entity.Update();
  1154. returnSuccessMsg("保存成功!");
  1155. LogHelper.addLog(entity.ctid, UserID, name + "额外:" + entity.OtherMemo, entity.OrderState);
  1156. return;
  1157. }
  1158. returnErrorMsg("找不到记录");
  1159. return;
  1160. }
  1161. returnErrorMsg("缺少必要的参数ctid");
  1162. }
  1163. public void save_customermemo()
  1164. {
  1165. if (UrlPostParmsCheck("ctid"))
  1166. {
  1167. string ctid = GetPostString("ctid");
  1168. CeErpTradeCell entity = null;
  1169. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1170. if (entity != null)
  1171. {
  1172. entity.CustomerMemo = GetPostString("CustomerMemo");
  1173. entity.Update();
  1174. ApiVo apiVo = new ApiVo();
  1175. apiVo.orderNumber = entity.ctid;
  1176. apiVo.actionName = "followRemarks";
  1177. apiVo.orderRemarks = entity.CustomerMemo;
  1178. designHelper.API_WorkCore(apiVo);//followRemarks
  1179. returnSuccessMsg("保存成功!");
  1180. return;
  1181. }
  1182. returnErrorMsg("找不到记录");
  1183. }
  1184. }
  1185. public void create_order()
  1186. {
  1187. if (UrlPostParmsCheck("data"))
  1188. {
  1189. string data = GetPostString("data");
  1190. Api_trade_info info = null;
  1191. try
  1192. {
  1193. info = JsonConvert.DeserializeObject<Api_trade_info>(data);
  1194. }
  1195. catch (Exception ex)
  1196. {
  1197. XLog.SaveLog(0, "create_order|1|" + ex.Message);
  1198. returnErrorMsg(ex.Message);
  1199. return;
  1200. }
  1201. if (info == null)
  1202. {
  1203. XLog.SaveLog(0, "Api_trade_info isNull");
  1204. return;
  1205. }
  1206. BizOrder bizOrder = info.bizOrder;
  1207. if (bizOrder == null)
  1208. {
  1209. returnErrorMsg("接口对象处理错误bizOrder=null");
  1210. return;
  1211. }
  1212. bool isCreate = false;
  1213. CeErpTrade trade = null;
  1214. trade = CeErpTrade.Get(bizOrder.thirdOrderId);
  1215. if (trade == null)
  1216. {
  1217. isCreate = true;
  1218. }
  1219. List<tempResponse> callResult = null;
  1220. try
  1221. {
  1222. trade = createTradeOrder(bizOrder, trade, isCreate);
  1223. List<Api_trade_info.TradeItemOrder> orderList = bizOrder.bizOrderItems;
  1224. createItemOrder(orderList, trade);
  1225. List<Api_trade_info.bizOrderSplit> bizOrderSplit = bizOrder.bizOrderSplits;
  1226. callResult = createCellOrder(bizOrderSplit, trade, isCreate);
  1227. }
  1228. catch (Exception ex)
  1229. {
  1230. XLog.SaveLog(0, "create_order|2|" + ex);
  1231. returnErrorMsg(ex.Message);
  1232. return;
  1233. }
  1234. returnSuccessMsg(JsonConvert.SerializeObject(callResult));
  1235. return;
  1236. }
  1237. returnErrorMsg("缺少必要的参数data");
  1238. }
  1239. public void refundOrder()
  1240. {
  1241. if (UrlPostParmsCheck("data"))
  1242. {
  1243. string data = GetPostString("data");
  1244. Api_refund_info info = null;
  1245. try
  1246. {
  1247. info = JsonConvert.DeserializeObject<Api_refund_info>(data);
  1248. }
  1249. catch (Exception ex)
  1250. {
  1251. XLog.SaveLog(0, "refundOrder|4|" + ex.Message);
  1252. returnErrorMsg(ex.Message);
  1253. return;
  1254. }
  1255. if (info == null)
  1256. {
  1257. XLog.SaveLog(0, "Api_refund_info isNull");
  1258. returnErrorMsg("接口对象处理错误RefundOrder=null1");
  1259. return;
  1260. }
  1261. RefundOrder refundOrder = info.refundOrder;
  1262. if (refundOrder == null)
  1263. {
  1264. returnErrorMsg("接口对象处理错误RefundOrder=null2");
  1265. return;
  1266. }
  1267. CeErpTrade trade = CeErpTrade.Get(refundOrder.tid);
  1268. if (trade != null)
  1269. {
  1270. CeErpTradeRefund refund = CeErpTradeRefund.GetByOidAndReId(refundOrder.ctid, refundOrder.orderSn);
  1271. LogHelper.addLog(refundOrder.ctid, 0, "客户退款", 0);
  1272. if (refund == null)
  1273. {
  1274. refund = new CeErpTradeRefund();
  1275. refund.refund_id = refundOrder.orderSn;
  1276. refund.tid = refundOrder.tid;
  1277. refund.oid = refundOrder.ctid;
  1278. if (refundOrder.createTime != null && refundOrder.createTime.Length > 0)
  1279. {
  1280. refund.created = Convert.ToDateTime(refundOrder.createTime);
  1281. }
  1282. if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
  1283. {
  1284. refund.modified = Convert.ToDateTime(refundOrder.updateTime);
  1285. }
  1286. refund.status = refundOrder.status;
  1287. refund.order_status = refundOrder.orderStatus;
  1288. refund.payment = refundOrder.payment.ToString();
  1289. refund.refund_fee = refundOrder.refundFee;//退款金额
  1290. refund.buyer_nick = GetNull_tostring(refundOrder.openBuyerNick);
  1291. refund.seller_nick = refundOrder.seller_nick;
  1292. refund.total_fee = refundOrder.totalFee;
  1293. refund.RefundState = 1;
  1294. refund.reason = refundOrder.reason;
  1295. refund.refundDesc = refundOrder.desc;
  1296. refund.IsPartRefund = refundOrder.isPartRefund;
  1297. refund.Create();
  1298. try
  1299. {
  1300. StringBuilder CeErpTradeCellSql = new StringBuilder();
  1301. CeErpTradeCellSql.AppendFormat("select * from CE_ErpTradeCell where ctid='{0}';", refundOrder.ctid);
  1302. DataSet cell = DbHelper.DbConn.ExecuteDataset(CeErpTradeCellSql.ToString());
  1303. DataTable datatable = cell.Tables[0];
  1304. if (datatable.Rows.Count > 0)
  1305. {
  1306. foreach (DataRow dr in datatable.Rows)
  1307. {
  1308. int DesignUserId = Convert.ToInt32(dr["DesignUserId"]);
  1309. int OrderState = Convert.ToInt32(dr["OrderState"]);
  1310. int CustomerUserId = Convert.ToInt32(dr["CustomerUserId"]);
  1311. if (DesignUserId > 0 && OrderState == 4)
  1312. {
  1313. createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, DesignUserId, 1);
  1314. }
  1315. if (CustomerUserId > 0)
  1316. {
  1317. createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, CustomerUserId, 1);
  1318. }
  1319. }
  1320. }
  1321. }
  1322. catch (Exception ex)
  1323. {
  1324. XLog.SaveLog(0, "退款推送通知创建失败!!" + ex);
  1325. }
  1326. int rstate = commonHelper.getRefundTagByState(refundOrder.status);
  1327. StringBuilder sql = new StringBuilder();
  1328. if (refund.IsPartRefund == 1)
  1329. {
  1330. double paylast = Convert.ToDouble(refundOrder.payment) - Convert.ToDouble(refund.refund_fee);
  1331. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1},payment={2} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 3, paylast);
  1332. }
  1333. else
  1334. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, rstate);
  1335. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1336. string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
  1337. //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  1338. StringBuilder sqls = new StringBuilder();
  1339. sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
  1340. CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
  1341. LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
  1342. }
  1343. else
  1344. {
  1345. if (refund.status != refundOrder.status)
  1346. {
  1347. refund.modified = DateTime.Now;
  1348. if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
  1349. {
  1350. refund.modified = Convert.ToDateTime(refundOrder.updateTime);
  1351. }
  1352. refund.order_status = refundOrder.orderStatus;
  1353. refund.status = refundOrder.status;
  1354. refund.Update();
  1355. int rstate = commonHelper.getRefundTagByState(refundOrder.status);
  1356. string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
  1357. StringBuilder sql = new StringBuilder();
  1358. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={0} where ctid='{1}' and isAfterSaleOrder=0;", rstate, refundOrder.ctid);
  1359. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1360. //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  1361. LogHelper.addLog(refundOrder.tid, 0, "更新退款状态:" + rstateWord, (int)OrderState.交易关闭);
  1362. // 取消设计费
  1363. StringBuilder sqls = new StringBuilder();
  1364. sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
  1365. CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
  1366. LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
  1367. }
  1368. }
  1369. List<RefundItemOrder> goodsItems = refundOrder.goodsItems;
  1370. foreach (RefundItemOrder item in goodsItems)
  1371. {
  1372. CeErpTradeOrder goods = CeErpTradeOrder.GetByOid(item.refOlId);
  1373. if (goods != null)
  1374. {
  1375. goods.refund_status = item.refundStatus;
  1376. goods.Update();
  1377. }
  1378. }
  1379. if (refundOrder.status == "WAIT_SELLER_AGREE")
  1380. {
  1381. StringBuilder sql = new StringBuilder();
  1382. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 1);
  1383. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1384. designHelper.API_refundOrder(refundOrder.tid, "refundIng", refundOrder.reason);
  1385. LogHelper.addLog(refundOrder.tid, 0, "申请退款中", 0);
  1386. }
  1387. else if (refundOrder.status == "CLOSED")
  1388. {
  1389. StringBuilder sql = new StringBuilder();
  1390. sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 0);
  1391. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1392. designHelper.API_refundOrder(refundOrder.tid, "refundCancel", refundOrder.reason);
  1393. LogHelper.addLog(refundOrder.tid, 0, "关闭申请退款中", 0);
  1394. }
  1395. else if (refundOrder.status == "REFUNDED" || refundOrder.status == "SUCCESS")
  1396. {
  1397. designHelper.API_refundOrder(refundOrder.tid, "refundEd", refundOrder.reason);
  1398. }
  1399. }
  1400. else
  1401. {
  1402. }
  1403. }
  1404. returnErrorMsg("缺少必要的参数data");
  1405. }
  1406. public void createRefundMessage(string ctid, MessageState messageState, int userId, int type)
  1407. {
  1408. CeErpMessageTip ceErpMessageTip = new CeErpMessageTip();
  1409. ceErpMessageTip.tid = ctid;
  1410. ceErpMessageTip.type = Convert.ToInt32(messageState);
  1411. ceErpMessageTip.userId = userId;
  1412. ceErpMessageTip.isVisit = false;
  1413. ceErpMessageTip.content = "订单" + ctid + "申请了退款!";
  1414. ceErpMessageTip.Create();
  1415. StringBuilder sqlTip = new StringBuilder();
  1416. if (type == 1)
  1417. {
  1418. 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);
  1419. }
  1420. if (type == 2)
  1421. {
  1422. 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);
  1423. }
  1424. DataTable dth = DbHelper.DbConn.ExecuteDataset(sqlTip.ToString()).Tables[0];
  1425. if (dth.Rows.Count > 0)
  1426. {
  1427. foreach (DataRow dthdr in dth.Rows)
  1428. {
  1429. int Bid = Convert.ToInt32(dthdr["id"]);
  1430. if (Bid > 0)
  1431. {
  1432. CeErpMessageTip ceErpMessageTipB = new CeErpMessageTip();
  1433. ceErpMessageTipB.tid = ctid;
  1434. ceErpMessageTipB.type = Convert.ToInt32(messageState);
  1435. ceErpMessageTipB.userId = Bid;
  1436. ceErpMessageTipB.isVisit = false;
  1437. ceErpMessageTipB.content = "订单" + ctid + "申请了退款!";
  1438. ceErpMessageTipB.Create();
  1439. }
  1440. }
  1441. }
  1442. }
  1443. public List<tempResponse> createCellOrder(List<Api_trade_info.bizOrderSplit> bizOrderSplit, CeErpTrade trade, bool isCreate)
  1444. {
  1445. List<tempResponse> tempResponses = new List<tempResponse>();
  1446. CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
  1447. foreach (Api_trade_info.bizOrderSplit item in bizOrderSplit)
  1448. {
  1449. bool create = false;
  1450. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(item.splitNo);
  1451. if (entity == null)
  1452. {
  1453. entity = new CeErpTradeCell();
  1454. create = true;
  1455. entity.tid = trade.tid;
  1456. entity.pay_time = trade.pay_time;
  1457. }
  1458. if (entity.OrderState > 4)
  1459. {
  1460. continue;
  1461. }
  1462. entity.ctid = item.splitNo;
  1463. entity.seller_memo = item.systemRemark;
  1464. if (!string.IsNullOrEmpty(item.splitAmount))
  1465. {
  1466. entity.payment = Convert.ToDouble(item.splitAmount);
  1467. }
  1468. if (!string.IsNullOrEmpty(item.splitAmount))
  1469. {
  1470. entity.AfterSalePayment = Convert.ToDouble(item.splitAmount);
  1471. }
  1472. if (!string.IsNullOrEmpty(item.sfMark))
  1473. {
  1474. entity.IsSF = Convert.ToInt32(item.sfMark);
  1475. }
  1476. entity.ProductSize = item.size;
  1477. entity.Material = item.material;
  1478. entity.CustomerUserId = item.erpCustomerServiceId;
  1479. //entity.Craft = item.craft;
  1480. entity.ProductCount = item.productQuantity;
  1481. entity.ProductId = tmcHelper.getProductIdByName(item.cate3Id);
  1482. if (!string.IsNullOrEmpty(item.internalStatus))
  1483. {
  1484. entity.OrderState = Convert.ToInt32(item.internalStatus);
  1485. }
  1486. entity.IsUrgency = item.isUrgent;
  1487. entity.ptid = item.ptid;
  1488. entity.SplitTag = item.splitInfoNo;
  1489. if (!string.IsNullOrEmpty(item.paymentFile))
  1490. {
  1491. entity.PayProofImg = item.paymentFile;
  1492. }
  1493. if (item.shippingTime != null && item.shippingTime.Length > 0)
  1494. {
  1495. entity.UnusualTime = Convert.ToDateTime(item.shippingTime);
  1496. entity.UrgencyTime = Convert.ToDateTime(item.shippingTime);
  1497. }
  1498. if (!string.IsNullOrEmpty(item.sendGiftMark))
  1499. {
  1500. entity.IsSendGift = Convert.ToInt32(item.sendGiftMark);
  1501. }
  1502. entity.OtherMemo = item.otherRemark;
  1503. entity.IsOldCustomer = item.isRepurchase ? 1 : 0;
  1504. entity.IsOldCustomerMore = item.isOldCustomerMore;
  1505. entity.MemoOpt = item.memoOpt;
  1506. entity.isDianziOrder = item.isDianziOrder;
  1507. if (item.isPreShipping != null && item.isPreShipping.Length > 0)
  1508. {
  1509. entity.IsPreDelivery = Convert.ToInt32(item.isPreShipping);
  1510. }
  1511. if (item.checkOrderTime != null && item.checkOrderTime.Length > 0)
  1512. {
  1513. entity.CheckOrderTime = Convert.ToDateTime(item.checkOrderTime);
  1514. }
  1515. int shopId = 0;
  1516. if (nShop != null)
  1517. {
  1518. shopId = nShop.ID;
  1519. }
  1520. entity.ShopId = shopId;
  1521. entity.OrderSn = item.OrderSn;
  1522. entity.ParentSplitNo = item.parentSplitNo;
  1523. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1524. if (ceErpTradeCellExtend == null)
  1525. {
  1526. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  1527. ceErpTradeCellExtend.ctid = entity.ctid;
  1528. }
  1529. ceErpTradeCellExtend.cate1 = item.cate1;
  1530. ceErpTradeCellExtend.cate2 = item.cate2;
  1531. ceErpTradeCellExtend.scene = item.scene;
  1532. ceErpTradeCellExtend.material = item.material;
  1533. ceErpTradeCellExtend.offerAmount = item.offerAmount;
  1534. ceErpTradeCellExtend.numbers = item.numbers;
  1535. ceErpTradeCellExtend.typeScene = item.typeScene;
  1536. ceErpTradeCellExtend.opScene = item.opScene;
  1537. ceErpTradeCellExtend.craft = item.craft;
  1538. ceErpTradeCellExtend.numberType = item.numberType;
  1539. ceErpTradeCellExtend.cate1Id = item.cate1Id;
  1540. ceErpTradeCellExtend.cate2Id = item.cate2Id;
  1541. ceErpTradeCellExtend.cate3Id = item.cate3Id;
  1542. ceErpTradeCellExtend.sceneId = item.sceneId;
  1543. ceErpTradeCellExtend.typeSceneId = item.typeSceneId;
  1544. ceErpTradeCellExtend.opSceneId = item.opSceneId;
  1545. ceErpTradeCellExtend.materialId = item.materialId;
  1546. ceErpTradeCellExtend.width = item.width;
  1547. ceErpTradeCellExtend.height = item.height;
  1548. ceErpTradeCellExtend.length = item.length;
  1549. ceErpTradeCellExtend.recSize = item.recSize;
  1550. ceErpTradeCellExtend.sizeUnit = item.sizeUnit;
  1551. ceErpTradeCellExtend.numberUnit = item.numberUnit;
  1552. ceErpTradeCellExtend.orderFrom = 30;
  1553. ceErpTradeCellExtend.spu_id = item.spuId;
  1554. ceErpTradeCellExtend.quantity = item.quantity;
  1555. ceErpTradeCellExtend.discountAmount = item.discountAmount;
  1556. ceErpTradeCellExtend.differentAmount = item.compensateAmount;
  1557. ceErpTradeCellExtend.differentSplitNo = item.compensateSplitOrderUniqueNo;
  1558. ceErpTradeCellExtend.orderType = item.orderType;
  1559. ceErpTradeCellExtend.parentOrderSn = item.parentSplitNo;
  1560. if (ceErpTradeCellExtend.ID > 0)
  1561. {
  1562. ceErpTradeCellExtend.Update();
  1563. }
  1564. else
  1565. {
  1566. ceErpTradeCellExtend.Create();
  1567. }
  1568. if (item.isGift == 1)
  1569. {
  1570. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  1571. entity.IsXianHuo = 1;
  1572. entity.IsGift = 1;
  1573. entity.FinishPlaceTime = trade.pay_time;
  1574. if (entity.OrderState < 6)
  1575. {
  1576. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1577. }
  1578. }
  1579. if (item.isSpot)
  1580. {
  1581. if (entity.OrderState < 6)
  1582. {
  1583. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  1584. }
  1585. entity.seller_memo = item.systemRemark;
  1586. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1587. entity.IsXianHuo = 1;
  1588. entity.FinishPlaceTime = entity.pay_time;
  1589. if (item.systemRemark.IndexOf("封酒贴") != -1)
  1590. {
  1591. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  1592. if (trade.buyer_memo != "")
  1593. {
  1594. entity.OrderState = 2;
  1595. entity.ProductId = 1;
  1596. entity.IsXianHuo = 0;
  1597. item.systemRemark = item.systemRemark.Replace("现货", "");
  1598. item.systemRemark = item.systemRemark.Replace(" ", "");
  1599. entity.seller_memo = item.systemRemark;
  1600. if (entity.ShopId != 0)
  1601. {
  1602. entity.OrderState = orderAudit(entity.ShopId);
  1603. }
  1604. }
  1605. }
  1606. else if (item.systemRemark.IndexOf("#") != -1)
  1607. {
  1608. entity.SupplierId = 87;
  1609. }
  1610. else if (item.systemRemark.IndexOf("喜字贴") != -1)
  1611. {
  1612. entity.SupplierId = 70;
  1613. }
  1614. else if (item.systemRemark.IndexOf("兔团团") != -1)
  1615. {
  1616. entity.SupplierId = 101;
  1617. }
  1618. else if (item.systemRemark.IndexOf("手拉旗") != -1)
  1619. {
  1620. entity.SupplierId = 108;
  1621. }
  1622. try
  1623. {
  1624. string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
  1625. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  1626. List<Dictionary<string, string>> material_list = new List<Dictionary<string, string>>();
  1627. List<Dictionary<string, string>> name_list = new List<Dictionary<string, string>>();
  1628. foreach (DataRow dr in goodsDt.Rows)
  1629. {
  1630. string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
  1631. List<string> xianhuo = sqlMemo.Split(',').ToList();
  1632. foreach (var val in xianhuo)
  1633. {
  1634. if (string.IsNullOrEmpty(val)) continue;
  1635. Dictionary<string, string> material_map = new Dictionary<string, string>();//材质
  1636. Dictionary<string, string> name_map = new Dictionary<string, string>();//特殊名称
  1637. if (val.IndexOf('-') > -1)
  1638. {
  1639. List<string> list = val.Split('-').ToList();
  1640. material_map.Add(dr["id"].ToString(), list[0]);
  1641. name_map.Add(dr["id"].ToString(), list[1]);
  1642. }
  1643. else
  1644. {
  1645. material_map.Add(dr["id"].ToString(), val);
  1646. }
  1647. material_list.Add(material_map);
  1648. name_list.Add(name_map);
  1649. }
  1650. }
  1651. List<string> materials = new List<string>();
  1652. List<string> names = new List<string>();
  1653. List<string> result = new List<string>();
  1654. for (int i = 0; i < material_list.Count; i++)
  1655. {
  1656. Dictionary<string, string> map = material_list[i];
  1657. foreach (var val in map)
  1658. {
  1659. if (item.systemRemark.IndexOf(val.Value) > -1)
  1660. {
  1661. Dictionary<string, string> map2 = name_list[i];
  1662. if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
  1663. {
  1664. foreach (var item1 in map2)
  1665. {
  1666. if (item.systemRemark.IndexOf(item1.Value) > -1)
  1667. {
  1668. names.Add(item1.Key);
  1669. materials.Add(val.Key);
  1670. }
  1671. }
  1672. }
  1673. else
  1674. {
  1675. materials.Add(val.Key);
  1676. }
  1677. }
  1678. }
  1679. }
  1680. if (names.Count > 0)//特殊名称有只先在特殊名称里选择
  1681. {
  1682. result = names.Distinct().ToList();
  1683. }
  1684. else
  1685. {
  1686. result = materials.Distinct().ToList();
  1687. }
  1688. if (result.Count > 0)
  1689. {
  1690. Random rnd = new Random();
  1691. int index = rnd.Next(result.Count);
  1692. entity.SupplierId = int.Parse(result[index]);
  1693. }
  1694. }
  1695. catch (Exception e)
  1696. {
  1697. XLog.SaveLog(0, "|现货匹配|" + e.Message);
  1698. }
  1699. }
  1700. if (isCreate)
  1701. {
  1702. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  1703. if (oldRes > 0)
  1704. {
  1705. //entity.IsOldCustomer = 1;
  1706. //if (oldRes == 2) entity.IsOldCustomerMore = 1;
  1707. }
  1708. }
  1709. if (item.sampleMark == "1")
  1710. {
  1711. entity.IsSample = 1;
  1712. entity.OrderState = 6;
  1713. entity.FinishPlaceTime = DateTime.Now;
  1714. entity.IsOldCustomer = 0;
  1715. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1716. }
  1717. if (item.sampleMark == "3")
  1718. {
  1719. entity.IsSample = 3;
  1720. entity.OrderState = 6;
  1721. entity.FinishPlaceTime = DateTime.Now;
  1722. entity.IsOldCustomer = 0;
  1723. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1724. }
  1725. if (item.sampleMark == "2" && !string.IsNullOrEmpty(item.parentSplitNo))
  1726. {
  1727. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(item.parentSplitNo);
  1728. if (ceErpTradeCell != null)
  1729. {
  1730. entity.CustomerUserId = ceErpTradeCell.CustomerUserId;
  1731. entity.DesignUserId = ceErpTradeCell.DesignUserId;
  1732. entity.SupplierId = ceErpTradeCell.SupplierId;
  1733. entity.IsSample = 2;
  1734. entity.WaitDesignTime = ceErpTradeCell.WaitDesignTime;
  1735. entity.StartDesignTime = ceErpTradeCell.StartDesignTime;
  1736. entity.FinishDesignTime = ceErpTradeCell.FinishDesignTime;
  1737. entity.FinishPlaceTime = ceErpTradeCell.FinishPlaceTime;
  1738. }
  1739. CeErpTradeCellExtend parentCell = CeErpTradeCellExtend.getByTid(item.parentSplitNo);
  1740. if (parentCell == null)
  1741. {
  1742. parentCell = new CeErpTradeCellExtend();
  1743. parentCell.ctid = item.parentSplitNo;
  1744. }
  1745. if (!string.IsNullOrEmpty(item.splitAmount))
  1746. {
  1747. parentCell.differentAmount += Convert.ToDouble(item.splitAmount);
  1748. }
  1749. if (parentCell.ID > 0)
  1750. {
  1751. parentCell.Update();
  1752. }
  1753. else
  1754. {
  1755. parentCell.Create();
  1756. }
  1757. ApiVo apiVo = new ApiVo();
  1758. apiVo.orderNumber = entity.ptid;
  1759. apiVo.payment = entity.payment;
  1760. apiVo.actionName = "repairDesign";
  1761. designHelper.API_WorkCore(apiVo);//repairDesign
  1762. }
  1763. bool isCopyFile = false;
  1764. //老客户
  1765. if (item.isRepurchase)
  1766. {
  1767. if (item.isOldCustomer == 1)
  1768. {
  1769. tmcHelper.dealOldCustomerEntityTag(ref entity, trade);
  1770. }
  1771. if (item.isOldCustomer == 3)
  1772. {
  1773. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  1774. entity.WaitDesignTime = DateTime.Now;
  1775. isCopyFile = true;
  1776. }
  1777. if (item.isOldCustomer == 2)
  1778. {
  1779. entity.OrderState = 3;
  1780. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  1781. entity.WaitDesignTime = DateTime.Now;
  1782. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  1783. }
  1784. }
  1785. if (create)
  1786. {
  1787. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "创建推送生成:" + entity.seller_memo, entity.OrderState);
  1788. entity.Create();
  1789. }
  1790. else
  1791. {
  1792. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "更新推送生成:" + entity.seller_memo, entity.OrderState);
  1793. designHelper.API_update_order(entity);
  1794. entity.Update();
  1795. }
  1796. if (isCopyFile)
  1797. {
  1798. apiUploaderResponse upResult = CopyDesignFile(entity.ctid, item.oldOrderSn, entity.CustomerUserId);
  1799. if (upResult == null || "error".Equals(upResult.type))
  1800. {
  1801. tempResponse response = new tempResponse();
  1802. response.flag = "1";
  1803. response.flagData = entity.ctid;
  1804. response.flagMsg = upResult == null ? "复制文件出错!" : upResult.result;
  1805. }
  1806. }
  1807. }
  1808. return tempResponses;
  1809. }
  1810. public void createItemOrder(List<Api_trade_info.TradeItemOrder> orderList, CeErpTrade trade)
  1811. {
  1812. foreach (Api_trade_info.TradeItemOrder item in orderList)
  1813. {
  1814. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.thirdOrderItemId);
  1815. bool isCreateOrder = false;
  1816. if (order == null)
  1817. {
  1818. order = new CeErpTradeOrder();
  1819. isCreateOrder = true;
  1820. order.oid = item.thirdOrderItemId;
  1821. order.tid = trade.tid;
  1822. order.buyer_nick = trade.buyer_nick;
  1823. }
  1824. order.refund_status = item.refundStatus;
  1825. order.status = trade.status;
  1826. order.title = item.title;
  1827. if (!string.IsNullOrEmpty(item.price))
  1828. {
  1829. order.price = Convert.ToDouble(item.price);
  1830. }
  1831. if (item.picUrl != null)
  1832. {
  1833. order.pic_path = item.picUrl;
  1834. }
  1835. if (!string.IsNullOrEmpty(item.num))
  1836. {
  1837. order.num = Convert.ToDouble(item.num);
  1838. }
  1839. if (!string.IsNullOrEmpty(item.totalAmount))
  1840. {
  1841. order.payment = Convert.ToDouble(item.totalAmount);
  1842. }
  1843. if (!string.IsNullOrEmpty(item.totalSellPrice))
  1844. {
  1845. order.total_fee = Convert.ToDouble(item.totalSellPrice);
  1846. }
  1847. //order.adjust_fee = Convert.ToDouble(item.price);
  1848. if (item.thirdSkuId != null && item.thirdSkuId != "")
  1849. {
  1850. order.sku_id = item.thirdSkuId;
  1851. }
  1852. if (item.specification != null && item.specification != "")
  1853. {
  1854. order.sku_properties_name = item.specification;
  1855. }
  1856. if (item.thirdSpuId != null && item.thirdSpuId != "")
  1857. {
  1858. order.spu_id = item.thirdSpuId;
  1859. }
  1860. if (isCreateOrder)
  1861. {
  1862. order.Create();
  1863. }
  1864. else
  1865. {
  1866. order.Update();
  1867. }
  1868. }
  1869. }
  1870. public CeErpTrade createTradeOrder(BizOrder bizOrder, CeErpTrade trade, bool isCreate)
  1871. {
  1872. if (trade == null)
  1873. { //新生成订单的
  1874. isCreate = true;
  1875. trade = new CeErpTrade();
  1876. trade.tid = bizOrder.thirdOrderId;
  1877. trade.type = bizOrder.orderPlatform;
  1878. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1879. {
  1880. trade.price = Convert.ToDouble(bizOrder.payAmount);
  1881. }
  1882. trade.discount_fee = 0;
  1883. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1884. {
  1885. trade.total_fee = Convert.ToDouble(bizOrder.payAmount);
  1886. }
  1887. if (bizOrder.orderTime != null && bizOrder.orderTime.Length > 0)
  1888. {
  1889. trade.created = Convert.ToDateTime(bizOrder.orderTime);
  1890. }
  1891. if (bizOrder.payTime != null && bizOrder.payTime.Length > 0)
  1892. {
  1893. trade.pay_time = Convert.ToDateTime(bizOrder.payTime);
  1894. }
  1895. trade.seller_nick = GetNull_tostring(bizOrder.openSellerNick);
  1896. if (!string.IsNullOrEmpty(bizOrder.payAmount))
  1897. {
  1898. trade.payment = Convert.ToDouble(bizOrder.payAmount);
  1899. }
  1900. }
  1901. trade.buyer_nick = GetNull_tostring(bizOrder.openBuyerNick);
  1902. trade.receiver_state = bizOrder.province;
  1903. if (!string.IsNullOrEmpty(bizOrder.num))
  1904. {
  1905. trade.num = Convert.ToDouble(bizOrder.num);
  1906. }
  1907. trade.receiver_city = bizOrder.city;
  1908. trade.receiver_address = GetNoNullValue_string(bizOrder.address);
  1909. trade.receiver_town = GetNoNullValue_string(bizOrder.receiverTown);
  1910. trade.receiver_district = GetNoNullValue_string(bizOrder.area);
  1911. trade.seller_flag = bizOrder.thirdFlag;
  1912. trade.orderType = bizOrder.orderType;
  1913. trade.orderFrom = 30;
  1914. trade.unrefundedAmount = bizOrder.unrefundedAmount;
  1915. if (bizOrder.modifyTime != null && bizOrder.modifyTime.Length > 0)
  1916. {
  1917. trade.modified = Convert.ToDateTime(bizOrder.modifyTime);
  1918. }
  1919. if (bizOrder.finishTime != null && bizOrder.finishTime.Length > 0)
  1920. {
  1921. trade.end_time = Convert.ToDateTime(bizOrder.finishTime);
  1922. }
  1923. if (bizOrder.shippingTime != null && bizOrder.shippingTime.Length > 0)
  1924. {
  1925. trade.delivery_time = Convert.ToDateTime(bizOrder.shippingTime);
  1926. }
  1927. if (bizOrder.confirmTime != null && bizOrder.confirmTime.Length > 0)
  1928. {
  1929. trade.confirmTime = Convert.ToDateTime(bizOrder.confirmTime);
  1930. }
  1931. trade.buyer_memo = GetNoNullValue_string(bizOrder.buyerRemark);
  1932. bool isSellerMemoChange = false;
  1933. //备注修改
  1934. bizOrder.sellerRemark = GetNoNullValue_string(bizOrder.sellerRemark);
  1935. if (trade.seller_memo != bizOrder.sellerRemark || trade.seller_memo.Length != bizOrder.sellerRemark.Length)
  1936. {
  1937. isSellerMemoChange = true;
  1938. }
  1939. trade.status = bizOrder.status;
  1940. trade.seller_memo = bizOrder.sellerRemark;
  1941. trade.buyer_id = bizOrder.openBuyerId;
  1942. trade.posCode = bizOrder.shopCode;
  1943. if (isCreate)
  1944. {
  1945. trade.Create();
  1946. }
  1947. else
  1948. {
  1949. if (bizOrder.status == "CLOSE")
  1950. {
  1951. trade.consign_time = DateTime.Now;
  1952. }
  1953. trade.Update();
  1954. }
  1955. try
  1956. {
  1957. if (bizOrder.status == "CLOSE" || bizOrder.status == "CANCEL")
  1958. {
  1959. StringBuilder sql = new StringBuilder();
  1960. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, bizOrder.thirdOrderId);
  1961. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1962. ApiVo apiVo = new ApiVo();
  1963. apiVo.actionName = "closeDesign";
  1964. apiVo.orderNumber = bizOrder.thirdOrderId;
  1965. //designHelper.API_WorkCore(apiVo);//closeDesign
  1966. LogHelper.addLog(bizOrder.thirdOrderId, 0, "交易关闭", (int)OrderState.交易关闭);
  1967. // commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
  1968. // removeOldCustomerInfo(trade);
  1969. }
  1970. else if (bizOrder.status == "COMPLETE")
  1971. {
  1972. StringBuilder sql = new StringBuilder();
  1973. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, bizOrder.thirdOrderId);
  1974. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1975. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
  1976. }
  1977. else if (bizOrder.status == "SHIPPED")//已发货
  1978. {
  1979. StringBuilder sql = new StringBuilder();
  1980. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, bizOrder.thirdOrderId);
  1981. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1982. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
  1983. }
  1984. }
  1985. catch (Exception ex)
  1986. {
  1987. XLog.SaveLog(0, bizOrder.thirdOrderId + "shipped:" + ex.Message);
  1988. throw ex;
  1989. }
  1990. return trade;
  1991. }
  1992. public static apiUploaderResponse CopyDesignFile(string ctid, string oldCtid, int userId)
  1993. {
  1994. string post_url = "http://183.250.143.56:8088/autocopy.aspx";
  1995. WebClient wc = new WebClient();
  1996. wc.Encoding = Encoding.GetEncoding("utf-8");
  1997. //json参数
  1998. NameValueCollection PostVars = new NameValueCollection();
  1999. PostVars.Add("hexdata", oldCtid + "," + ctid);
  2000. PostVars.Add("userid", userId.ToString());
  2001. apiUploaderResponse result = null;
  2002. try
  2003. {
  2004. byte[] ret = wc.UploadValues(post_url, "POST", PostVars);
  2005. string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret);
  2006. result = JsonConvert.DeserializeObject<apiUploaderResponse>(remoteInfo);
  2007. }
  2008. catch (Exception ex)
  2009. {
  2010. XLog.SaveLog(0, "CopyDesignFile:" + ex.Message);
  2011. }
  2012. return result;
  2013. }
  2014. public static DateTime StampToDateTime(string timeStamp)
  2015. {
  2016. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  2017. long lTime = long.Parse(timeStamp + "0000");
  2018. TimeSpan toNow = new TimeSpan(lTime);
  2019. return dateTimeStart.Add(toNow);
  2020. }
  2021. public static string GetNull_tostring(object value)
  2022. {
  2023. if (value == null)
  2024. {
  2025. return "";
  2026. }
  2027. return value.ToString();
  2028. }
  2029. public static string GetNoNullValue_string(string value)
  2030. {
  2031. if (value == null)
  2032. {
  2033. return "";
  2034. }
  2035. value = value.Replace("\n", " ");
  2036. value = value.Replace("\r", " ");
  2037. return value;
  2038. }
  2039. public static string getShopNameByECode(string code)
  2040. {
  2041. string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
  2042. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  2043. if (dt != null && dt.Rows.Count > 0)
  2044. {
  2045. return dt.Rows[0]["ShopName"].ToString();
  2046. }
  2047. return "";
  2048. }
  2049. public static int orderAudit(int shopId)
  2050. {
  2051. try
  2052. {
  2053. CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
  2054. if (ceErpShop == null) return 2;
  2055. if (!ceErpShop.orderAudit) return 2;
  2056. return -1;
  2057. }
  2058. catch (Exception ex)
  2059. {
  2060. return 2;
  2061. }
  2062. }
  2063. public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
  2064. {
  2065. if (father.seller_nick == "") return 0;
  2066. CeErpCustomer cus = null;
  2067. cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
  2068. if (cus == null)
  2069. {
  2070. cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
  2071. }
  2072. int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
  2073. if (cus != null)
  2074. {
  2075. if (cus.lastbuy_time.ToString() == "") return 0;
  2076. if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
  2077. cus.buyer_id = father.buyer_id;
  2078. if (cus.lastTid == father.tid)
  2079. {
  2080. if (pcount != cus.product_count)
  2081. {
  2082. cus.product_count = pcount;
  2083. cus.Update();
  2084. }
  2085. }
  2086. else
  2087. {
  2088. int returnNum = 0;
  2089. TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
  2090. cus.buy_day = Convert.ToInt32(tsday.TotalDays);
  2091. cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
  2092. cus.buy_count = cus.buy_count + 1;
  2093. cus.lastbuy_time2 = cus.lastbuy_time;
  2094. cus.buyer_id = father.buyer_id;
  2095. cus.lastbuy_time = father.pay_time;
  2096. int lastpCount = cus.product_count;
  2097. cus.product_count = pcount;
  2098. cus.lastTid2 = cus.lastTid;
  2099. cus.lastTid = father.tid;
  2100. if (cus.buy_day > 1)
  2101. {
  2102. if (pcount > lastpCount && cus.product_count != 0)
  2103. {
  2104. cus.isMore = 1;
  2105. returnNum = 2;
  2106. }
  2107. else
  2108. returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
  2109. }
  2110. else
  2111. returnNum = 0;
  2112. cus.Update();
  2113. return returnNum;
  2114. }
  2115. }
  2116. else
  2117. {
  2118. try
  2119. {
  2120. cus = new CeErpCustomer();
  2121. cus.buyer_nick = father.buyer_nick;
  2122. cus.seller_nick = father.seller_nick;
  2123. cus.buyer_id = father.buyer_id;
  2124. cus.buy_day = 0;
  2125. cus.buy_count = 1;
  2126. cus.lastbuy_time = father.pay_time;
  2127. cus.lastTid = father.tid;
  2128. cus.total_fee = Convert.ToDouble(father.payment);
  2129. cus.product_count = pcount;
  2130. cus.Create();
  2131. return 0;
  2132. }
  2133. catch (Exception ex)
  2134. {
  2135. XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
  2136. }
  2137. }
  2138. return 0;
  2139. }
  2140. }
  2141. }