PushController.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  1. using JCSoft.WX.Framework.Api;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.AspNetCore.Http;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using Common.Wechat;
  9. using Common;
  10. using System.Data;
  11. using ZcPeng.PublicLibrary;
  12. using CoreEntity.Entity;
  13. using Common.Model;
  14. using Newtonsoft.Json.Converters;
  15. using Newtonsoft.Json;
  16. using System.Data.SqlClient;
  17. using ZcPeng.weixin.PublicAccount;
  18. using CoreEntity.DAL;
  19. using PublicLibrary.Model;
  20. using Microsoft.Extensions.Caching.Memory;
  21. using CoreEntity.BAL;
  22. using static CoreEntity.BAL.PushBAL;
  23. using SupplierWeb.Codes.mvc;
  24. using SupplierWeb.Codes.Push;
  25. using CoreEntity.TimedTask;
  26. using System.Collections.Concurrent;
  27. using Microsoft.AspNetCore.Hosting;
  28. using static SupplierWeb.Controllers.NewGoodsController;
  29. using System.IO;
  30. using Npoi.Mapper;
  31. using LigerRM.Common;
  32. namespace SupplierWeb.Controllers
  33. {
  34. [Route("web/pushall")]
  35. public class PushController : BaseController
  36. {
  37. public PushController(IMemoryCache cache, IApiClient client) : base(cache, client)
  38. {
  39. }
  40. private ConcurrentDictionary<int, Role> roleMap = new ConcurrentDictionary<int, Role>();
  41. [AuthPermission]
  42. [HttpPost, Route("permissionRole")]
  43. public JsonResult PermissionRole(QueryFilter[] filters, String permissions, [FromBody]dynamic data)
  44. {
  45. string result;
  46. String roleids = "";
  47. if (data != null)
  48. {
  49. filters = data.filters.ToObject<QueryFilter[]>();
  50. permissions = data.temp;
  51. }
  52. #region 获取权限列表
  53. DataTable dt = new DataTable();
  54. IList<Permission> permss = new List<Permission>(0);
  55. List<SqlParameter> parameters = new List<SqlParameter>();
  56. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Permission(), "A.");
  57. #endregion
  58. if (dt != null && dt.Rows.Count > 0)
  59. {
  60. // 把DataTable转换为IList<Permission>
  61. permss = ModelConvertHelper<Permission>.ConvertToModel(dt);
  62. #region 获取权限的角色列表
  63. //角色列表
  64. IList<Role> roles = RoleDAL.GetRoles();
  65. // 把DataTable转换为IList<Role>
  66. if (roleMap.Count < roles.Count)
  67. {
  68. foreach (Role role in roles)
  69. {
  70. roleMap.TryAdd(role.Id, role);
  71. }
  72. }
  73. //for (var i = 0;i < )
  74. //{
  75. //}
  76. String permissionIds = permissions.Substring(0, permissions.Length - 1);
  77. string commonText = "select RO.roleId as roleId from " +
  78. Config.TablePrefix + "Permission A," +
  79. Config.TablePrefix + "RoleRelatePermission RP "
  80. + " WHERE 1=1 AND A.isdelete = '0' AND A.AuthType in('A','O') " +
  81. "and A.id = RP.PermissionId and A.id in (" + permissionIds + ")";
  82. bool success = DataAccess.GetValues(commonText, ref dt, parameters.ToArray(), out result);
  83. // 把DataTable转换为IList<RoleRelatePermission>
  84. if (dt != null && dt.Rows.Count > 0)
  85. {
  86. IList<RoleRelatePermission> permRelates = ModelConvertHelper<RoleRelatePermission>.ConvertToModel(dt);
  87. List<int> superior_list = new List<int>(0);
  88. foreach (RoleRelatePermission permsr in permRelates)
  89. {
  90. superior_list.Add(permsr.RoleId);
  91. }
  92. roleids = string.Join(",", superior_list.ToArray());
  93. }
  94. //}
  95. #endregion
  96. }
  97. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  98. {
  99. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  100. };
  101. var jsonData = JsonConvert.SerializeObject(permss, timejson);
  102. return Json(new
  103. {
  104. items = JsonConvert.DeserializeObject(jsonData),
  105. sum = new { },
  106. RoleId = roleids
  107. });
  108. }
  109. /// <summary>
  110. ////手动保存并推送:
  111. ///选出已经建立账户的供应商业务员推送
  112. /// </summary>
  113. /// <param name="Id">推送id</param>
  114. /// <param name="data"></param>
  115. /// <returns></returns>
  116. [AuthPermission]
  117. [HttpPost, Route("saveandpush")]
  118. public ActionResult SaveAndPush(
  119. //string Id,
  120. DateTime start,
  121. [FromBody]dynamic data)
  122. {
  123. string userids;
  124. string LoginAccountId = userids = getStaff("userid");
  125. string RoleId = getStaff("roleid");
  126. //判断参数是否合法
  127. if (string.IsNullOrEmpty(userids))
  128. {
  129. return Json(new
  130. {
  131. success = 0,
  132. msg="没有登陆"
  133. });
  134. }
  135. string[] goodsIds = null;
  136. PushContactWithGoods[] contacws = null;
  137. if (data != null)
  138. {
  139. //Newtonsoft.Json.Linq.JArray
  140. //Id = data.Id;
  141. goodsIds = data.goodsIds.ToObject<string[]>();
  142. contacws = data.contactws.ToObject<PushContactWithGoods[]>();
  143. }
  144. string filterlimit = "";
  145. string filtercont = "";
  146. //string filtercontact = "";
  147. //if (Id != null&& Id != "")
  148. //{
  149. // filterlimit =
  150. // "and GoodsId in (select GoodsId from "
  151. // + Config.TablePrefix+"PushFeedback where " +
  152. // "PushRecordId = "+Id+")";
  153. // filtercontact = " and exists (select 1 from "
  154. // + Config.TablePrefix + "PushFeedback where 1=1 " +
  155. // " and PushRecordId = " + Id + "" +
  156. // " and PushAccountId = UserId " +
  157. // ") ";
  158. //}
  159. if (goodsIds!=null && goodsIds.Length > 0)
  160. {
  161. string goodsIdStr = string.Join("','", goodsIds);
  162. filterlimit =
  163. " and GoodsId in ('" + goodsIdStr + "') ";
  164. string contactwgs = string.Join("','", contacws.Where(contact => (contact.ContactId != "" && contact.ContactId !=null)));
  165. filtercont =
  166. " and ContactId in ('" + contactwgs + "') ";
  167. }
  168. if (start != null && !start.ToString().StartsWith("0001"))
  169. {
  170. TimedProgram.RunProgram(start.Second.ToString(), start.Minute.ToString(), start.Hour.ToString(), RoleId, LoginAccountId,
  171. filterlimit,filtercont, _client).GetAwaiter().GetResult();
  172. }
  173. /*
  174. //获取推送上下限
  175. IList<PushStorLimit> pushLimits = PushRecordDAL.GetPushLimit(filterlimit);
  176. if(pushLimits.Count == 0)
  177. return Json(new
  178. {
  179. success = 0,
  180. result = "没有选择库存低于下限品种",
  181. });
  182. // 获取待推联系人 绑定账户 和微信
  183. string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId);
  184. string filterstr = filtercont+" and UserId IS NOT NULL and UserId !=''" +
  185. //" and FocusMicNo IS NOT NULL and FocusMicNo !='' " +
  186. FilterRuleByPur.getRolePermFilter(RoleId, " and SaleManId = '" + StaffDocId + "' ") //只查询当前采购员的联系人
  187. //+ filtercontact
  188. ;
  189. Dictionary<string, PushStorLimit> gapnum;
  190. List<PushContactWithGoods> GetPushContacts = ContactBAL.GetPushContactWithGoods( filterstr,"", pushLimits, out gapnum);
  191. //判断参数是否合法
  192. if (GetPushContacts.Count == 0)
  193. {
  194. return Json(new
  195. {
  196. success = 0,
  197. msg = "没有建立账户,或者业务员没有绑定"
  198. });
  199. }
  200. var result = PushBAL.pushAll(GetPushContacts, gapnum, LoginAccountId, _client);
  201. var codeids = result[result.Count - 1];
  202. Object Ids;
  203. codeids.TryGetValue("Ids",out Ids);
  204. List<String> ids = (List<String>)Ids;
  205. foreach (String recordId in ids)
  206. {
  207. CancelPushRecordTimedJob.CancelPushRecord(recordId,DateTime.Now, CancelPushRecordTimedJob.HoursToCancel);
  208. }
  209. */
  210. bool success = PushBAL.Push(LoginAccountId, RoleId,filterlimit,filtercont, out var result,_client);
  211. return Json(new
  212. {
  213. success = success,
  214. result = result,
  215. });
  216. }
  217. //自动推送
  218. [AuthPermission]
  219. [HttpPost, Route("push")]
  220. public ActionResult Push(
  221. DateTime start,
  222. [FromBody]dynamic data)
  223. {
  224. string userids;
  225. string LoginAccountId = userids = getStaff("userid");
  226. string RoleId = getStaff("roleid");
  227. //判断参数是否合法
  228. if (string.IsNullOrEmpty(userids))
  229. {
  230. return Json(new
  231. {
  232. success = 0,
  233. msg = "没有登陆"
  234. });
  235. }
  236. string[] goodsIds = null;
  237. PushContactWithGoods[] contacws = null;
  238. if (data != null)
  239. {
  240. //Newtonsoft.Json.Linq.JArray
  241. start = data.start;
  242. goodsIds = data.goodsIds.ToObject<string[]>();
  243. contacws = data.contactws.ToObject<PushContactWithGoods[]>();
  244. }
  245. string filterlimit = "";
  246. string filtercont = "";
  247. if (goodsIds != null && goodsIds.Length > 0)
  248. {
  249. string goodsIdStr = string.Join("','", goodsIds);
  250. filterlimit =
  251. " and GoodsId in ('" + goodsIdStr + "') ";
  252. string contactwgs = string.Join("','", contacws.Where(contact => (contact.ContactId != "" && contact.ContactId != null)));
  253. filtercont =
  254. " and ContactId in ('" + contactwgs + "') ";
  255. }
  256. TimedProgram.RunProgram(start.Second.ToString(), start.Minute.ToString(), start.Hour.ToString(), RoleId, LoginAccountId,
  257. filterlimit,filtercont,_client).GetAwaiter().GetResult();
  258. return Json(new
  259. {
  260. success = 1
  261. });
  262. }
  263. ////供应商业务员修改过的记录:手动保存并添加待推业务员:
  264. //[AuthPermission]
  265. //[HttpPost, Route("saveandrepush/{editpush}")]
  266. //public ActionResult SaveAndRePush(
  267. // string Id, string LoginAccountId,
  268. // DateTime start,
  269. // int editpush,
  270. // List<PushFeedbackExt> pfbs,
  271. // [FromBody]dynamic data)
  272. //{
  273. // string RecordId = string.Empty;
  274. // if (data != null)
  275. // {
  276. // //Newtonsoft.Json.Linq.JArray
  277. // Id = data.Id;
  278. // if (Id != null)
  279. // RecordId = Id;
  280. // LoginAccountId = data.LoginAccountId;
  281. // start = data.PushTime!=null? data.PushTime:DateTime.Now;
  282. // pfbs = data.pfbs.ToObject<PushFeedbackExt[]>();
  283. // }
  284. // //string userids;
  285. // //string LoginAccountId = userids = getStaffUserid(staffId);
  286. // //判断参数是否合法
  287. // if (string.IsNullOrEmpty(LoginAccountId))
  288. // {
  289. // return Json(new
  290. // {
  291. // success = 0,
  292. // msg = "没有登陆"
  293. // });
  294. // }
  295. // //if (start != null && !start.ToString().StartsWith("0001"))
  296. // //{
  297. // // TimedProgram.RunProgram(start.Second.ToString(), start.Minute.ToString(), start.Hour.ToString(), _client).GetAwaiter().GetResult();
  298. // //}
  299. // string filterlimit = "";
  300. // string filtercontact = "";
  301. // if (Id != null && Id != "")
  302. // {
  303. // filterlimit =
  304. // " and GoodsId in (select GoodsId from LJHYBZK.dbo."
  305. // + Config.TablePrefix + "PushFeedback where 1=1 " +
  306. // " and PushRecordId = '" + Id + "' " +
  307. // " and State IS NULL or State in (0,6,5)" +
  308. // ")";
  309. // filtercontact = " and exists (select 1 from "
  310. // + Config.TablePrefix + "PushFeedback A where 1=1 " +
  311. // " and A.PushRecordId = '" + Id + "' " +
  312. // " and State IS NULL or State in (0,6,5) " +
  313. // " and PushAccountId = UserId " +
  314. // " and A.GoodsId = GoodsId " +
  315. // ")";
  316. // }
  317. // //获取推送上下限
  318. // IList<PushStorLimit> pushLimits = PushRecordDAL.GetPushLimit(filterlimit);
  319. // string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId);
  320. // // 获取待推联系人 绑定账户 保存推送记录不需要绑定微信
  321. // string filterstr =
  322. // " and UserId IS NOT NULL and UserId !=''" +
  323. // //" and FocusMicNo IS NOT NULL and FocusMicNo !='' "+
  324. // //" and SaleManId = '"+StaffDocId+"' " +//只查询当前采购员的联系人
  325. // filtercontact;
  326. // Dictionary<string, PushStorLimit> gapnum;
  327. // List<PushContactWithGoods> GetPushContacts = ContactBAL.GetPushContactWithGoods(filterstr, ",t1.ContactId,t1.SuppliersId ", pushLimits, out gapnum);
  328. // //判断参数是否合法
  329. // if (GetPushContacts.Count == 0)
  330. // {
  331. // return Json(new
  332. // {
  333. // success = 0,
  334. // msg = "业务员没有绑定,或者没有建立账户"
  335. // });
  336. // }
  337. // DateTime EndTime = DateTime.Now.AddHours((double)24);
  338. // String loginAccountId = string.Empty;
  339. // string filter = "";
  340. // if (editpush == 0)
  341. // filter = " and State in (5,6) ";
  342. // else if(editpush == 1)
  343. // filter = " and State IS NULL or State = 0 " +
  344. // " ";
  345. // List<PushFeedbackExt> list = PushFeedBackDAL.GetFeedbacks(Id, filter);
  346. // PushRecord prec = PushRecordDAL.GetRecord(Id);
  347. // List<Object> result = new List<object>();
  348. // int successAll = 1;
  349. // foreach(PushFeedback feedback in list) {
  350. // int OldPushAccountId = feedback.PushAccountId;
  351. // int newPushAccountId = OldPushAccountId;
  352. // PushFeedback newpfb = null;
  353. // foreach (PushFeedback pfb in pfbs)
  354. // {
  355. // //根据userid 初始化PushAccountId SuppliersId
  356. // string[] ContactIds = pfb.ContactId.Split("_");
  357. // string PushAccountId = "";
  358. // if (ContactIds.Length > 2)
  359. // {
  360. // pfb.ContactId = ContactIds[0];
  361. // pfb.SuppliersId = ContactIds[1];
  362. // PushAccountId = ContactIds[3];
  363. // }
  364. // if(PushAccountId!=null&& PushAccountId != "")
  365. // pfb.PushAccountId = Convert.ToInt32(PushAccountId);
  366. // if (PushAccountId == ""|| PushAccountId==null)
  367. // {
  368. // return Json(new
  369. // {
  370. // success = 0,
  371. // msg = "业务员没有绑定,或者没有建立账户"
  372. // });
  373. // }
  374. // ////ContactDoc cdoc = AccountDAL.getContactor(pfb.ContactId);
  375. // //List<PushContactWithGoods> users = ContactBAL.GetPushContactWithGoods(
  376. // // " and ContactId in ('" + ContactId + "') " +
  377. // // " and GoodsId in ('" + pfb.GoodsId + "')", ",t1.ContactId,t1.SuppliersId",
  378. // // new List<PushStorLimit>(),
  379. // // out gapnum);
  380. // //PushContactWithGoods cdoc = null;
  381. // //if (users.Count > 0) {
  382. // // cdoc = users[0];
  383. // //}
  384. // //else
  385. // //{//contactid不合法
  386. // // return Json(new
  387. // // {
  388. // // success = 0,
  389. // // msg = "contactid不合法"
  390. // // });
  391. // //}
  392. // //if (cdoc.UserId!=null&& cdoc.UserId != "") {
  393. // // pfb.PushAccountId = Convert.ToInt32(cdoc.UserId);
  394. // // pfb.SuppliersId = cdoc.SuppliersId;
  395. // //}
  396. // if (pfb.Id.Equals(feedback.Id)) {
  397. // newpfb = pfb;
  398. // if ( pfb.PushAccountId != Convert.ToInt32(OldPushAccountId)
  399. // || pfb.SuppliersId != feedback.SuppliersId)
  400. // {
  401. // Message msg = TimeTask.sendSupplyMassMesage(_client,
  402. // Convert.ToInt32(feedback.PushAccountId),
  403. // pfb.PushRecordId.ToString(),
  404. // feedback.GoodsName,
  405. // feedback.StoreGapNum.ToString(),
  406. // feedback.PurPrice.ToString(),
  407. // EndTime);
  408. // newPushAccountId = pfb.PushAccountId;
  409. // result.Add(msg);
  410. // }
  411. // }
  412. // }
  413. // //添加或修改推送记录
  414. // IDictionary<string, Object> successs =
  415. // PushRecordDAL.AddOrUpdatePushFeedBack(
  416. // prec.PushCode,
  417. // Id
  418. // , feedback.Id.ToString(),
  419. // newPushAccountId,
  420. // newpfb.ContactId,
  421. // feedback.GoodsId, feedback.GoodsCode
  422. // , feedback.GoodsName, feedback.StoreGapNum
  423. // , feedback.GoodsSpec, feedback.Manufacturer
  424. // , feedback.BusinessId, feedback.BusinessCode, feedback.BusinessName
  425. // , feedback.SuppliersId, feedback.BrandName, feedback.BrandId
  426. // , feedback.EntId, feedback.Remark, LoginAccountId
  427. // , feedback.PurPrice
  428. // , feedback.ActPrice
  429. // , feedback.PurchaseTotalNum);
  430. // result.Add(successs);
  431. // Object successDT;
  432. // Object resultDT;
  433. // successs.TryGetValue("successRecord", out successDT);
  434. // successs.TryGetValue("resultRecord", out resultDT);
  435. // if (((string)resultDT).StartsWith("在执行数据操作时发生错误"))
  436. // {
  437. // successAll = 0;
  438. // }
  439. // }
  440. // if(successAll > 0)
  441. // {
  442. // #region 更新记录
  443. // string commandTextRecord = "UPDATE " + Config.TablePrefix + "PushRecord " +
  444. // " SET LastModifiedPerson = @LastModifiedPerson, " +
  445. // " State = 5 " +
  446. // " WHERE Id= @RecordId ";
  447. // string resultRecord;
  448. // //准备参数
  449. // List<List<Object>> parametersRecord = new List<List<Object>>();
  450. // parametersRecord.Add(new List<Object>() { "RecordId", Id });
  451. // parametersRecord.Add(new List<Object>() { "LastModifiedPerson", Convert.ToInt32(LoginAccountId) });
  452. // List<SqlParameter> parametersRecord1 = DataAccess.ToParameters(parametersRecord);
  453. // int successRecord = DataAccess.ExecuteCommand(commandTextRecord, parametersRecord1, out resultRecord);
  454. // #endregion
  455. // result.Add(successRecord);
  456. // result.Add(resultRecord);
  457. // }
  458. // return Json(new
  459. // {
  460. // success = successAll,
  461. // successAll = successAll,
  462. // result = result,
  463. // });
  464. //}
  465. ////修改过供应商的记录重推
  466. //[AuthPermission]
  467. //[HttpPost, Route("repush")]
  468. //public ActionResult RePush(string LoginAccountId,
  469. // DateTime start)
  470. //{
  471. // string filter = " and State in (5,6) ";
  472. // List<PushFeedbackExt> list = PushFeedBackDAL.GetFeedbacks(new List<SqlParameter>(), filter);
  473. // List<Object> result = new List<object>();
  474. // #region 更新记录
  475. // List<DataAccessCommand> listcmd = new List<DataAccessCommand>();
  476. // string resultFeed;
  477. // int successAll = 1;
  478. // DateTime EndTime = DateTime.Now.AddHours((double)24);
  479. // foreach (PushFeedbackExt feedback in list)
  480. // {
  481. // Message msg = TimeTask.sendSupplyMassMesage(_client,
  482. // Convert.ToInt32(feedback.PushAccountId),
  483. // feedback.PushRecordId.ToString(),
  484. // feedback.GoodsName,
  485. // feedback.StoreGapNum.ToString(),
  486. // feedback.PurPrice.ToString(),
  487. // EndTime);
  488. // result.Add(msg);
  489. // string commandTextFeed = "UPDATE " + Config.TablePrefix + "PushFeedback " +
  490. // " SET IsPush = @IsPush, " +
  491. // " WHERE Id= @Id AND (state in (5,6)) " +
  492. // " and IsPush = 0";
  493. // //准备参数
  494. // List<List<Object>> parametersFeed = new List<List<Object>>();
  495. // parametersFeed.Add(new List<Object>() { "Id", feedback.Id });
  496. // parametersFeed.Add(new List<Object>() { "IsPush", 1 });
  497. // List<SqlParameter> parametersFeed1 = DataAccess.ToParameters(parametersFeed);
  498. // listcmd.Add(new DataAccessCommand(commandTextFeed, parametersFeed1, CommandType.Text, true));
  499. // }
  500. // bool success = DataAccess.ExecuteBatchCommands(listcmd, out resultFeed);
  501. // #endregion
  502. // return Json(new
  503. // {
  504. // success = success,
  505. // successAll = successAll,
  506. // result = resultFeed,
  507. // });
  508. //}
  509. ///保存到采购计划
  510. [HttpPost, Route("savetoplan")]
  511. [AuthPermission]
  512. public ActionResult SaveToPlan(
  513. string Id
  514. , string LoginAccountId,
  515. //Int32 ReceiptMd, Int32 CentPayMd,
  516. PushFeedbackExt[] pfbs,
  517. string EntId,
  518. string OrgId,String DeptId,
  519. // DateTime RequestDate,
  520. [FromBody]dynamic data)
  521. {
  522. if (data != null)
  523. {
  524. //Newtonsoft.Json.Linq.JArray
  525. Id = data.Id;
  526. LoginAccountId = data.LoginAccountId;
  527. //ReceiptMd = data.ReceiptMd;
  528. //CentPayMd = data.CentPayMd;
  529. OrgId = data.OrgId;
  530. DeptId = data.DeptId;
  531. //RequestDate = data.RequestDate;
  532. pfbs = data.pfbs ==null? new PushFeedbackExt[] { } : data.pfbs.ToObject<PushFeedbackExt[]>();
  533. }
  534. //PushRecord rec = PushRecordDAL.GetRecord(Id);
  535. //int IsCompleteAll = 1;
  536. //if (IsCompleteAll == 1)
  537. // return Json(new
  538. // {
  539. // success = 0,
  540. // msg = "已经全部生成采购计划!"
  541. // });
  542. //List<PushFeedbackExt> listAll = PushFeedBackDAL.GetFeedbacks(Id);
  543. List<PushFeedbackExt> list = PushFeedBackDAL.GetFeedbacks(Id," and state in (1,2) ");
  544. //
  545. if(list == null)
  546. {
  547. return Json(new
  548. {
  549. success = 0,
  550. msg = "不能重复提交,已经全部生成采购计划!"
  551. });
  552. }
  553. Dictionary<string, List<PushFeedbackExt>> groups = new Dictionary<string, List<PushFeedbackExt>>();
  554. Dictionary<string, PushInfo> groupGoodsNames = new Dictionary<string, PushInfo>();
  555. //Dictionary<string, bool> haveSupp = new Dictionary<string, bool>();
  556. foreach (PushFeedbackExt fb in list)
  557. {
  558. //初始化付款方式 发货方式 要求日期
  559. foreach (PushFeedbackExt fb0 in pfbs) {
  560. if (fb0.Id.Equals(fb.Id))
  561. {
  562. //采购员可以编辑付款方式
  563. fb.CentPayMd = fb0.CentPayMd;
  564. fb.ReceiptMd = fb0.ReceiptMd;
  565. fb.RequestDate = fb0.RequestDate;
  566. fb.Remark = fb0.Remark;
  567. //采购员可以编辑供货数量
  568. fb.StoreGapNum = fb0.StoreGapNum;
  569. //预付款
  570. fb.PrepayAmt = fb0.PrepayAmt;
  571. fb.IsPrepay = fb0.IsPrepayI == 1?"Y":"N";
  572. //对方业务员,isyw='Y' and IsSaleDelegate='N'
  573. fb.OppContId = fb0.OppContId;
  574. }
  575. }
  576. if (fb.StoreGapNum > 0)
  577. {
  578. ContactDoc cd = ContactDAL.getContactor(fb.ContactId);
  579. string SuppliersId = fb.SuppliersId;
  580. if (cd != null)
  581. SuppliersId = cd.BusinessId;
  582. fb.SuppliersId = SuppliersId;
  583. fb.BusinessId = SuppliersId;
  584. var accountSuppliers = fb.PushAccountId +"_" + SuppliersId;
  585. if (groups.ContainsKey(accountSuppliers))
  586. {
  587. List<PushFeedbackExt> to;
  588. groups.TryGetValue(accountSuppliers, out to);
  589. to.Add(fb);
  590. groups.Remove(accountSuppliers);
  591. groups.Add(accountSuppliers, to);
  592. }
  593. else
  594. {
  595. List<PushFeedbackExt> to = new List<PushFeedbackExt>();
  596. to.Add(fb);
  597. groups.Add(accountSuppliers, to);
  598. }
  599. }
  600. //生成计划
  601. string contactid = fb.ContactId;
  602. if (fb.StoreGapNum <= 0)//对方没货 找下一个有货的供应商推送 生成计划前推送状态Y 生成计划后生成计划前推送状态N
  603. {
  604. //删除明细
  605. //PushFeedBackDAL.DeleteFeedback(fb.Id.ToString());
  606. ContactDAL.UpdatePushContactState(fb.GoodsId, contactid, fb.SuppliersId.Trim(), "Y", null);
  607. }
  608. else
  609. {//有货的记录需要推送状态为N 生成计划算在途
  610. ContactDAL.UpdatePushContactState(fb.GoodsId, contactid, fb.SuppliersId.Trim(), "N", null);
  611. }
  612. PushInfo.saveGoodsNames(fb, ref groupGoodsNames);
  613. }
  614. List<Object> result = new List<object>();
  615. int successAll = 0;
  616. int tempSuccess = 1;
  617. foreach (string groupkey in groups.Keys) {
  618. DateTime EndTime = DateTime.Now.AddHours((double)24);
  619. //string LoginStaffId = StaffDocDAL.GetStaffId(LoginAccountId);//改成谁绑定的品种就是谁的订单
  620. List<PushFeedbackExt> to;
  621. groups.TryGetValue(groupkey, out to);
  622. PushFeedbackExt fb0 = to.ToArray()[0];
  623. string StaffId = fb0.SaleManId;
  624. //添加采购计划
  625. IDictionary<string, Object> successs =
  626. PushRecordDAL.AddPlan(Id, fb0.Id.ToString(),
  627. fb0.PushAccountId,
  628. fb0.EntId, fb0.ReceiptMd, fb0.CentPayMd
  629. , OrgId, DeptId//depid
  630. , "采购计划", fb0.Remark //Summaries
  631. , fb0.GoodsId, fb0.SuppliersId
  632. , fb0.BusinessId, fb0.BusinessCode
  633. , StaffId
  634. , fb0.RequestDate
  635. , fb0.PrepayAmt
  636. , fb0.IsPrepay
  637. , fb0.OppContId
  638. , fb0.ContactId);
  639. Dictionary<string, Object> successsR = new Dictionary<string, object>();
  640. successsR.Add("successsPlan", successs);
  641. Object successPlan;
  642. successs.TryGetValue("successRecord", out successPlan);
  643. //billno
  644. Object PlanBillNo0;
  645. successs.TryGetValue("PlanBillNo", out PlanBillNo0);
  646. int PlanBillNo = (int)PlanBillNo0;
  647. if ((int)successPlan > 0)
  648. {
  649. List<Object> resultDt = new List<object>();
  650. int index = 1;
  651. foreach (PushFeedbackExt feedback in to)
  652. {
  653. Decimal LastPrice = feedback.PurPrice;
  654. string Summaries = feedback.Feedback;
  655. //添加采购计划明细
  656. int SafeDays = 0;
  657. IDictionary<string, Object> successs1 =
  658. PushRecordDAL.AddPlanDT(feedback.Id.ToString(), PlanBillNo, index,
  659. feedback.GoodsId, feedback.GoodsSpec, Convert.ToInt32(feedback.StoreGapNum),
  660. LastPrice, feedback.Remark,
  661. feedback.EntId,
  662. feedback.BusinessId, feedback.BusinessCode,
  663. feedback.SuppliersId,
  664. Convert.ToInt32(feedback.PurchaseTotalNum), SafeDays
  665. , StaffId
  666. , feedback.RequestDate);
  667. resultDt.Add(successs1);
  668. Object successPlanDT1;
  669. successs1.TryGetValue("successRecord", out successPlanDT1);
  670. if((int)successPlanDT1 > 0)
  671. {
  672. //更新推送状态 生成计划
  673. string resultState;
  674. var successState = PurPlanDAL.UpdatePlanState(feedback.Id.ToString(), Id, LoginAccountId,out resultState,
  675. " Remark = '" + feedback.Remark + "',StoreGapNum = '" + feedback.StoreGapNum + "',"
  676. + "OppContId = '" + feedback.OppContId + "',");
  677. if (resultState.StartsWith("在执行数据操作时发生错误"))
  678. tempSuccess = 0;
  679. }
  680. //记录失败
  681. else
  682. {
  683. tempSuccess = 0;
  684. }
  685. index += 1;
  686. }
  687. successsR.Add("successsPlanDT", resultDt);
  688. }
  689. else
  690. {
  691. //记录失败
  692. tempSuccess = 0;
  693. }
  694. result.Add(successsR);
  695. }
  696. if ((int)tempSuccess > 0)//&& listAll.Count == list.Count 全部生成计划
  697. {
  698. //更新推送状态 生成计划
  699. string resultState;
  700. var successState = PurPlanDAL.UpdateRecordPlanState(Id, LoginAccountId,out resultState);
  701. result.Add(successState);
  702. if (resultState.StartsWith("在执行数据操作时发生错误"))
  703. successAll = 1;
  704. foreach(string groupkey in groupGoodsNames.Keys) {
  705. //推送计划
  706. PushInfo pushInfos = null;
  707. groupGoodsNames.TryGetValue(groupkey, out pushInfos);
  708. DateTime EndTime = DateTime.Now.AddHours((double)Config.HoursToCancel);
  709. Message msg = PlanBAL.PushPlan(_client,
  710. Convert.ToInt32(groupkey),
  711. Id,
  712. pushInfos.GoodsName,
  713. pushInfos.GoodsNums,
  714. pushInfos.TotalAmount,
  715. EndTime);
  716. Dictionary<string, Object> msgd = new Dictionary<string, object>(1);
  717. msgd.Add("msg", msg);
  718. result.Add(msgd);
  719. }
  720. }
  721. if (tempSuccess > 0) {
  722. return Json(new
  723. {
  724. success = 1,
  725. result = result,
  726. successAll = successAll
  727. });
  728. }
  729. else
  730. {
  731. return Json(new
  732. {
  733. success = 0,
  734. result = result,
  735. successAll = successAll
  736. });
  737. }
  738. }
  739. ////待推送联系人--所有推送的业务员,查询业务员的推送记录
  740. [AuthPermission]
  741. [HttpPost, Route("pendingcontacts")]
  742. public JsonResult PendingContacts(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  743. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  744. {
  745. string LoginAccountId = getStaff("userid");
  746. string RoleId = getStaff("roleid");
  747. //判断参数是否合法
  748. if (string.IsNullOrEmpty(LoginAccountId))
  749. {
  750. return Json(new
  751. {
  752. items = new string[] { },
  753. sum = new { },
  754. totalCount = 0,
  755. timeout = 1
  756. });
  757. }
  758. if (data != null)
  759. {
  760. //Newtonsoft.Json.Linq.JArray
  761. filters = data.filters.ToObject<QueryFilter[]>();
  762. pageIndex = data.pageIndex;
  763. pageSize = data.pageSize;
  764. sortField = data.sortField;
  765. sortDirection = data.sortDirection;
  766. sumFields = data.sumFields.ToObject<string[]>();
  767. }
  768. #region 获取待推联系人
  769. DataTable dt = new DataTable();
  770. string result = string.Empty;
  771. string direct = " desc ";
  772. if (sortDirection != 1)
  773. direct = " asc";
  774. int start = (pageIndex - 1) * pageSize;
  775. int end = (start + 1 + pageSize);
  776. //string filterstr = QueryFilter.getFilterString(filters);
  777. List<SqlParameter> parameters1 = new List<SqlParameter>();
  778. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters1, new PushContactWithGoods());
  779. string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId);
  780. //filterstr += ((RoleId == "1" || RoleId == "6" || RoleId == "7") ? "" : (" and SaleManId = '" + StaffDocId + "' "));
  781. filterstr += FilterTranslator.ruleSql(ref parameters1);
  782. IList<PushContactWithGoods> users = new List<PushContactWithGoods>();
  783. Int64 totalcount = 0;
  784. //跨库 获取存储上下限
  785. //IList<PushStorLimit> limits = new List<PushStorLimit>();
  786. IList<PushStorLimit> limits = PushRecordDAL.GetPushLimit();
  787. if (limits.Count > 0)
  788. {
  789. //List<string> superior_list = new List<string>(0);
  790. Dictionary<string, PushStorLimit> gapnum = new Dictionary<string, PushStorLimit>();
  791. //foreach (PushStorLimit limit in limits)
  792. //{
  793. // //Role role;
  794. // //if (roleMap.TryGetValue(permsr.RoleId, out role))
  795. // //{
  796. // // listRoles.Add(role);
  797. // //}
  798. // superior_list.Add(limit.GoodsId);
  799. // gapnum.Add(limit.GoodsId, limit);
  800. //}
  801. ////perms.RoleList = listRoles;
  802. //string limitss = string.Join("','", superior_list.ToArray());
  803. string commandText0 = "select * from ( select *, row_number() over (order by ContactCode " + direct + " ) as rownum ";
  804. string commandText1 = "";
  805. //string commandText1 = "" +
  806. // " FROM(SELECT ROW_NUMBER() OVER(PARTITION BY t1.GoodsId ORDER BY t1.LastPrice asc,t1.SysDates1 asc) AS RNUM," +//,t1.ContactId
  807. // " * " +
  808. // "FROM sup_PushContactWithGoods t1" +
  809. // " WHERE 1=1 " +
  810. // //" and exists(" +
  811. // //" select 1 from LJHYBZK.dbo.sup_PushStorLimit A " +
  812. // //" where A.GoodsId = t1.GoodsId)" +
  813. // " and t1.GoodsId IN ('" +
  814. // limitss +
  815. // " ')" +
  816. // filterstr +
  817. // ") AS T " +
  818. // " WHERE T.RNUM = 1";
  819. string commandText2 = ")AAA where AAA.rownum>" + start + " and AAA.rownum<" + end + " ";
  820. //string commandText = commandText0 + commandText1 + commandText2;
  821. //bool result1 = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
  822. //// 把DataTable转换为IList<UserInfo>
  823. //if (dt != null && dt.Rows.Count > 0)
  824. //{
  825. // // 把DataTable转换为IList<UserInfo>
  826. // users = ModelConvertHelper<PushContactWithGoods>.ConvertToModel(dt);
  827. // foreach (PushContactWithGoods user in users)
  828. // {
  829. // //Role role;
  830. // //if (roleMap.TryGetValue(permsr.RoleId, out role))
  831. // //{
  832. // // listRoles.Add(role);
  833. // //}
  834. // PushStorLimit StorLimit;
  835. // gapnum.TryGetValue(user.GoodsId, out StorLimit);
  836. // user.StoreGapNum = StorLimit.StoreGapNum;
  837. // user.EntId = StorLimit.EntId;
  838. // user.PurchaseTotalNum = StorLimit.PurchaseTotalNum;//StoreGapNum
  839. // }
  840. //}
  841. #endregion
  842. users = ContactBAL.GetPushContactWithGoods(filterstr,null, limits,out gapnum,out commandText1,false, commandText0, commandText2, parameters1.ToArray());
  843. foreach (PushContactWithGoods user in users)
  844. {
  845. //Role role;
  846. //if (roleMap.TryGetValue(permsr.RoleId, out role))
  847. //{
  848. // listRoles.Add(role);
  849. //}
  850. PushStorLimit StorLimit;
  851. gapnum.TryGetValue(user.GoodsId, out StorLimit);
  852. user.StoreGapNum = StorLimit.StoreGapNum;
  853. user.EntId = StorLimit.EntId;
  854. user.PurchaseTotalNum = StorLimit.PurchaseTotalNum;//StoreGapNum
  855. }
  856. string resultrow;
  857. string commandTextRowCount = "select count(*) " + commandText1;
  858. //totalcount = DataAccess.GetRowCountDefine(connectstr, commandTextRowCount, out resultrow);
  859. totalcount = DataAccess.GetRowCountDefine(commandTextRowCount, parameters1.ToArray(), out resultrow);
  860. }
  861. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  862. {
  863. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  864. };
  865. var jsonData = JsonConvert.SerializeObject(users, timejson);
  866. return Json(new
  867. {
  868. items = JsonConvert.DeserializeObject(jsonData),
  869. sum = new { },
  870. totalCount = totalcount
  871. });
  872. }
  873. ////待推送联系人--所有推送的业务员,查询业务员的推送记录
  874. [AuthPermission]
  875. [HttpGet, Route("getcontacts")]
  876. public JsonResult GetContacts(string GoodsId)
  877. {
  878. IList<PushContactWithGoods> users = new List<PushContactWithGoods>();
  879. DataTable dt = new DataTable();
  880. string result = string.Empty;
  881. if (GoodsId == null || GoodsId == "") {
  882. return Json(new String[] { ""});
  883. }
  884. GoodsId = GoodsId.Replace(",","','");
  885. //跨库 获取存储上下限
  886. IList<PushStorLimit> limits = new List<PushStorLimit>();//PushRecordDAL.GetPushLimit(" and GoodsId in ('"+GoodsId+"')");
  887. //if (limits.Count > 0)
  888. //{
  889. List<string> superior_list = new List<string>(0);
  890. Dictionary<string, PushStorLimit> gapnum = new Dictionary<string, PushStorLimit>();
  891. users = ContactBAL.GetPushContactWithGoods(" and GoodsId in ('" + GoodsId + "') ", ",t1.ContactId,t1.SuppliersId", limits,out gapnum, out _);
  892. //}
  893. IList<Option> options = new List<Option>();
  894. foreach (PushContactWithGoods role in users) {
  895. var option = new Option() { label = role.Contact+" 最近价格:"+role.LastPrice+"供应商:"+role.BusinessName,
  896. //value = (role.UserId==null)? "" :role.UserId.Trim(),
  897. value = (role.ContactId == null) ? ("_"+role.SuppliersId+"_" + (role.UserId==null?"":role.UserId.Trim())) : (role.ContactId.Trim() + "_" +role.SuppliersId + "_" + (role.UserId == null ? "" : role.UserId.Trim())),
  898. disabled = (role.UserId == null|| role.UserId.Trim() == "")?true:false };
  899. options.Add(option);
  900. }
  901. return Json(options);
  902. }
  903. [AuthPermission]
  904. [HttpPost, Route("cancelrecord")]
  905. public JsonResult CancelRecord(string staffId, string RecordId,
  906. string IsCancel,
  907. [FromBody]dynamic data)
  908. {
  909. string userids;
  910. string LoginAccountId = userids = getStaffUserid(staffId);
  911. //判断参数是否合法
  912. if (string.IsNullOrEmpty(userids))
  913. {
  914. return Json(new
  915. {
  916. success = 0,
  917. msg = "登陆超时",
  918. timeout = 1
  919. });
  920. }
  921. Int32 SalemanAccountId = Convert.ToInt32(userids);
  922. string PushAccountId = string.Empty;
  923. if (data != null)
  924. {
  925. RecordId = data.Id;
  926. PushAccountId = data.PushAccountId;
  927. IsCancel = data.IsCancel;
  928. }
  929. List<DataAccessCommand> list = new List<DataAccessCommand>();
  930. #region 更新记录状态
  931. string commandTextStateR = "UPDATE " + Config.TablePrefix + "PushRecord " +
  932. " SET CancelTime = @CancelTime, " +
  933. " CancelPerson = @CancelPerson, " +
  934. " IsCancel = @IsCancel" +
  935. " WHERE Id = @RecordId " +
  936. " and PushAccountId = @PushAccountId "+
  937. " and (state IS NULL or state = 0) or state in(2) " +
  938. " and IsCancel = "+ (IsCancel == "1" ? "0":"1")
  939. ;
  940. //string resultStateR;
  941. //准备参数
  942. List<List<Object>> parametersStateR = new List<List<Object>>();
  943. parametersStateR.Add(new List<Object>() { "CancelTime", DateTime.Now });
  944. parametersStateR.Add(new List<Object>() { "CancelPerson", SalemanAccountId });
  945. parametersStateR.Add(new List<Object>() { "IsCancel", IsCancel });
  946. parametersStateR.Add(new List<Object>() { "RecordId", RecordId });
  947. parametersStateR.Add(new List<Object>() { "PushAccountId", PushAccountId });
  948. List<SqlParameter> parametersStateR1 = DataAccess.ToParameters(parametersStateR);
  949. list.Add(new DataAccessCommand(commandTextStateR, parametersStateR1, CommandType.Text, true));
  950. #endregion
  951. string pushflag = (IsCancel == "1" ? "N" : "Y");
  952. List<PushFeedbackExt> listpfb = PushFeedBackDAL.GetFeedbacks(RecordId, " and IsCancel = '" + (IsCancel == "1" ? "0" : "1") + "'");
  953. #region 更新推送状态
  954. if (listpfb != null)
  955. {
  956. foreach (PushFeedbackExt pfb in listpfb)
  957. {
  958. //设置推送状态
  959. //ContactDAL.UpdatePushContactState(pfb.GoodsId, contactid, pfb.SuppliersId.Trim(), "N");
  960. string commandText = "Update k_contactsp set PushFlag = '" + pushflag + "' " +
  961. " Where 1=1 " +
  962. " and GoodsId=@GoodsId " +
  963. " and ContactId=@ContactId "
  964. //+" and SuppliersId=@SuppliersId "
  965. ;
  966. //string result;
  967. List<List<Object>> parameters = new List<List<Object>>();
  968. parameters.Add(new List<Object>() { "GoodsId", pfb.GoodsId });
  969. parameters.Add(new List<Object>() { "ContactId", pfb.ContactId });
  970. //parameters.Add(new List<Object>() { "SuppliersId", pfb.SuppliersId.Trim() });
  971. list.Add(new DataAccessCommand(commandText, DataAccess.ToParameters(parameters), CommandType.Text, false));
  972. //bool success = DataAccess.ExecuteBatchCommands(list, out result);
  973. }
  974. }
  975. #endregion
  976. #region 更新明细状态
  977. string commandTextStateF = "UPDATE " + Config.TablePrefix + "PushFeedback " +
  978. " SET CancelTime = @CancelTime, " +
  979. " CancelPerson = @CancelPerson, " +
  980. " IsCancel = @IsCancel" +
  981. " WHERE PushRecordId = @RecordId " +
  982. " and PushAccountId = @PushAccountId " +
  983. " and (state IS NULL or state = 0 or state in(5,6))" +
  984. " and IsCancel = " + (IsCancel == "1" ? "0" : "1")
  985. ;
  986. string resultStateF;
  987. //准备参数
  988. List<List<Object>> parametersStateF = new List<List<Object>>();
  989. parametersStateF.Add(new List<Object>() { "CancelTime", DateTime.Now });
  990. parametersStateF.Add(new List<Object>() { "CancelPerson", SalemanAccountId });
  991. parametersStateF.Add(new List<Object>() { "IsCancel", IsCancel });
  992. parametersStateF.Add(new List<Object>() { "RecordId", RecordId });
  993. parametersStateF.Add(new List<Object>() { "PushAccountId", PushAccountId });
  994. List<SqlParameter> parametersStateF1 = DataAccess.ToParameters(parametersStateF);
  995. list.Add(new DataAccessCommand(commandTextStateF, parametersStateF1, CommandType.Text, true));
  996. #endregion
  997. bool success = DataAccess.ExecuteBatchCommands(list, out resultStateF);
  998. return Json(new
  999. {
  1000. success = success,
  1001. result = resultStateF,
  1002. });
  1003. }
  1004. /// <summary>
  1005. ///
  1006. /// </summary>
  1007. /// <param name="staffId"></param>
  1008. /// <param name="RecordId"></param>
  1009. /// <param name="IsCancel"></param>
  1010. /// <param name="data"></param>
  1011. /// <returns></returns>
  1012. [AuthPermission]
  1013. [HttpPost, Route("cancelPush")]
  1014. public JsonResult CancelPush(string staffId, string RecordId,
  1015. string IsCancel,
  1016. [FromBody]dynamic data)
  1017. {
  1018. string userids;
  1019. string LoginAccountId = userids = getStaffUserid(staffId);
  1020. //判断参数是否合法
  1021. if (string.IsNullOrEmpty(userids))
  1022. {
  1023. return Json(new
  1024. {
  1025. success = 0,
  1026. msg = "登陆超时",
  1027. timeout = 1
  1028. });
  1029. }
  1030. Int32 SalemanAccountId = Convert.ToInt32(userids);
  1031. string PushAccountId = string.Empty;
  1032. if (data != null)
  1033. {
  1034. RecordId = data.Id;
  1035. PushAccountId = data.PushAccountId;
  1036. IsCancel = data.IsCancel;
  1037. }
  1038. List<DataAccessCommand> list = new List<DataAccessCommand>();
  1039. string pushflag = (IsCancel == "1" ? "N" : "Y");
  1040. List<PushFeedbackExt> listpfb = PushFeedBackDAL.GetFeedbacks(RecordId, "");
  1041. #region 更新推送状态
  1042. foreach (PushFeedbackExt pfb in listpfb)
  1043. {
  1044. //设置推送状态
  1045. //ContactDAL.UpdatePushContactState(pfb.GoodsId, contactid, pfb.SuppliersId.Trim(), "N");
  1046. string commandText = "Update k_contactsp set PushFlag = '" + pushflag + "' " +
  1047. " Where 1=1 " +
  1048. " and GoodsId=@GoodsId " +
  1049. " and ContactId=@ContactId " +
  1050. " and SuppliersId=@SuppliersId ";
  1051. //string result;
  1052. List<List<Object>> parameters = new List<List<Object>>();
  1053. parameters.Add(new List<Object>() { "GoodsId", pfb.GoodsId });
  1054. parameters.Add(new List<Object>() { "ContactId", pfb.ContactId });
  1055. parameters.Add(new List<Object>() { "SuppliersId", pfb.SuppliersId.Trim() });
  1056. list.Add(new DataAccessCommand(commandText, DataAccess.ToParameters(parameters), CommandType.Text, true));
  1057. //bool success = DataAccess.ExecuteBatchCommands(list, out result);
  1058. }
  1059. #endregion
  1060. string resultStateF;
  1061. bool success = DataAccess.ExecuteBatchCommands(list, out resultStateF);
  1062. return Json(new
  1063. {
  1064. success = success,
  1065. result = resultStateF,
  1066. });
  1067. }
  1068. ///删除记录
  1069. [AuthPermission]
  1070. [HttpPost, Route("delete")]
  1071. public ActionResult Delete(
  1072. [FromBody]dynamic data)
  1073. {
  1074. string userids;
  1075. string Idstr = string.Empty;
  1076. string LoginAccountId = userids = getStaff("userid");
  1077. //判断参数是否合法
  1078. if (string.IsNullOrEmpty(userids))
  1079. {
  1080. return Json(new
  1081. {
  1082. success = 0,
  1083. msg = "登陆超时",
  1084. timeout = 1
  1085. });
  1086. }
  1087. if (data != null)
  1088. {
  1089. Idstr = data.Id;
  1090. }
  1091. string[] Ids = new string[] { };
  1092. if (Idstr.IndexOf(",") > 0)
  1093. {
  1094. Ids = Idstr.Split(',');
  1095. }
  1096. else
  1097. {
  1098. Ids = new string[1] { Idstr};
  1099. }
  1100. List<DataAccessCommand> list = new List<DataAccessCommand>();
  1101. string result = "";
  1102. foreach (string Id in Ids) {
  1103. #region 删除记录
  1104. string commandText = "DELETE FROM " + Config.TablePrefix + "PushRecord WHERE Id = @Id";
  1105. //准备参数
  1106. List<List<Object>> parameters = new List<List<Object>>();
  1107. parameters.Add(new List<Object>() { "Id", Id });
  1108. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  1109. list.Add(new DataAccessCommand(commandText, parameters1, CommandType.Text, true));
  1110. //int successDel = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  1111. #endregion
  1112. string pushflag = "N";
  1113. List<PushFeedbackExt> listpfb = PushFeedBackDAL.GetFeedbacks(Id, "");// and IsCancel = '1'
  1114. if(listpfb!=null)
  1115. #region 更新推送状态
  1116. foreach (PushFeedbackExt pfb in listpfb)
  1117. {
  1118. //设置推送状态
  1119. //ContactDAL.UpdatePushContactState(pfb.GoodsId, contactid, pfb.SuppliersId.Trim(), "N");
  1120. string commandTextFlag = "Update k_contactsp set PushFlag = '" + pushflag + "' " +
  1121. " Where 1=1 " +
  1122. " and GoodsId=@GoodsId " +
  1123. " and ContactId=@ContactId "
  1124. // + " and SuppliersId=@SuppliersId "
  1125. ;
  1126. //string result;
  1127. List<List<Object>> parametersFlag = new List<List<Object>>();
  1128. parametersFlag.Add(new List<Object>() { "GoodsId", pfb.GoodsId });
  1129. parametersFlag.Add(new List<Object>() { "ContactId", pfb.ContactId });
  1130. //parametersFlag.Add(new List<Object>() { "SuppliersId", pfb.SuppliersId.Trim() });
  1131. list.Add(new DataAccessCommand(commandTextFlag, DataAccess.ToParameters(parametersFlag), CommandType.Text, false));
  1132. //bool success = DataAccess.ExecuteBatchCommands(list, out result);
  1133. //string resultsp = "";
  1134. //int success = DataAccess.ExecuteCommand(commandTextFlag, DataAccess.ToParameters(parametersFlag), out resultsp);
  1135. }
  1136. #endregion
  1137. if (listpfb != null && listpfb.Count > 0) {
  1138. #region 删除明细
  1139. string commandTextDT = "DELETE FROM " + Config.TablePrefix + "PushFeedback WHERE PushRecordId = @Id";
  1140. //准备参数
  1141. List<List<Object>> parametersDT = new List<List<Object>>();
  1142. parametersDT.Add(new List<Object>() { "Id", Id });
  1143. List<SqlParameter> parametersDT1 = DataAccess.ToParameters(parametersDT);
  1144. list.Add(new DataAccessCommand(commandTextDT, parametersDT1, CommandType.Text, true));
  1145. //string resultDT = "";
  1146. //int successDelDT = DataAccess.ExecuteCommand(commandTextDT, parametersDT1, out resultDT);
  1147. #endregion
  1148. }
  1149. }
  1150. bool successDel = DataAccess.ExecuteBatchCommands(list, out result);
  1151. return Json(new
  1152. {
  1153. success = successDel,
  1154. resultDel = result,
  1155. });
  1156. }
  1157. ///删除记录
  1158. [AuthPermission]
  1159. [HttpPost, Route("deleteabandon")]
  1160. public ActionResult deleteAbandon(
  1161. [FromBody]dynamic data)
  1162. {
  1163. string userids;
  1164. string Idstr = string.Empty;
  1165. string LoginAccountId = userids = getStaff("userid");
  1166. //判断参数是否合法
  1167. if (string.IsNullOrEmpty(userids))
  1168. {
  1169. return Json(new
  1170. {
  1171. success = 0,
  1172. msg = "登陆超时",
  1173. timeout = 1
  1174. });
  1175. }
  1176. if (data != null)
  1177. {
  1178. Idstr = data.Id;
  1179. }
  1180. string[] Ids = new string[] { };
  1181. if (Idstr.IndexOf(",") > 0)
  1182. {
  1183. Ids = Idstr.Split(',');
  1184. }
  1185. else
  1186. {
  1187. Ids = new string[1] { Idstr };
  1188. }
  1189. Idstr = string.Join("','", Ids);
  1190. DataTable dt = new DataTable();
  1191. List<SqlParameter> param = new List<SqlParameter>();
  1192. //param.Add(new SqlParameter("BusinessId", BusinessIds));
  1193. DataAccess.GetValues("select * from sup_PushRecord where " +
  1194. " state in(0,1) " +
  1195. " and Id in(select PushRecordId from sup_PushFeedback where Id in ('" + Idstr + "') " +
  1196. ")" +
  1197. "", ref dt, param.ToArray(), out var msg);
  1198. IList<Option> options = new List<Option>();
  1199. if(dt!=null && dt.Rows.Count > 0)
  1200. {
  1201. return Json(new
  1202. {
  1203. success = 0,
  1204. msg = "请选择上次生成计划不要的品种删除",
  1205. });
  1206. }
  1207. List<DataAccessCommand> list = new List<DataAccessCommand>(Ids.Length*2);
  1208. string result = "";
  1209. foreach (string Id in Ids)
  1210. {
  1211. string pushflag = "N";
  1212. List<PushFeedbackExt> listpfb = PushFeedBackDAL.GetFeedbacksIn(Id, "");// and IsCancel = '1'
  1213. #region 更新推送状态
  1214. foreach (PushFeedbackExt pfb in listpfb)
  1215. {
  1216. //设置推送状态
  1217. //ContactDAL.UpdatePushContactState(pfb.GoodsId, contactid, pfb.SuppliersId.Trim(), "N");
  1218. string commandTextFlag = "Update k_contactsp set PushFlag = '" + pushflag + "' " +
  1219. " Where 1=1 " +
  1220. " and GoodsId=@GoodsId " +
  1221. " and ContactId=@ContactId "
  1222. // + " and SuppliersId=@SuppliersId "
  1223. ;
  1224. //string result;
  1225. List<List<Object>> parametersFlag = new List<List<Object>>();
  1226. parametersFlag.Add(new List<Object>() { "GoodsId", pfb.GoodsId });
  1227. parametersFlag.Add(new List<Object>() { "ContactId", pfb.ContactId });
  1228. //parametersFlag.Add(new List<Object>() { "SuppliersId", pfb.SuppliersId.Trim() });
  1229. list.Add(new DataAccessCommand(commandTextFlag, DataAccess.ToParameters(parametersFlag), CommandType.Text, false));
  1230. //bool success = DataAccess.ExecuteBatchCommands(list, out result);
  1231. //string resultsp = "";
  1232. //int success = DataAccess.ExecuteCommand(commandTextFlag, DataAccess.ToParameters(parametersFlag), out resultsp);
  1233. }
  1234. #endregion
  1235. #region 删除明细
  1236. string commandTextDT = "DELETE FROM " + Config.TablePrefix + "PushFeedback WHERE Id = @Id and state in (1,2) and PushRecordId in (select Id from sup_PushRecord where Id = PushRecordId and State in (3,4))";
  1237. //准备参数
  1238. List<List<Object>> parametersDT = new List<List<Object>>();
  1239. parametersDT.Add(new List<Object>() { "Id", Id });
  1240. List<SqlParameter> parametersDT1 = DataAccess.ToParameters(parametersDT);
  1241. list.Add(new DataAccessCommand(commandTextDT, parametersDT1, CommandType.Text, true));
  1242. //string resultDT = "";
  1243. //int successDelDT = DataAccess.ExecuteCommand(commandTextDT, parametersDT1, out resultDT);
  1244. #endregion
  1245. }
  1246. bool successDel = DataAccess.ExecuteBatchCommands(list, out result);
  1247. return Json(new
  1248. {
  1249. success = successDel,
  1250. msg = result,
  1251. });
  1252. }
  1253. ////待推送联系人--所有推送的业务员,查询业务员的推送记录
  1254. [HttpGet, Route("getstates")]
  1255. public JsonResult GetStates()
  1256. {
  1257. IList<Option> options = new List<Option>();
  1258. var option = new Option()
  1259. {
  1260. label = "未填写",
  1261. //value = (role.UserId==null)? "" :role.UserId.Trim(),
  1262. value = "0",
  1263. disabled = false
  1264. };
  1265. options.Add(option);
  1266. var option1 = new Option()
  1267. {
  1268. label = "已填写",
  1269. //value = (role.UserId==null)? "" :role.UserId.Trim(),
  1270. value = "1",
  1271. disabled = false
  1272. };
  1273. options.Add(option1);
  1274. var option4 = new Option()
  1275. {
  1276. label = "低于缺口",
  1277. //value = (role.UserId==null)? "" :role.UserId.Trim(),
  1278. value = "2",
  1279. disabled = false
  1280. };
  1281. options.Add(option4);
  1282. var option2 = new Option()
  1283. {
  1284. label = "已生成采购计划",
  1285. //value = (role.UserId==null)? "" :role.UserId.Trim(),
  1286. value = "3",
  1287. disabled = false
  1288. };
  1289. options.Add(option2);
  1290. var option3 = new Option()
  1291. {
  1292. label = "已生成订单",
  1293. //value = (role.UserId==null)? "" :role.UserId.Trim(),
  1294. value = "4",
  1295. disabled = false
  1296. };
  1297. options.Add(option3);
  1298. return Json(options);
  1299. }
  1300. [HttpGet, Route("getOppContact")]
  1301. public JsonResult getOppContact(string BusinessId)
  1302. {
  1303. string BusinessIds = string.IsNullOrEmpty(BusinessId)?"":BusinessId.TrimEnd(',');
  1304. if(string.IsNullOrEmpty(BusinessIds))
  1305. return Json(new string[] { });
  1306. BusinessIds = "'"+BusinessIds.Replace(",","','")+"'";
  1307. DataTable dt = new DataTable();
  1308. List<SqlParameter> param = new List<SqlParameter>();
  1309. //param.Add(new SqlParameter("BusinessId", BusinessIds));
  1310. DataAccess.GetValues("select ContactId,Contact from ContactDoc where " +
  1311. "BusinessId in("+ BusinessIds + ") " +
  1312. " and isyw='Y' and IsSaleDelegate='N' and BeActive='Y'", ref dt,param.ToArray(),out var result);
  1313. IList <Option> options = new List<Option>();
  1314. foreach(DataRow item in dt.Rows) {
  1315. var option3 = new Option()
  1316. {
  1317. label = item["Contact"].ToString(),
  1318. //value = (role.UserId==null)? "" :role.UserId.Trim(),
  1319. value = item["ContactId"].ToString(),
  1320. disabled = false
  1321. };
  1322. options.Add(option3);
  1323. }
  1324. return Json(options);
  1325. }
  1326. }
  1327. }