OrderController.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using Common.Model;
  7. using JCSoft.WX.Framework.Api;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Caching.Memory;
  10. using Newtonsoft.Json;
  11. using PublicLibrary.Model;
  12. using SupplierWeb.Codes.EF;
  13. using ZcPeng.PublicLibrary;
  14. using System.Linq.Dynamic.Core;
  15. using SupplierWeb.Codes.mvc;
  16. using CoreEntity.Entity;
  17. using CoreEntity.DAL;
  18. using Common.Wechat;
  19. using Newtonsoft.Json.Converters;
  20. using LigerRM.Common;
  21. namespace SupplierWeb.Controllers
  22. {
  23. /// <summary>
  24. ///
  25. /// 订单汇总明细,入库单汇总明细,拒收单汇总明细
  26. /// </summary>
  27. [Route("web/order")]
  28. [ApiController]
  29. public class OrderController : BaseController
  30. {
  31. public OrderController(IMemoryCache cache, IApiClient client) : base(cache, client)
  32. {
  33. }
  34. [AuthPermission]
  35. [HttpPost]
  36. [Route("getData")]
  37. public JsonResult GetData(string[] filters, Int32 pageIndex, Int32 pageSize,
  38. string sortField, Int32 sortDirection, string[] sumFields, string staffid, [FromBody]dynamic data)
  39. {
  40. var userid = getStaffUserid(staffid);
  41. //判断参数是否合法
  42. if (string.IsNullOrEmpty(userid))
  43. {
  44. return Json(new
  45. {
  46. success = 0,
  47. msg = "没有登陆",
  48. timeout = 1,
  49. });
  50. }
  51. var sql0 = "select * from sup_Account where id = @userid";
  52. var param0 = new List<SqlParameter>();
  53. param0.Add(new SqlParameter("userid", int.Parse(userid)));
  54. var dt0 = new DataTable();
  55. DataAccess.GetValues(sql0, ref dt0, param0.ToArray(), out _);
  56. var purStaffId = string.Empty;
  57. var name = string.Empty;
  58. if (dt0 != null && dt0.Rows.Count > 0)
  59. {
  60. purStaffId = dt0.Rows[0]["PurStaffId"].ToString();
  61. name = dt0.Rows[0]["AccountRealName"].ToString();
  62. }
  63. List<QueryFilter> filterList = new List<QueryFilter>();
  64. if (data != null)
  65. {
  66. if (data.filters.Count > 0)
  67. {
  68. var list = JsonConvert.SerializeObject(data.filters);
  69. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  70. }
  71. pageIndex = data.pageIndex;
  72. pageSize = data.pageSize;
  73. sortField = data.sortField;
  74. sortDirection = data.sortDirection;
  75. sumFields = data.sumFields.ToObject<string[]>();
  76. }
  77. var isAce = sortDirection == 0;
  78. var queryCondition = string.Empty;
  79. var param = new List<SqlParameter>();
  80. var start = (pageIndex - 1) * pageSize;
  81. var end = (start + 1 + pageSize);
  82. var dt = new DataTable();
  83. if (filterList != null)
  84. {
  85. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(), out param, new PurInMt(), "A.");
  86. }
  87. var sql =
  88. $"select * from " +
  89. $"(select A.*,row_number() over (order by A.BillNo desc) as rowNum " +
  90. $"from (select *,'{name}' as AccountRealName from PurOrderMT A " +
  91. $"where SaleManId= '{purStaffId}') A where 1=1 {queryCondition}) R" +
  92. $" where rowNum > {start} and rowNum < {end}";
  93. DataAccess.GetValues(sql, ref dt, param.ToArray(), out _);
  94. IList<Temp> result = new List<Temp>();
  95. if (dt != null && dt.Rows.Count > 0)
  96. {
  97. result = ModelConvertHelper<Temp>.ConvertToModel(dt);
  98. }
  99. var jsonData = JsonConvert.SerializeObject(result);
  100. var countSql =
  101. $"select count(1) from (select * from (select * from PURORDERMT where SaleManId= '{purStaffId}') A where 1=1 {queryCondition}) R";
  102. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out _);
  103. return Json(new
  104. {
  105. items = result,
  106. sum = new { },
  107. totalCount = count
  108. });
  109. }
  110. [AuthPermission]
  111. [HttpPost]
  112. [Route("orderin")]
  113. public JsonResult orderin(string[] filters, Int32 pageIndex, Int32 pageSize,
  114. string sortField, Int32 sortDirection, string[] sumFields, string staffid, [FromBody]dynamic data)
  115. {
  116. var userid = getStaffUserid(staffid);
  117. //判断参数是否合法
  118. if (string.IsNullOrEmpty(userid))
  119. {
  120. return Json(new
  121. {
  122. success = 0,
  123. msg = "没有登陆",
  124. timetout = 1,
  125. });
  126. }
  127. //var sql0 = "select ContactId from ContactDoc where UserId = @userid";
  128. //var param0 = new List<SqlParameter>();
  129. //param0.Add(new SqlParameter("userid", int.Parse(userid)));
  130. //var dt0 = new DataTable();
  131. //DataAccess.GetValues(sql0, ref dt0, param0.ToArray(), out _);
  132. //var ContactId = string.Empty;
  133. //if (dt0 != null && dt0.Rows.Count > 0)
  134. //{
  135. // ContactId = dt0.Rows[0]["ContactId"].ToString();
  136. //}
  137. List<QueryFilter> filterList = new List<QueryFilter>();
  138. if (data != null)
  139. {
  140. if (data.filters.Count > 0)
  141. {
  142. var list = JsonConvert.SerializeObject(data.filters);
  143. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  144. }
  145. pageIndex = data.pageIndex;
  146. pageSize = data.pageSize;
  147. sortField = data.sortField;
  148. sortDirection = data.sortDirection;
  149. sumFields = data.sumFields.ToObject<string[]>();
  150. }
  151. var isAce = sortDirection == 0;
  152. var queryCondition = string.Empty;
  153. var param = new List<SqlParameter>();
  154. var start = (pageIndex - 1) * pageSize;
  155. var end = (start + 1 + pageSize);
  156. var dt = new DataTable();
  157. if (filterList != null)
  158. {
  159. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(),out param,new PurInMt(),"B.");
  160. }
  161. queryCondition = queryCondition.Replace("B.Contact", "A.Contact");
  162. queryCondition = queryCondition.Replace("B.OppContact", "A1.OppContact");
  163. queryCondition = queryCondition.Replace("B.StaffName","D.StaffName");
  164. //param.Add(new SqlParameter("userid", int.Parse(userid)));
  165. string rulesql = FilterTranslator.ruleSql(ref param);
  166. var sql = $"select * from";
  167. var sql1 = $"(select row_number() over (order by b.BillNo desc) as rownum,b.*,A.Contact,A1.Contact as OppContact,D.StaffName " +
  168. $"from PURINMT B " +
  169. $"left join PURORDERMT C on b.K_BillCode=c.BillCode and C.EntId = B.EntId " +
  170. $"left join CONTACTDOC A on C.K_ContactId = A.ContactId and A.EntId = C.EntId " +
  171. $"left join CONTACTDOC A1 on A1.ContactId = C.OppContId and A1.EntId = C.EntId " +
  172. $"left join StaffDoc D on D.StaffId = B.SaleManId and D.EntId = B.EntId " +
  173. $"where 1=1 " +
  174. //$"and c.Source = 'coop.360lj.com' " +
  175. //$"and c.Source = 'coop.360lj.com' and C.K_ContactId in (select ContactId from ContactDoc where UserId = @userid) " +
  176. queryCondition +
  177. rulesql +
  178. $")R";
  179. var sql2 = $" where rownum > {start} and rownum< {end}";
  180. string resultstr;
  181. DataAccess.GetValues(sql+sql1+sql2, ref dt, param.ToArray(), out resultstr);
  182. IList<Temp3> result = new List<Temp3>();
  183. if (dt != null && dt.Rows.Count > 0)
  184. {
  185. result = ModelConvertHelper<Temp3>.ConvertToModel(dt);
  186. }
  187. var jsonData = JsonConvert.SerializeObject(result);
  188. var countSql =
  189. $"select count(1) from " +
  190. sql1;
  191. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out resultstr);
  192. return Json(new
  193. {
  194. items = result,
  195. sum = new { },
  196. totalCount = count
  197. });
  198. }
  199. [AuthPermission]
  200. [HttpPost]
  201. [Route("orderindt")]
  202. public JsonResult orderindt(string[] filters, Int32 pageIndex, Int32 pageSize,
  203. string sortField, Int32 sortDirection, string[] sumFields, string staffid, [FromBody]dynamic data)
  204. {
  205. var userid = getStaffUserid(staffid);
  206. //判断参数是否合法
  207. if (string.IsNullOrEmpty(userid))
  208. {
  209. return Json(new
  210. {
  211. success = 0,
  212. msg = "没有登陆",
  213. timetout = 1,
  214. });
  215. }
  216. //var sql0 = "select * from ContactDoc where userid = @userid";
  217. //var param0 = new List<SqlParameter>();
  218. //param0.Add(new SqlParameter("userid", int.Parse(userid)));
  219. //var dt0 = new DataTable();
  220. //DataAccess.GetValues(sql0, ref dt0, param0.ToArray(), out _);
  221. //var ContactId = "'";
  222. //if (dt0 != null && dt0.Rows.Count > 0)
  223. //{
  224. // int i = 0;
  225. // foreach (DataRow row in dt0.Rows)
  226. // {
  227. // if (i != (dt0.Rows.Count - 1))
  228. // ContactId += dt0.Rows[0]["ContactId"].ToString() + "','";
  229. // else
  230. // ContactId += dt0.Rows[0]["ContactId"].ToString() + "'";
  231. // i += 1;
  232. // }
  233. //}
  234. //var billNo = string.Empty;
  235. List<QueryFilter> filterList = new List<QueryFilter>();
  236. if (data != null)
  237. {
  238. if (data.filters.Count > 0)
  239. {
  240. var list = JsonConvert.SerializeObject(data.filters);
  241. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  242. }
  243. pageIndex = data.pageIndex;
  244. pageSize = data.pageSize;
  245. sortField = data.sortField;
  246. sortDirection = data.sortDirection;
  247. sumFields = data.sumFields.ToObject<string[]>();
  248. //billNo = filterList.FirstOrDefault()?.value;
  249. }
  250. //if (string.IsNullOrEmpty(billNo))
  251. //{
  252. // billNo = "0000";
  253. //}
  254. var isAce = sortDirection == 0;
  255. var queryCondition = string.Empty;
  256. var param = new List<SqlParameter>();
  257. var start = (pageIndex - 1) * pageSize;
  258. var end = (start + 1 + pageSize);
  259. var dt = new DataTable();
  260. //var filter = " and D.K_ContactId in( " + ContactId + ")";
  261. if (filterList != null)
  262. {
  263. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(), out param, new PurInMt(), "B.");
  264. }
  265. queryCondition = queryCondition.Replace("B.kdcode", "F.k_kdcode");
  266. queryCondition = queryCondition.Replace("B.GoodsName", "G.GoodsName");
  267. //queryCondition = queryCondition.Replace("B.StaffName", "D.StaffName");
  268. string rulesql = FilterTranslator.ruleSql(ref param);
  269. var sql = $"select * from ";
  270. var sql1 = $"(select row_number() over (order by a.BillNo desc) as rownum,b.*,F.k_kdcode as kdcode,G.GoodsName " +
  271. $"from PURINDT B " +
  272. $"left join PURINMT A on A.BillNo=B.BillNo and A.EntId = B.EntId " +
  273. $"left join PURNOTESDT C on b.RfBillNo=c.BillNo and C.BillSn=B.RfBillSn and C.EntId = B.EntId " +
  274. $"left join PURORDERMT D on A.K_BillCode = d.BillCode and D.EntId = A.EntId " +
  275. $"left join sup_PurShipmentOrderDT E on E.BillNo=C.BillNo and E.BillSn=C.BillSn " +
  276. $"left join sup_PurOrderShipment F on F.Id=E.ShipmentId " +
  277. $"left join GOODSDOC G on G.GoodsId=B.GoodsId and G.EntId = B.EntId " +
  278. $"where 1=1 " +
  279. $" {queryCondition} " +
  280. $" {rulesql}" +
  281. //$" and a.billno ={billNo}" +
  282. $") R " ;
  283. var sql2 = $" where rownum > {start} and rownum < {end}";
  284. string resultstr;
  285. DataAccess.GetValues(sql + sql1 +sql2, ref dt, param.ToArray(), out resultstr);
  286. IList<Temp4> result = new List<Temp4>();
  287. if (dt != null && dt.Rows.Count > 0)
  288. {
  289. result = ModelConvertHelper<Temp4>.ConvertToModel(dt);
  290. }
  291. var jsonData = JsonConvert.SerializeObject(result);
  292. var countSql = $"select count(1) from " + sql1;
  293. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out resultstr);
  294. return Json(new
  295. {
  296. items = result,
  297. sum = new { },
  298. totalCount = count
  299. });
  300. }
  301. ////查询采购订单明细
  302. [AuthPermission]
  303. [HttpPost, Route("purchaseorderdt/{staffId}")]
  304. public JsonResult purchaseorderdt(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  305. string sortField, Int32 sortDirection, string[] sumFields,
  306. string staffId,
  307. [FromBody]dynamic data)
  308. {
  309. string userids;
  310. userids = getStaffUserid(staffId);
  311. //判断参数是否合法
  312. if (string.IsNullOrEmpty(userids))
  313. {
  314. return Json(new
  315. {
  316. items = new string[] { },
  317. sum = new { },
  318. totalCount = 0,
  319. timeout = 1
  320. });
  321. }
  322. if (data != null)
  323. {
  324. //Newtonsoft.Json.Linq.JArray
  325. filters = data.filters.ToObject<QueryFilter[]>();
  326. pageIndex = data.pageIndex;
  327. pageSize = data.pageSize;
  328. sortField = data.sortField;
  329. sortDirection = data.sortDirection;
  330. sumFields = data.sumFields.ToObject<string[]>();
  331. }
  332. string StaffDocId = StaffDocDAL.GetStaffId(userids);
  333. List<SqlParameter> parameters1 = new List<SqlParameter>();
  334. string filterstring = QueryFilter.getFilterSqlParam(filters, out parameters1, new PurOrderDTEx(), "G.");
  335. filterstring += " " +
  336. " and A.SaleManId = '" + StaffDocId + "' ";
  337. filterstring = filterstring.Replace("and G.GoodsName", "and H.GoodsName");
  338. filterstring = filterstring.Replace("and G.GoodsCode", "and H.GoodsCode");
  339. filterstring = filterstring.Replace("and G.StaffName", "and C.StaffName");
  340. filterstring = filterstring.Replace("and G.Contact", "and F.Contact");
  341. filterstring = filterstring.Replace("and G.BusinessName", "and E.BusinessName");
  342. #region 获取订单
  343. DataTable dt = new DataTable();
  344. string result = string.Empty;
  345. string direct = " desc ";
  346. if (sortDirection != 1)
  347. direct = " asc";
  348. int start = (pageIndex - 1) * pageSize;
  349. int end = (start + 1 + pageSize);
  350. string commandText0 = "select * from (";
  351. string commandText1 =
  352. "select G.*,A.OppContId,A.SuppliersId,B.AccountRealName,C.StaffName," +
  353. "E.BusinessName,F.Contact," +
  354. "H.GoodsName,H.GoodsCode,H.GoodsSpec,H.Manufacturer," +
  355. "row_number() over" +
  356. "( order by G." + sortField + " " + direct + " ) as rownum" +
  357. " from PurOrderDT G left join PurOrderMT A on G.BillNo = A.BillNo and A.EntId = G.EntId " +
  358. " left join GoodsDoc H on H.GoodsId=G.GoodsId and H.EntId = G.EntId " +
  359. " left join " + Config.TablePrefix + "Account B on A.SaleManId=B.PurStaffId " +
  360. " left join StaffDoc C on A.SaleManId=C.StaffId and C.EntId = A.EntId " +
  361. " left join supplydoc D on A.SuppliersId=D.SuppliersId and D.EntId = A.EntId " +
  362. " left join BusinessDoc E on E.BusinessId=D.SuppliersId and E.Is_Supp = 'Y' and E.EntId = D.EntId " +
  363. " left join ContactDoc F on F.ContactId=A.oppcontid and F.EntId = A.EntId " +
  364. " where 1=1 " +
  365. filterstring +
  366. ")AAA";
  367. string commandText2 =
  368. " where AAA.rownum>" + start + " and AAA.rownum<" + end
  369. ;
  370. string commandText = commandText0 + commandText1 + commandText2;
  371. bool result1 = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
  372. IList<PurOrderDTEx> users = new List<PurOrderDTEx>();
  373. if (dt != null && dt.Rows.Count > 0)
  374. {
  375. // 把DataTable转换为IList<UserInfo>
  376. users = ModelConvertHelper<PurOrderDTEx>.ConvertToModel(dt);
  377. }
  378. #endregion
  379. string resultrow;
  380. string commandTextCount = "select count(*) from (" + commandText1;
  381. long totalcount = DataAccess.GetRowCountDefine(commandTextCount, parameters1.ToArray(), out resultrow);
  382. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  383. {
  384. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  385. };
  386. var jsonData = JsonConvert.SerializeObject(users, timejson);
  387. return Json(new
  388. {
  389. items = JsonConvert.DeserializeObject(jsonData),
  390. sum = new { },
  391. totalCount = totalcount
  392. });
  393. }
  394. [AuthPermission]
  395. [HttpPost]
  396. [Route("gsnotacp")]
  397. public JsonResult GspNotAcpData(string staffid, [FromBody] dynamic data)
  398. {
  399. var userid = getStaff("userid");
  400. //判断参数是否合法
  401. if (string.IsNullOrEmpty(userid))
  402. {
  403. return Json(new
  404. {
  405. success = 0,
  406. msg = "没有登陆",
  407. timeout = 1
  408. });
  409. }
  410. var sql0 = "select * from sup_Account where id = @userid";
  411. var param0 = new List<SqlParameter>();
  412. param0.Add(new SqlParameter("userid", int.Parse(userid)));
  413. var dt0 = new DataTable();
  414. DataAccess.GetValues(sql0, ref dt0, param0.ToArray(), out _);
  415. var purStaffId = string.Empty;
  416. if (dt0 != null && dt0.Rows.Count > 0)
  417. {
  418. purStaffId = dt0.Rows[0]["PurStaffId"].ToString();
  419. }
  420. List<QueryFilter> filterList = new List<QueryFilter>();
  421. int pageIndex = 1;
  422. int pageSize = 15;
  423. string sortField;
  424. int sortDirection = 0;
  425. string[] sumFields;
  426. if (data != null)
  427. {
  428. if (data.filters.Count > 0)
  429. {
  430. var list = JsonConvert.SerializeObject(data.filters);
  431. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  432. }
  433. pageIndex = data.pageIndex;
  434. pageSize = data.pageSize;
  435. sortField = data.sortField;
  436. sortDirection = data.sortDirection;
  437. sumFields = data.sumFields.ToObject<string[]>();
  438. }
  439. var isAce = sortDirection == 0;
  440. var queryCondition = string.Empty;
  441. var param = new List<SqlParameter>();
  442. var start = (pageIndex - 1) * pageSize;
  443. var end = (start + 1 + pageSize);
  444. var dt = new DataTable();
  445. if (filterList != null)
  446. {
  447. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(), out param, new PurInMt(), "A.");
  448. }
  449. string rulesql = FilterTranslator.ruleSql(ref param);
  450. var sql =
  451. $"select * from ";
  452. var sql1 = $"(select row_number() over (order by A.BillNo desc) as rownum," +
  453. $" H.StaffName,F.contact,G.contact as oppcontact,E.K_ContactId,E.OppContId,K_BillCode,A.* from GSPNOTACPMT A " +
  454. $" left join GSPINMT B on A.RfBillNo = B.BillNo and A.EntId = B.EntId " +
  455. $" left join(select billno, entid, RfBillNo, ROW_NUMBER() over(partition by billno order by billno asc) as rn from GSPINDT )C on C.BillNo = B.BillNo and rn = 1 and C.EntId = B.EntId" +
  456. $" left join PURNOTESMT D on D.BillNo = C.RfBillNo and D.EntId = C.EntId" +
  457. $" left join PurOrderMT E on E.BillCode = D.K_BillCode and E.EntId = D.EntId" +
  458. $" left join contactdoc F on F.ContactId = E.K_ContactId and F.EntId = E.EntId" +
  459. $" left join contactdoc G on G.ContactId = E.OppContId and G.EntId = E.EntId" +
  460. $" left join StaffDoc H on H.STAFFID = E.SaleManId and H.EntId = E.EntId" +
  461. $" where rn = 1 " +
  462. $"{queryCondition} " +
  463. $"{rulesql})AAA";
  464. var sql2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end;
  465. DataAccess.GetValues(sql + sql1 + sql2, ref dt, param.ToArray(), out var msg);
  466. IList<GSPNotAcpMT> result = new List<GSPNotAcpMT>();
  467. if (dt != null && dt.Rows.Count > 0)
  468. {
  469. result = ModelConvertHelper<GSPNotAcpMT>.ConvertToModel(dt);
  470. }
  471. var jsonData = JsonConvert.SerializeObject(result);
  472. var countSql =
  473. $"select count(1) from " +
  474. sql1;
  475. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out var msg1);
  476. return Json(new
  477. {
  478. items = JsonConvert.DeserializeObject(jsonData),
  479. sum = new { },
  480. totalCount = count
  481. });
  482. }
  483. [AuthPermission]
  484. [HttpPost]
  485. [Route("gsnotacpdt")]
  486. public JsonResult GspNotAcpDataDT(string staffid, [FromBody] dynamic data)
  487. {
  488. var userid = getStaff("userid");
  489. //判断参数是否合法
  490. if (string.IsNullOrEmpty(userid))
  491. {
  492. return Json(new
  493. {
  494. success = 0,
  495. msg = "没有登陆",
  496. timeout = 1
  497. });
  498. }
  499. var sql0 = "select * from sup_Account where id = @userid";
  500. var param0 = new List<SqlParameter>();
  501. param0.Add(new SqlParameter("userid", int.Parse(userid)));
  502. var dt0 = new DataTable();
  503. DataAccess.GetValues(sql0, ref dt0, param0.ToArray(), out _);
  504. var purStaffId = string.Empty;
  505. if (dt0 != null && dt0.Rows.Count > 0)
  506. {
  507. purStaffId = dt0.Rows[0]["PurStaffId"].ToString();
  508. }
  509. List<QueryFilter> filterList = new List<QueryFilter>();
  510. int pageIndex = 1;
  511. int pageSize = 15;
  512. string sortField;
  513. int sortDirection = 0;
  514. string[] sumFields;
  515. if (data != null)
  516. {
  517. if (data.filters.Count > 0)
  518. {
  519. var list = JsonConvert.SerializeObject(data.filters);
  520. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  521. }
  522. pageIndex = data.pageIndex;
  523. pageSize = data.pageSize;
  524. sortField = data.sortField;
  525. sortDirection = data.sortDirection;
  526. sumFields = data.sumFields.ToObject<string[]>();
  527. }
  528. var isAce = sortDirection == 0;
  529. var queryCondition = string.Empty;
  530. var param = new List<SqlParameter>();
  531. var start = (pageIndex - 1) * pageSize;
  532. var end = (start + 1 + pageSize);
  533. var dt = new DataTable();
  534. if (filterList != null)
  535. {
  536. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(), out param, new PurInMt(), "A.");
  537. }
  538. string rulesql = FilterTranslator.ruleSql(ref param);
  539. var sql =
  540. $"select * from ";
  541. var sql1 = $"(select row_number() over (order by A.BillNo desc) as rownum," +
  542. $"H.StaffName,F.contact,G.contact as oppcontact,H1.GoodsName," +
  543. $"E.K_ContactId,E.OppContId,A.*,B.BillCode from GSPNOTACPDT A" +
  544. $" left join GSPNOTACPMT B on A.BillNo = B.BillNo and B.EntId = A.EntId" +
  545. $" left join GSPINDT C on C.BillNo = B.RfBillNo and C.BillSn = A.BillSn and C.EntId = A.EntId" +//----订单验货
  546. $" left join PURNOTESMT D on D.BillNo = C.RfBillNo and D.EntId = C.EntId" +//--订单收货
  547. $" left join PurOrderMT E on E.BillCode = D.K_BillCode and E.EntId = D.EntId" +
  548. $" left join contactdoc F on F.ContactId = E.K_ContactId and F.EntId = E.EntId" +
  549. $" left join contactdoc G on G.ContactId = E.OppContId and G.EntId = E.EntId" +
  550. $" left join StaffDoc H on H.STAFFID = E.SaleManId and H.EntId = E.EntId" +
  551. $" left join GoodsDoc H1 on H1.GoodsId = A.GoodsId " +
  552. $"where 1=1 " +
  553. $"{queryCondition} " +
  554. $"{rulesql})AAA";
  555. var sql2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end;
  556. DataAccess.GetValues(sql + sql1 + sql2, ref dt, param.ToArray(), out var msg);
  557. IList<Temp2> result = new List<Temp2>();
  558. if (dt != null && dt.Rows.Count > 0)
  559. {
  560. result = ModelConvertHelper<Temp2>.ConvertToModel(dt);
  561. }
  562. var jsonData = JsonConvert.SerializeObject(result);
  563. var countSql =
  564. $"select count(1) from " +
  565. sql1;
  566. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out var msg1);
  567. return Json(new
  568. {
  569. items = result,
  570. sum = new { },
  571. totalCount = count,
  572. result = msg
  573. });
  574. }
  575. }
  576. internal class Temp
  577. {
  578. public string Key => Guid.NewGuid().ToString();
  579. public int BillNo { get; set; }
  580. public string Dates { get; set; }
  581. public string Address { get; set; }
  582. public string AccountRealName { get; set; }
  583. public string Delivery { get; set; }
  584. public string PayType { get; set; }
  585. public string Summaries { get; set; }
  586. public string BillCode { get; set; }
  587. public string InmtState { get; set; }
  588. public decimal k_pay { get; set; }
  589. public string k_kdcode { get; set; }
  590. public string SaleMan { get; set; }
  591. public string Supplier { get; set; }
  592. }
  593. internal class Temp2
  594. {
  595. public int BillNo { get; set; }
  596. public int BillSn { get; set; }
  597. public string EntId { get; set; }
  598. public int BillSort { get; set; }
  599. public string GoodsId { get; set; }
  600. public decimal Num { get; set; }
  601. public string unit { get; set; }
  602. public int Meas { get; set; }
  603. public string AngleId { get; set; }
  604. public string BatchCode { get; set; }
  605. public string ProduceDate { get; set; }
  606. public string SterilCode { get; set; }
  607. public string ValDate { get; set; }
  608. public string ArrivalDate { get; set; }
  609. public string ApprovalNo { get; set; }
  610. public decimal CheckNum { get; set; }
  611. public string Zhilbz { get; set; }
  612. public string Zhilwt { get; set; }
  613. public string AcceptId { get; set; }
  614. public string Yansrq { get; set; }
  615. public string Remark { get; set; }
  616. public string OwnerId { get; set; }
  617. public string constraint { get; set; }
  618. public string BillCode { get; set; }
  619. public string GoodsName { get; set; }
  620. public string StaffName { get; set; }
  621. public string Contact { get; set; }
  622. public string OppContact { get; set; }
  623. }
  624. internal class Temp3
  625. {
  626. public string Key => Guid.NewGuid().ToString();
  627. public int BillNo { get; set; }
  628. public string BillCode { get; set; }
  629. public string Dates { get; set; }
  630. public string SaleManId { get; set; }
  631. public decimal Amount { get; set; }
  632. public string IsInvoice { get; set; }
  633. public string OrgId { get; set; }
  634. public string DeptId { get; set; }
  635. public string Invoice { get; set; }
  636. public string OlderNo { get; set; }
  637. public string K_DFBillCode { get; set; }
  638. public string K_BillCode { get; set; }
  639. public string WareManId { get; set; }
  640. public string OppContId { get; set; }
  641. public string PayOrgId { get; set; }
  642. public string Contact { get; set; }
  643. public string OppContact { get; set; }
  644. public string StaffName { get; set; }
  645. }
  646. internal class Temp4
  647. {
  648. public string Key => Guid.NewGuid().ToString();
  649. public int BillNo { get; set; }
  650. public int BillSn { get; set; }
  651. public string GoodsId { get; set; }
  652. public decimal Num { get; set; }
  653. public string GoodsName { get; set; }
  654. public decimal Amount { get; set; }
  655. public string IsInvoice { get; set; }
  656. public string Remark { get; set; }
  657. public string Kdcode { get; set; }
  658. }
  659. }
  660. public class Filter
  661. {
  662. public string field { get; set; }
  663. public string operate { get; set; }
  664. public string value { get; set; }
  665. }