mem_ProductController.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Net.Http.Headers;
  8. using System.Threading.Tasks;
  9. using Common.Model;
  10. using CoreEntity.Entity;
  11. using CoreEntity.ESEntity;
  12. using JCSoft.WX.Framework.Api;
  13. using MemberWeb.Commonss;
  14. using Microsoft.AspNetCore.Hosting;
  15. using Microsoft.AspNetCore.Mvc;
  16. using Microsoft.Extensions.Caching.Memory;
  17. using Newtonsoft.Json;
  18. using Newtonsoft.Json.Converters;
  19. using Newtonsoft.Json.Linq;
  20. using NPOI.HSSF.UserModel;
  21. using PublicLibrary.Model;
  22. using SupplierWeb.Commonss;
  23. using ZcPeng.PublicLibrary;
  24. using Num = CoreEntity.ESEntity.Num;
  25. namespace SupplierWeb.Controllers
  26. {
  27. [Route("web/memProduct")]
  28. public class mem_ProductController : BaseController
  29. {
  30. private readonly IHostingEnvironment _hostingEnvironment;
  31. public mem_ProductController(IHostingEnvironment hostingEnvironmen,IMemoryCache cache, IApiClient client) : base(cache, client)
  32. {
  33. _hostingEnvironment = hostingEnvironmen;
  34. }
  35. public IActionResult Index()
  36. {
  37. return View();
  38. }
  39. /// <summary>
  40. /// 产品列表
  41. /// </summary>
  42. /// <param name="data"></param>
  43. /// <param name="filters"></param>
  44. /// <returns></returns>
  45. [HttpPost]
  46. [Route("AllproductList")]
  47. public ActionResult AllTagList(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  48. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  49. {
  50. if (data != null)
  51. {
  52. filters = data.filters.ToObject<QueryFilter[]>();
  53. pageIndex = data.pageIndex;
  54. pageSize = data.pageSize;
  55. sortField = data.sortField;
  56. sortDirection = data.sortDirection;
  57. sumFields = data.sumFields.ToObject<string[]>();
  58. }
  59. DataTable dt = new DataTable();
  60. string result;
  61. IList<Mem_Product> permss = new List<Mem_Product>(0);
  62. List<SqlParameter> parameters = new List<SqlParameter>();
  63. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Mem_Product(), "p.");
  64. string direct = " desc ";
  65. if (sortDirection != 1)
  66. {
  67. direct = " asc";
  68. }
  69. if (sortField==null|| sortField=="") {
  70. sortField = " A.LastModified ";
  71. }
  72. int start = (pageIndex - 1) * pageSize;
  73. int end = (start + 1 + pageSize);
  74. string commandText0 = "select * from ";
  75. string commandText1 = "(" +
  76. "select A.*,row_number() over( order by " + sortField + direct + " ) as rownum from (SELECT p.*,t.TypeName FROM mem_ingProduct p LEFT JOIN mem_ingProductType t ON p.ProductType=t.TypeId WHERE p.IsDelete=1 " + filterstr +
  77. ") as A where 1=1 )AAA ";
  78. string commandText2 = " where AAA.rownum > "+ start + " and AAA.rownum < "+ end + " ORDER BY AAA.LastModified desc ";
  79. string commandText3 = commandText0 + commandText1+commandText2;
  80. bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
  81. if (dt != null && dt.Rows.Count > 0)
  82. {
  83. // 把DataTable转换为IList<T>
  84. permss = ModelConvertHelper<Mem_Product>.ConvertToModel(dt);
  85. }
  86. foreach (Mem_Product pd in permss) {
  87. pd.dt=getProductPic(pd.ProductCode);
  88. }
  89. string result1;
  90. long totalcount = DataAccess.GetRowCountDefine("select count(1) from " + commandText1, parameters.ToArray(), out result1);
  91. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  92. {
  93. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  94. };
  95. //IList<Menu> menus = Permission.Convert(permss);
  96. var jsonData = JsonConvert.SerializeObject(permss, timejson);
  97. return Json(new
  98. {
  99. items = JsonConvert.DeserializeObject(jsonData),
  100. sum = new { },
  101. totalCount = totalcount
  102. });
  103. }
  104. /// <summary>
  105. /// 商品等级定价列表
  106. /// </summary>
  107. /// <param name="filters"></param>
  108. /// <param name="pageIndex"></param>
  109. /// <param name="pageSize"></param>
  110. /// <param name="sortField"></param>
  111. /// <param name="sortDirection"></param>
  112. /// <param name="sumFields"></param>
  113. /// <param name="data"></param>
  114. /// <returns></returns>
  115. [HttpPost]
  116. [Route("AllproductLevel")]
  117. public ActionResult AllproductLevel(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  118. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  119. {
  120. if (data != null)
  121. {
  122. filters = data.filters.ToObject<QueryFilter[]>();
  123. pageIndex = data.pageIndex;
  124. pageSize = data.pageSize;
  125. sortField = data.sortField;
  126. sortDirection = data.sortDirection;
  127. sumFields = data.sumFields.ToObject<string[]>();
  128. }
  129. DataTable dt = new DataTable();
  130. string result;
  131. IList<Mem_Product> permss = new List<Mem_Product>(0);
  132. List<SqlParameter> parameters = new List<SqlParameter>();
  133. QueryFilter[] jArray = JsonConvert.DeserializeObject<QueryFilter[]>(data.filters.ToString());
  134. List<QueryFilter> filterList = new List<QueryFilter>();
  135. string LevelId = "";
  136. foreach (QueryFilter filter in jArray)
  137. {
  138. if (filter.field == "LevelId")
  139. LevelId = filter.value.ToString();
  140. else
  141. {
  142. filterList.Add(filter);
  143. }
  144. }
  145. //string filterstr = QueryFilter.getFilterSqlParam(filterList.ToArray(), out parameters, new Mem_Product(), "A.");
  146. string direct = " desc ";
  147. if (sortDirection != 1)
  148. {
  149. direct = " asc";
  150. }
  151. if (sortField == null || sortField == "")
  152. {
  153. sortField = " A.LastModified ";
  154. }
  155. int start = (pageIndex - 1) * pageSize;
  156. int end = (start + 1 + pageSize);
  157. string commandText0 = "select * from ";
  158. string commandText1 = "(" +
  159. "select A.*,row_number() over( order by " + sortField + direct + " ) as rownum from ( "+
  160. "SELECT p.ProductCode,p.ProductObject,p.ProductName,p.ProductDesc,p.ProductType,p.Manufacturer,p.PurchasePrice,p.Amount,p.State,p.ProductText,p.CreationDate,p.LastModified,t.TypeName,l.MarketIng,l.MarketPrice,l.LevelId from mem_ingProductLevel l " +
  161. "LEFT JOIN mem_ingProduct p ON l.ProductCode = p.ProductCode LEFT JOIN mem_ingProductType t ON p.ProductType = t.TypeId WHERE p.IsDelete = 1"+
  162. ") as A where 1=1 and A.LevelId='"+ LevelId + "')AAA ";
  163. string commandText2 = " where AAA.rownum > " + start + " and AAA.rownum < " + end + " ORDER BY AAA.LastModified desc ";
  164. string commandText3 = commandText0 + commandText1 + commandText2;
  165. bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
  166. if (dt != null && dt.Rows.Count > 0)
  167. {
  168. // 把DataTable转换为IList<T>
  169. permss = ModelConvertHelper<Mem_Product>.ConvertToModel(dt);
  170. }
  171. foreach (Mem_Product pd in permss)
  172. {
  173. pd.dt = getProductPic(pd.ProductCode);
  174. }
  175. string result1;
  176. long totalcount = DataAccess.GetRowCountDefine("select count(1) from " + commandText1, parameters.ToArray(), out result1);
  177. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  178. {
  179. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  180. };
  181. //IList<Menu> menus = Permission.Convert(permss);
  182. var jsonData = JsonConvert.SerializeObject(permss, timejson);
  183. return Json(new
  184. {
  185. items = JsonConvert.DeserializeObject(jsonData),
  186. sum = new { },
  187. totalCount = totalcount
  188. });
  189. }
  190. [HttpGet]
  191. [Route("getlevel")]
  192. public JsonResult getrole()
  193. {
  194. var sql = $"SELECT id as value,'0' as parentValue,name as label from mem_user_level";
  195. DataTable dt = new DataTable();
  196. var param = new List<SqlParameter>();
  197. DataAccess.GetValues(sql, ref dt, param.ToArray(), out _);
  198. IList<mem_userLevel> result = new List<mem_userLevel>();
  199. if (dt != null && dt.Rows.Count > 0)
  200. {
  201. result = ModelConvertHelper<mem_userLevel>.ConvertToModel(dt);
  202. }
  203. return Json(new
  204. {
  205. result
  206. });
  207. }
  208. /// <summary>
  209. /// 上传图片
  210. /// </summary>
  211. /// <returns></returns>
  212. [HttpPost]
  213. [Route("uploadprofile")]
  214. public JsonResult UploadPrfile()
  215. {
  216. var files = Request.Form.Files;
  217. foreach (var file in files)
  218. {
  219. var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
  220. string filePath = _hostingEnvironment.WebRootPath;
  221. if (!Directory.Exists(filePath + Path.DirectorySeparatorChar + "UploadFiles" + Path.DirectorySeparatorChar))
  222. {
  223. Directory.CreateDirectory(filePath + Path.DirectorySeparatorChar + "UploadFiles" + Path.DirectorySeparatorChar);
  224. }
  225. var fileType = Path.GetExtension(fileName).Substring(1);
  226. fileName = Guid.NewGuid() + Path.GetExtension(fileName);
  227. var vpath = "/UploadFiles/" + fileName;
  228. string fileFullName = filePath + vpath;
  229. using (FileStream fs = System.IO.File.Create(fileFullName))
  230. {
  231. file.CopyTo(fs);
  232. fs.Flush();
  233. }
  234. return new JsonResult(new
  235. {
  236. success = true,
  237. //path = result
  238. path = vpath
  239. });
  240. }
  241. return new JsonResult(new
  242. {
  243. success = false,
  244. path = string.Empty
  245. });
  246. }
  247. /// <summary>
  248. /// 修改添加商品
  249. /// </summary>
  250. /// <param name="data"></param>
  251. /// <param name="staffId"></param>
  252. /// <returns></returns>
  253. [HttpPost]
  254. [Route("addMemProduct")]
  255. public JsonResult addMemProduct( [FromBody]dynamic data, string staffId)
  256. {
  257. string accountId = getStaff(staffId, "userid");
  258. List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
  259. Mem_Product product = new Mem_Product();
  260. //判断参数是否合法
  261. if (string.IsNullOrEmpty(accountId))
  262. {
  263. return Json(new
  264. {
  265. timeout = false,
  266. msg = "没有登陆"
  267. });
  268. }
  269. string productCode = Convert.ToString(Guid.NewGuid());
  270. if (data != null)
  271. {
  272. product.MarketPrice = data.MarketPrice;//默认价格
  273. product.MarketIng = data.MarketIng;//默认积分
  274. product.ProductCode = data.ProductCode;//商品编号
  275. product.ProductName = data.ProductName;//商品名称
  276. product.ProductObject = data.ProductObject;//产品属性
  277. product.ProductDesc = data.ProductDesc;//产品概要
  278. product.Manufacturer = data.Mnufacturer;//供应商
  279. product.PurchasePrice = data.PurchasePrice;//成本价
  280. product.Amount = data.Amount;//库存
  281. product.ProductText = data.ProductText;//详细
  282. }
  283. int success = 0;
  284. string msg = "";
  285. //查询商品是否存在
  286. string result1;
  287. long totalcount = -1;
  288. if (product.ProductCode != null && product.ProductCode!="") {
  289. List<SqlParameter> parameters = new List<SqlParameter>();
  290. totalcount = DataAccess.GetRowCountDefine("select count(1) from mem_ingProduct where ProductCode='"+ product.ProductCode + "'", parameters.ToArray(), out result1);
  291. }
  292. string logStr = "";
  293. if (totalcount<=0)
  294. {
  295. //添加
  296. var sql = "INSERT INTO mem_ingProduct(ProductCode,ProductObject,ProductName,ProductDesc,Manufacturer,PurchasePrice,Amount,ProductText,MarketPrice,MarketIng,CreationDate) Values(" +
  297. "@ProductCode,@ProductObject,@ProductName,@ProductDesc,@Manufacturer,@PurchasePrice,@Amount,@ProductText,@MarketPrice,@MarketIng,@CreationDate)";
  298. var param = new List<SqlParameter>();
  299. product.ProductCode = productCode;
  300. param.Add(new SqlParameter("ProductCode", productCode));
  301. param.Add(new SqlParameter("ProductObject", product.ProductObject));
  302. param.Add(new SqlParameter("ProductName", product.ProductName));
  303. param.Add(new SqlParameter("ProductDesc", product.ProductDesc));
  304. param.Add(new SqlParameter("Manufacturer", product.Manufacturer));
  305. param.Add(new SqlParameter("PurchasePrice", product.PurchasePrice));
  306. param.Add(new SqlParameter("Amount", product.Amount));
  307. param.Add(new SqlParameter("ProductText", product.ProductText));
  308. param.Add(new SqlParameter("MarketPrice", product.MarketPrice));
  309. param.Add(new SqlParameter("MarketIng", product.MarketIng));
  310. param.Add(new SqlParameter("CreationDate", DateTime.Now));
  311. success = DataAccess.ExecuteCommand(sql, param, out msg);
  312. logStr = "添加商品:"+ product.ProductName;
  313. }
  314. else
  315. {
  316. string sql = "UPDATE mem_ingProduct SET ProductObject=@ProductObject,ProductName=@ProductName,ProductDesc=@ProductDesc,Manufacturer=@Manufacturer ,PurchasePrice=@PurchasePrice,Amount=@Amount,ProductText=@ProductText,MarketPrice=@MarketPrice,MarketIng=@MarketIng,LastModified=@LastModified WHERE ProductCode = @ProductCode";
  317. //准备参数
  318. List<List<Object>> parametersC = new List<List<Object>>();
  319. parametersC.Add(new List<Object>() { "ProductObject", product.ProductObject });
  320. parametersC.Add(new List<Object>() { "ProductName", product.ProductName });
  321. parametersC.Add(new List<Object>() { "ProductDesc", product.ProductDesc });
  322. parametersC.Add(new List<Object>() { "Manufacturer", product.Manufacturer });
  323. parametersC.Add(new List<Object>() { "PurchasePrice", product.PurchasePrice });
  324. parametersC.Add(new List<Object>() { "Amount", product.Amount });
  325. parametersC.Add(new List<Object>() { "ProductText", product.ProductText });
  326. parametersC.Add(new List<Object>() { "MarketPrice", product.MarketPrice });
  327. parametersC.Add(new List<Object>() { "MarketIng", product.MarketIng });
  328. parametersC.Add(new List<Object>() { "LastModified", DateTime.Now });
  329. parametersC.Add(new List<Object>() { "ProductCode", product.ProductCode });
  330. List<SqlParameter> parametersC1 = DataAccess.ToParameters(parametersC);
  331. success = DataAccess.ExecuteCommand(sql, parametersC1, out msg);
  332. logStr = "修改商品:" + product.ProductName;
  333. }
  334. if (success>0) {
  335. //商品图片
  336. string fileimg = JsonConvert.SerializeObject(data.fileImg);
  337. addProductPic(product.ProductCode,fileimg);
  338. //记录日志
  339. addProductLog(accountId,"1", logStr, product.ProductCode);
  340. }
  341. return Json(new
  342. {
  343. success = success,
  344. msg = msg
  345. });
  346. }
  347. /// <summary>
  348. /// 上下架
  349. /// </summary>
  350. /// <param name="data"></param>
  351. /// <returns></returns>
  352. [HttpPost]
  353. [Route("updaState")]
  354. public JsonResult updaState([FromBody]dynamic data) {
  355. string msg = "";
  356. if (data!=null && data.State!=null && data.ProductCode!=null) {
  357. string sql = "UPDATE mem_ingProduct SET State='"+ data.State + "' WHERE ProductCode = '" + data.ProductCode + "'";
  358. //准备参数
  359. List<List<Object>> parametersC = new List<List<Object>>();
  360. List<SqlParameter> parametersC1 = DataAccess.ToParameters(parametersC);
  361. int success = DataAccess.ExecuteCommand(sql, parametersC1, out msg);
  362. }
  363. return Json(new
  364. {
  365. obj = msg
  366. });
  367. }
  368. /// <summary>
  369. /// 获取商品日志
  370. /// </summary>
  371. /// <param name="data"></param>
  372. /// <param name="staffId"></param>
  373. /// <returns></returns>
  374. [HttpPost]
  375. [Route("getProductLog")]
  376. public JsonResult getProductLog([FromBody]dynamic data, string staffId)
  377. {
  378. string accountId = getStaff(staffId, "userid");
  379. //判断参数是否合法
  380. if (string.IsNullOrEmpty(accountId))
  381. {
  382. return Json(new
  383. {
  384. timeout = false,
  385. msg = "没有登陆"
  386. });
  387. }
  388. DataTable dt = new DataTable();
  389. if (data!=null && data.productCode!=null) {
  390. List<SqlParameter> parameters = new List<SqlParameter>();
  391. string commandText = "SELECT l.*,a.AccountRealName FROM mem_ingProductLog l LEFT JOIN mem_Account a ON l.MemberId=a.Id WHERE l.logCode=1 AND l.Value='" + data.productCode + "' ORDER BY CreationDate DESC ";
  392. string result;
  393. bool success = DataAccess.GetValues(commandText, ref dt, parameters.ToArray(), out result);
  394. }
  395. return Json(new
  396. {
  397. obj = dt
  398. }) ;
  399. }
  400. /// <summary>
  401. /// 获取商品等级价格
  402. /// </summary>
  403. /// <param name="data"></param>
  404. /// <param name="staffId"></param>
  405. /// <returns></returns>
  406. [HttpPost]
  407. [Route("getProductLevel")]
  408. public JsonResult getProductLevel([FromBody]dynamic data, string staffId)
  409. {
  410. string accountId = getStaff(staffId, "userid");
  411. //判断参数是否合法
  412. if (string.IsNullOrEmpty(accountId))
  413. {
  414. return Json(new
  415. {
  416. timeout = false,
  417. msg = "没有登陆"
  418. });
  419. }
  420. DataTable dt = new DataTable();
  421. if (data != null && data.productCode != null)
  422. {
  423. List<SqlParameter> parameters = new List<SqlParameter>();
  424. string commandText = "SELECT l.name,l.[level],l.id,p.ProductCode,m.MarketIng,m.MarketPrice FROM [mem_user_level] l LEFT JOIN mem_ingProductLevel m ON m.levelId=l.id AND m.ProductCode='"+ data.productCode + "' LEFT JOIN mem_ingProduct p ON p.ProductCode=M.ProductCode";
  425. string result;
  426. bool success = DataAccess.GetValues(commandText, ref dt, parameters.ToArray(), out result);
  427. }
  428. return Json(new
  429. {
  430. obj = dt
  431. });
  432. }
  433. [HttpPost]
  434. [Route("addMemProductLevel")]
  435. public JsonResult addMemProductLevel([FromBody]dynamic data, string staffId,string ProductCode,string levelProduct)
  436. {
  437. string accountId = getStaff(staffId, "userid");
  438. List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
  439. //判断参数是否合法
  440. if (string.IsNullOrEmpty(accountId))
  441. {
  442. return Json(new
  443. {
  444. timeout = false,
  445. msg = "没有登陆"
  446. });
  447. }
  448. int success = 0;
  449. string msg = "";
  450. if (data!=null) {
  451. ProductCode = data.ProductCode;//商品ID
  452. levelProduct = JsonConvert.SerializeObject(data.levelProduct);//定价
  453. JArray jArray = JArray.Parse(levelProduct);
  454. int success1 = 0;
  455. if (jArray.Count > 0)
  456. {
  457. string imgStr = "";
  458. foreach (var jj in jArray)
  459. {
  460. string PlId = "";
  461. JObject job = (JObject)jj;
  462. string MarketIng = job["MarketIng"].ToString();
  463. string MarketPrice = job["MarketPrice"].ToString();
  464. string LevelId = job["id"].ToString();
  465. if (MarketIng!=null&& MarketPrice!=null&& MarketIng != "" && MarketPrice != "") {
  466. string plId = Convert.ToString(Guid.NewGuid());
  467. //查询等级是否存在
  468. string result1;
  469. long totalcount = -1;
  470. if (ProductCode != null && ProductCode != "" && LevelId != null && LevelId != "")
  471. {
  472. List<SqlParameter> parameters = new List<SqlParameter>();
  473. totalcount = DataAccess.GetRowCountDefine("SELECT count(1) from mem_ingProductLevel WHERE ProductCode='" + ProductCode + "' AND levelId='" + LevelId + "'", parameters.ToArray(), out result1);
  474. }
  475. string logStr = "";
  476. if (totalcount <= 0)
  477. {
  478. //添加
  479. var sql = "INSERT INTO mem_ingProductLevel(PlId,ProductCode,LevelId,MarketIng,MarketPrice,CreationDate) Values(" +
  480. "@PlId,@ProductCode,@LevelId,@MarketIng,@MarketPrice,@CreationDate)";
  481. var param = new List<SqlParameter>();
  482. PlId = plId;
  483. param.Add(new SqlParameter("PlId", PlId));
  484. param.Add(new SqlParameter("ProductCode", ProductCode));
  485. param.Add(new SqlParameter("LevelId", LevelId));
  486. param.Add(new SqlParameter("MarketIng", MarketIng));
  487. param.Add(new SqlParameter("MarketPrice", MarketPrice));
  488. param.Add(new SqlParameter("CreationDate", DateTime.Now));
  489. success = DataAccess.ExecuteCommand(sql, param, out msg);
  490. logStr = "产品等级定价:" + ProductCode + "levelId:" + LevelId;
  491. }
  492. else
  493. {
  494. string sql = "UPDATE mem_ingProductLevel SET MarketIng=@MarketIng,MarketPrice=@MarketPrice WHERE ProductCode = @ProductCode and LevelId = @LevelId";
  495. //准备参数
  496. List<List<Object>> parametersC = new List<List<Object>>();
  497. parametersC.Add(new List<Object>() { "MarketIng", MarketIng });
  498. parametersC.Add(new List<Object>() { "MarketPrice", MarketPrice });
  499. parametersC.Add(new List<Object>() { "ProductCode", ProductCode });
  500. parametersC.Add(new List<Object>() { "LevelId", LevelId });
  501. List<SqlParameter> parametersC1 = DataAccess.ToParameters(parametersC);
  502. success = DataAccess.ExecuteCommand(sql, parametersC1, out msg);
  503. logStr = "产品等级定价:" + ProductCode + "levelId:" + LevelId;
  504. }
  505. if (success > 0)
  506. {
  507. //记录日志
  508. addProductLog(accountId, "5", logStr, ProductCode);
  509. }
  510. }
  511. }
  512. }
  513. }
  514. /*if (data != null)
  515. {
  516. ProductCode = data.ProductCode;
  517. MarketIng = data.MarketIng;
  518. MarketPrice = data.MarketPrice;
  519. LevelId = data.LevelId;
  520. }*/
  521. return Json(new
  522. {
  523. success = success,
  524. msg = msg
  525. });
  526. }
  527. public DataTable getProductPic(string productCode)
  528. {
  529. DataTable dt = new DataTable();
  530. if (productCode != null)
  531. {
  532. List<SqlParameter> parameters = new List<SqlParameter>();
  533. string commandText = "SELECT top 8 * FROM mem_ingProductPic WHERE IsDelete='1' AND ProductCode='" + productCode + "' ORDER BY CreationDate DESC ";
  534. string result;
  535. bool success = DataAccess.GetValues(commandText, ref dt, parameters.ToArray(), out result);
  536. }
  537. return dt;
  538. }
  539. /// <summary>
  540. /// 记录日志
  541. /// </summary>
  542. /// <returns></returns>
  543. public static int addProductLog(string MemberId,string logCode,string key="",string Value="", string Text = "") {
  544. int success = 0;
  545. if (MemberId!=null&& logCode!=null) {
  546. var sql = "INSERT INTO [dbo].[mem_ingProductLog] ([MemberId], [logCode], [CreationDate], [key], [Text], [Value]) VALUES ( @MemberId, @logCode, @CreationDate, @key, @Text, @Value)";
  547. var param = new List<SqlParameter>();
  548. param.Add(new SqlParameter("MemberId", MemberId));
  549. param.Add(new SqlParameter("logCode", logCode));
  550. param.Add(new SqlParameter("CreationDate", DateTime.Now));
  551. param.Add(new SqlParameter("key", key));
  552. param.Add(new SqlParameter("Text", Text));
  553. param.Add(new SqlParameter("Value", Value));
  554. string msg = "";
  555. success = DataAccess.ExecuteCommand(sql, param, out msg);
  556. }
  557. return success;
  558. }
  559. /// <summary>
  560. /// 商品类目
  561. /// </summary>
  562. /// <param name="filters"></param>
  563. /// <param name="pageIndex"></param>
  564. /// <param name="pageSize"></param>
  565. /// <param name="sortField"></param>
  566. /// <param name="sortDirection"></param>
  567. /// <param name="sumFields"></param>
  568. /// <param name="data"></param>
  569. /// <returns></returns>
  570. [HttpPost]
  571. [Route("AllproductType")]
  572. public ActionResult AllproductType(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  573. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  574. {
  575. if (data != null)
  576. {
  577. filters = data.filters.ToObject<QueryFilter[]>();
  578. pageIndex = data.pageIndex;
  579. pageSize = data.pageSize;
  580. sortField = data.sortField;
  581. sortDirection = data.sortDirection;
  582. sumFields = data.sumFields.ToObject<string[]>();
  583. }
  584. DataTable dt = new DataTable();
  585. string result;
  586. IList<mem_productType> permss = new List<mem_productType>(0);
  587. List<SqlParameter> parameters = new List<SqlParameter>();
  588. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new mem_productType(), "t.");
  589. int start = (pageIndex - 1) * pageSize;
  590. int end = (start + 1 + pageSize);
  591. string commandText0 = "select * from ";
  592. string commandText1 = "( select * ,row_number() over(order by t.CreationDate desc ) as rownum,(SELECT count(1) FROM mem_ingProduct WHERE ProductType=t.TypeId) as ProductCn from mem_ingProductType t where 1=1 "+ filterstr + " )AAA ";
  593. string commandText2 = " where AAA.rownum > " + start + " and AAA.rownum < " + end + " ORDER BY AAA.CreationDate desc ";
  594. string commandText3 = commandText0 + commandText1 + commandText2;
  595. bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
  596. if (dt != null && dt.Rows.Count > 0)
  597. {
  598. // 把DataTable转换为IList<T>
  599. permss = ModelConvertHelper<mem_productType>.ConvertToModel(dt);
  600. }
  601. string result1;
  602. long totalcount = DataAccess.GetRowCountDefine("select count(1) from " + commandText1, parameters.ToArray(), out result1);
  603. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  604. {
  605. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  606. };
  607. var jsonData = JsonConvert.SerializeObject(permss, timejson);
  608. return Json(new
  609. {
  610. items = JsonConvert.DeserializeObject(jsonData),
  611. sum = new { },
  612. totalCount = totalcount
  613. });
  614. }
  615. /// <summary>
  616. /// 修改商品类目
  617. /// </summary>
  618. /// <param name="data"></param>
  619. /// <param name="staffId"></param>
  620. /// <returns></returns>
  621. [HttpPost]
  622. [Route("editProductType")]
  623. public JsonResult editProductType([FromBody]dynamic data, string staffId,string typeId,string productCode,string productName)
  624. {
  625. string accountId = getStaff(staffId, "userid");
  626. //判断参数是否合法
  627. if (string.IsNullOrEmpty(accountId))
  628. {
  629. return Json(new
  630. {
  631. timeout = false,
  632. msg = "没有登陆"
  633. });
  634. }
  635. if (data != null)
  636. {
  637. typeId = data.typeId;
  638. productCode = data.productCode;
  639. productName = data.productName;
  640. }
  641. int success = 0;
  642. string msg = "";
  643. string logStr = "";
  644. if (productCode!=null && productCode!="" && typeId!=null && typeId!="") {
  645. var productCodes = productCode.Split(",");//多选
  646. foreach (string id in productCodes) {
  647. string sql = "UPDATE mem_ingProduct SET ProductType=@ProductType WHERE ProductCode = @ProductCode";
  648. //准备参数
  649. List<List<Object>> parametersC = new List<List<Object>>();
  650. parametersC.Add(new List<Object>() { "ProductType", typeId });
  651. parametersC.Add(new List<Object>() { "ProductCode", id });
  652. List<SqlParameter> parametersC1 = DataAccess.ToParameters(parametersC);
  653. success = DataAccess.ExecuteCommand(sql, parametersC1, out msg);
  654. }
  655. logStr = "商品修改分类:" +productCode + productName;
  656. }
  657. if (success>0) {
  658. //记录日志
  659. addProductLog(accountId, "4", logStr);
  660. }
  661. return Json(new
  662. {
  663. success = success,
  664. msg = msg
  665. });
  666. }
  667. [HttpPost]
  668. [Route("addMemProductType")]
  669. public JsonResult addMemProductType([FromBody]dynamic data, string staffId, string typeId, string typeName, string code)
  670. {
  671. string accountId = getStaff(staffId, "userid");
  672. //判断参数是否合法
  673. if (string.IsNullOrEmpty(accountId))
  674. {
  675. return Json(new
  676. {
  677. timeout = false,
  678. msg = "没有登陆"
  679. });
  680. }
  681. if (data != null)
  682. {
  683. typeId = data.typeId;
  684. typeName = data.typeName;
  685. code = data.code;
  686. }
  687. int success = 0;
  688. string msg = "";
  689. string logStr = "";
  690. if (code == "1")
  691. {
  692. //添加
  693. var sql = "INSERT INTO mem_ingProductType (TypeId,TypeName,CreationDate)VALUES(@TypeId,@TypeName,@CreationDate)";
  694. var param = new List<SqlParameter>();
  695. param.Add(new SqlParameter("TypeId", Guid.NewGuid()));
  696. param.Add(new SqlParameter("typeName", typeName));
  697. param.Add(new SqlParameter("CreationDate", DateTime.Now));
  698. success = DataAccess.ExecuteCommand(sql, param, out msg);
  699. logStr = "新增分类:" + typeName;
  700. }
  701. else
  702. {
  703. string sql = "UPDATE mem_ingProductType SET TypeName=@TypeName WHERE TypeId = @TypeId";
  704. //准备参数
  705. List<List<Object>> parametersC = new List<List<Object>>();
  706. parametersC.Add(new List<Object>() { "TypeName", typeName });
  707. parametersC.Add(new List<Object>() { "TypeId", typeId });
  708. List<SqlParameter> parametersC1 = DataAccess.ToParameters(parametersC);
  709. success = DataAccess.ExecuteCommand(sql, parametersC1, out msg);
  710. logStr = "修改分类:" + typeName;
  711. }
  712. if (success > 0)
  713. {
  714. //记录日志
  715. addProductLog(accountId, "4", logStr);
  716. }
  717. return Json(new
  718. {
  719. success = success,
  720. msg = msg
  721. });
  722. }
  723. public static int addProductPic(string ProductCode, string fileimg) {
  724. JArray jArray = JArray.Parse(fileimg);
  725. int success1 = 0;
  726. if (jArray.Count > 0)
  727. {
  728. string imgStr = "";
  729. foreach (var jj in jArray)
  730. {
  731. JObject job = (JObject)jj;
  732. string url = job["url"].ToString();//图片地址
  733. List<SqlParameter> parameters = new List<SqlParameter>();
  734. if (ProductCode != null && ProductCode != "")
  735. {
  736. imgStr += "('" + ProductCode + "','" + url + "'),";
  737. }
  738. }
  739. imgStr = "DELETE FROM mem_ingProductPic WHERE ProductCode='" + ProductCode + "';INSERT INTO mem_ingProductPic(ProductCode,PicUrl)Values" + imgStr.Substring(0, imgStr.Length - 1);
  740. //imgStr = "UPDATE mem_ingProductPic SET IsDelete=0 WHERE ProductCode='" + ProductCode + "';INSERT INTO mem_ingProductPic(ProductCode,PicUrl)Values" + imgStr.Substring(0, imgStr.Length - 1);
  741. var param = new List<SqlParameter>();
  742. string msg1 = "";
  743. success1 = DataAccess.ExecuteCommand(imgStr, param, out msg1);
  744. }
  745. return success1;
  746. }
  747. }
  748. }