UserStoreChangeController.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * 创客库存变动记录
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Data;
  10. using System.Threading.Tasks;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.Extensions.Logging;
  14. using Microsoft.Extensions.Options;
  15. using MySystem.Models;
  16. using Library;
  17. using LitJson;
  18. using MySystemLib;
  19. namespace MySystem.Areas.Admin.Controllers
  20. {
  21. [Area("Admin")]
  22. [Route("Admin/[controller]/[action]")]
  23. public class UserStoreChangeController : BaseController
  24. {
  25. public UserStoreChangeController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  26. {
  27. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  28. }
  29. #region 创客库存变动记录列表
  30. /// <summary>
  31. /// 根据条件查询创客库存变动记录列表
  32. /// </summary>
  33. /// <returns></returns>
  34. public IActionResult Index(UserStoreChange data, string right)
  35. {
  36. ViewBag.RightInfo = RightInfo;
  37. ViewBag.right = right;
  38. return View();
  39. }
  40. #endregion
  41. #region 根据条件查询创客库存变动记录列表
  42. /// <summary>
  43. /// 创客库存变动记录列表
  44. /// </summary>
  45. /// <returns></returns>
  46. public JsonResult IndexData(UserStoreChange data, string UserIdMakerCode, string UserIdRealName, string BindMerchantIdMerchantNo, string BindMerchantIdMerchantName, string BrandIdSelect, string TransTypeSelect, string StockOpDirectSelect, string SnStatusSelect, string BindStatusSelect, string ActiveStatusSelect, string BrandTypeSelect, int page = 1, int limit = 30)
  47. {
  48. Dictionary<string, string> Fields = new Dictionary<string, string>();
  49. Fields.Add("CreateDate", "3"); //时间
  50. Fields.Add("SnNo", "1"); //SN编号
  51. string condition = " and Status>-1";
  52. //创客编号
  53. if (!string.IsNullOrEmpty(UserIdMakerCode))
  54. {
  55. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  56. }
  57. //创客真实姓名
  58. if (!string.IsNullOrEmpty(UserIdRealName))
  59. {
  60. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  61. }
  62. //产品类型
  63. if (!string.IsNullOrEmpty(BrandIdSelect))
  64. {
  65. condition += " and BrandId=" + BrandIdSelect;
  66. }
  67. //交易类型
  68. if (!string.IsNullOrEmpty(TransTypeSelect))
  69. {
  70. condition += " and TransType=" + TransTypeSelect;
  71. }
  72. //库存操作方向
  73. if (!string.IsNullOrEmpty(StockOpDirectSelect))
  74. {
  75. condition += " and StockOpDirect=" + StockOpDirectSelect;
  76. }
  77. //SN状态
  78. if (!string.IsNullOrEmpty(SnStatusSelect))
  79. {
  80. condition += " and SnStatus=" + SnStatusSelect;
  81. }
  82. //绑定状态
  83. if (!string.IsNullOrEmpty(BindStatusSelect))
  84. {
  85. condition += " and BindStatus=" + BindStatusSelect;
  86. }
  87. //激活状态
  88. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  89. {
  90. condition += " and ActiveStatus=" + ActiveStatusSelect;
  91. }
  92. //绑定商户商户编号
  93. if (!string.IsNullOrEmpty(BindMerchantIdMerchantNo))
  94. {
  95. condition += " and BindMerchantId in (select MerchantId from MerchantForCode where Code='" + BindMerchantIdMerchantNo + "')";
  96. }
  97. //绑定商户商户姓名
  98. if (!string.IsNullOrEmpty(BindMerchantIdMerchantName))
  99. {
  100. condition += " and BindMerchantId in (select MerchantId from MerchantForName where Name='" + BindMerchantIdMerchantName + "')";
  101. }
  102. //品牌类型
  103. if (!string.IsNullOrEmpty(BrandTypeSelect))
  104. {
  105. condition += " and BrandType=" + BrandTypeSelect;
  106. }
  107. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserStoreChange", Fields, "Id desc", "0", page, limit, condition);
  108. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  109. foreach (Dictionary<string, object> dic in diclist)
  110. {
  111. //创客
  112. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  113. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  114. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  115. dic["UserIdRealName"] = userid_Users.RealName;
  116. dic.Remove("UserId");
  117. //产品类型
  118. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  119. //交易类型
  120. int TransType = int.Parse(dic["TransType"].ToString());
  121. if (TransType == 10) dic["TransType"] = "领取";
  122. if (TransType == 11) dic["TransType"] = "划拨";
  123. if (TransType == 13) dic["TransType"] = "退货";
  124. if (TransType == 0) dic["TransType"] = "";
  125. //SN机具类型
  126. int SnType = int.Parse(dic["SnType"].ToString());
  127. if (SnType == 0) dic["SnType"] = "购买机具";
  128. if (SnType == 1) dic["SnType"] = "赠送机具";
  129. //库存操作方向
  130. int StockOpDirect = int.Parse(dic["StockOpDirect"].ToString());
  131. if (StockOpDirect == 0) dic["StockOpDirect"] = "入库";
  132. if (StockOpDirect == 1) dic["StockOpDirect"] = "出库";
  133. //收货创客
  134. int ToUserId = int.Parse(function.CheckInt(dic["ToUserId"].ToString()));
  135. Users touserid_Users = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  136. dic["ToUserIdMakerCode"] = touserid_Users.MakerCode;
  137. dic["ToUserIdRealName"] = touserid_Users.RealName;
  138. dic.Remove("ToUserId");
  139. //创客退货收货仓库
  140. int ToStoreId = int.Parse(function.CheckInt(dic["ToStoreId"].ToString()));
  141. StoreHouse tostoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == ToStoreId) ?? new StoreHouse();
  142. dic["ToStoreIdStoreNo"] = tostoreid_StoreHouse.StoreNo;
  143. dic["ToStoreIdStoreName"] = tostoreid_StoreHouse.StoreName;
  144. dic.Remove("ToStoreId");
  145. //源仓库
  146. int SourceStoreId = int.Parse(function.CheckInt(dic["SourceStoreId"].ToString()));
  147. StoreHouse sourcestoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == SourceStoreId) ?? new StoreHouse();
  148. dic["SourceStoreIdStoreNo"] = sourcestoreid_StoreHouse.StoreNo;
  149. dic["SourceStoreIdStoreName"] = sourcestoreid_StoreHouse.StoreName;
  150. dic.Remove("SourceStoreId");
  151. //SN状态
  152. int SnStatus = int.Parse(dic["SnStatus"].ToString());
  153. if (SnStatus == 0) dic["SnStatus"] = "未拨出";
  154. if (SnStatus == 1) dic["SnStatus"] = "已拨出";
  155. //绑定状态
  156. int BindStatus = int.Parse(dic["BindStatus"].ToString());
  157. if (BindStatus == 0) dic["BindStatus"] = "未绑定";
  158. if (BindStatus == 1) dic["BindStatus"] = "已绑定";
  159. //绑定商户
  160. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  161. MerchantInfo bindmerchantid_MerchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new MerchantInfo();
  162. dic["BindMerchantIdMerchantNo"] = "";
  163. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.Name;
  164. dic.Remove("BindMerchantId");
  165. //激活状态
  166. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  167. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  168. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  169. //激活奖励创客
  170. int ActRewardUserId = int.Parse(function.CheckInt(dic["ActRewardUserId"].ToString()));
  171. Users actrewarduserid_Users = db.Users.FirstOrDefault(m => m.Id == ActRewardUserId) ?? new Users();
  172. dic["ActRewardUserIdMakerCode"] = actrewarduserid_Users.MakerCode;
  173. dic["ActRewardUserIdRealName"] = actrewarduserid_Users.RealName;
  174. dic.Remove("ActRewardUserId");
  175. //出货创客
  176. int FromUserId = int.Parse(function.CheckInt(dic["FromUserId"].ToString()));
  177. Users fromuserid_Users = db.Users.FirstOrDefault(m => m.Id == FromUserId) ?? new Users();
  178. dic["FromUserIdMakerCode"] = fromuserid_Users.MakerCode;
  179. dic["FromUserIdRealName"] = fromuserid_Users.RealName;
  180. dic.Remove("FromUserId");
  181. }
  182. Dictionary<string, object> other = new Dictionary<string, object>();
  183. string NotPutNotBindCount = "0.00";//支付成功总金额
  184. string NotPutBindCount = "0.00";//支付失败总金额
  185. string PutNotBindCount = "0.00";//支付成功总金额
  186. string PutBindCount = "0.00";//支付失败总金额
  187. string NotPutNotBindCount2 = "0.00";//支付成功总金额
  188. string NotPutBindCount2 = "0.00";//支付失败总金额
  189. string PutNotBindCount2 = "0.00";//支付成功总金额
  190. string PutBindCount2 = "0.00";//支付失败总金额
  191. string NotPutNotBindCount3 = "0.00";//支付成功总金额
  192. string NotPutBindCount3 = "0.00";//支付失败总金额
  193. string PutNotBindCount3 = "0.00";//支付成功总金额
  194. string PutBindCount3 = "0.00";//支付失败总金额
  195. string NotPutNotBindCount4 = "0.00";//支付成功总金额
  196. string NotPutBindCount4 = "0.00";//支付失败总金额
  197. string PutNotBindCount4 = "0.00";//支付成功总金额
  198. string PutBindCount4 = "0.00";//支付失败总金额
  199. // DataTable dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=0" + condition);
  200. // if (dt.Rows.Count > 0)
  201. // {
  202. // NotPutNotBindCount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  203. // }
  204. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  205. // if (dt.Rows.Count > 0)
  206. // {
  207. // NotPutBindCount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  208. // }
  209. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  210. // if (dt.Rows.Count > 0)
  211. // {
  212. // PutNotBindCount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  213. // }
  214. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  215. // if (dt.Rows.Count > 0)
  216. // {
  217. // PutBindCount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  218. // }
  219. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  220. // if (dt.Rows.Count > 0)
  221. // {
  222. // NotPutNotBindCount2 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  223. // }
  224. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  225. // if (dt.Rows.Count > 0)
  226. // {
  227. // NotPutBindCount2 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  228. // }
  229. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  230. // if (dt.Rows.Count > 0)
  231. // {
  232. // PutNotBindCount2 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  233. // }
  234. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  235. // if (dt.Rows.Count > 0)
  236. // {
  237. // PutBindCount2 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  238. // }
  239. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  240. // if (dt.Rows.Count > 0)
  241. // {
  242. // NotPutNotBindCount3 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  243. // }
  244. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  245. // if (dt.Rows.Count > 0)
  246. // {
  247. // NotPutBindCount3 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  248. // }
  249. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  250. // if (dt.Rows.Count > 0)
  251. // {
  252. // PutNotBindCount3 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  253. // }
  254. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  255. // if (dt.Rows.Count > 0)
  256. // {
  257. // PutBindCount3 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  258. // }
  259. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  260. // if (dt.Rows.Count > 0)
  261. // {
  262. // NotPutNotBindCount4 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  263. // }
  264. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  265. // if (dt.Rows.Count > 0)
  266. // {
  267. // NotPutBindCount4 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  268. // }
  269. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  270. // if (dt.Rows.Count > 0)
  271. // {
  272. // PutNotBindCount4 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  273. // }
  274. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  275. // if (dt.Rows.Count > 0)
  276. // {
  277. // PutBindCount4 = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  278. // }
  279. other.Add("NotPutNotBindCount", NotPutNotBindCount);
  280. other.Add("NotPutBindCount", NotPutBindCount);
  281. other.Add("PutNotBindCount", PutNotBindCount);
  282. other.Add("PutBindCount",PutBindCount);
  283. other.Add("NotPutNotBindCount2", NotPutNotBindCount2);
  284. other.Add("NotPutBindCount2", NotPutBindCount2);
  285. other.Add("PutNotBindCount2", PutNotBindCount2);
  286. other.Add("PutBindCount2", PutBindCount2);
  287. other.Add("NotPutNotBindCount3", NotPutNotBindCount3);
  288. other.Add("NotPutBindCount3", NotPutBindCount3);
  289. other.Add("PutNotBindCount3", PutNotBindCount3);
  290. other.Add("PutBindCount3", PutBindCount3);
  291. other.Add("NotPutNotBindCount4", NotPutNotBindCount4);
  292. other.Add("NotPutBindCount4", NotPutBindCount4);
  293. other.Add("PutNotBindCount4", PutNotBindCount4);
  294. other.Add("PutBindCount4", PutBindCount4);
  295. obj.Add("other", other);
  296. return Json(obj);
  297. }
  298. #endregion
  299. #region 增加创客库存变动记录
  300. /// <summary>
  301. /// 增加或修改创客库存变动记录信息
  302. /// </summary>
  303. /// <returns></returns>
  304. public IActionResult Add(string right)
  305. {
  306. ViewBag.RightInfo = RightInfo;
  307. ViewBag.right = right;
  308. return View();
  309. }
  310. #endregion
  311. #region 增加创客库存变动记录
  312. /// <summary>
  313. /// 增加或修改创客库存变动记录信息
  314. /// </summary>
  315. /// <returns></returns>
  316. [HttpPost]
  317. public string Add(UserStoreChange data)
  318. {
  319. Dictionary<string, object> Fields = new Dictionary<string, object>();
  320. Fields.Add("SeoTitle", data.SeoTitle);
  321. Fields.Add("SeoKeyword", data.SeoKeyword);
  322. Fields.Add("SeoDescription", data.SeoDescription);
  323. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("UserStoreChange", Fields, 0);
  324. AddSysLog(data.Id.ToString(), "UserStoreChange", "add");
  325. db.SaveChanges();
  326. return "success";
  327. }
  328. #endregion
  329. #region 修改创客库存变动记录
  330. /// <summary>
  331. /// 增加或修改创客库存变动记录信息
  332. /// </summary>
  333. /// <returns></returns>
  334. public IActionResult Edit(string right, int Id = 0)
  335. {
  336. ViewBag.RightInfo = RightInfo;
  337. ViewBag.right = right;
  338. UserStoreChange editData = db.UserStoreChange.FirstOrDefault(m => m.Id == Id) ?? new UserStoreChange();
  339. ViewBag.data = editData;
  340. return View();
  341. }
  342. #endregion
  343. #region 修改创客库存变动记录
  344. /// <summary>
  345. /// 增加或修改创客库存变动记录信息
  346. /// </summary>
  347. /// <returns></returns>
  348. [HttpPost]
  349. public string Edit(UserStoreChange data)
  350. {
  351. Dictionary<string, object> Fields = new Dictionary<string, object>();
  352. Fields.Add("SeoTitle", data.SeoTitle);
  353. Fields.Add("SeoKeyword", data.SeoKeyword);
  354. Fields.Add("SeoDescription", data.SeoDescription);
  355. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserStoreChange", Fields, data.Id);
  356. AddSysLog(data.Id.ToString(), "UserStoreChange", "update");
  357. db.SaveChanges();
  358. return "success";
  359. }
  360. #endregion
  361. #region 删除创客库存变动记录信息
  362. /// <summary>
  363. /// 删除创客库存变动记录信息
  364. /// </summary>
  365. /// <returns></returns>
  366. public string Delete(string Id)
  367. {
  368. string[] idlist = Id.Split(new char[] { ',' });
  369. AddSysLog(Id, "UserStoreChange", "del");
  370. foreach (string subid in idlist)
  371. {
  372. int id = int.Parse(subid);
  373. Dictionary<string, object> Fields = new Dictionary<string, object>();
  374. Fields.Add("Status", -1);
  375. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserStoreChange", Fields, id);
  376. }
  377. db.SaveChanges();
  378. return "success";
  379. }
  380. #endregion
  381. #region 开启
  382. /// <summary>
  383. /// 开启
  384. /// </summary>
  385. /// <returns></returns>
  386. public string Open(string Id)
  387. {
  388. string[] idlist = Id.Split(new char[] { ',' });
  389. AddSysLog(Id, "UserStoreChange", "open");
  390. foreach (string subid in idlist)
  391. {
  392. int id = int.Parse(subid);
  393. Dictionary<string, object> Fields = new Dictionary<string, object>();
  394. Fields.Add("Status", 1);
  395. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserStoreChange", Fields, id);
  396. }
  397. db.SaveChanges();
  398. return "success";
  399. }
  400. #endregion
  401. #region 关闭
  402. /// <summary>
  403. /// 关闭
  404. /// </summary>
  405. /// <returns></returns>
  406. public string Close(string Id)
  407. {
  408. string[] idlist = Id.Split(new char[] { ',' });
  409. AddSysLog(Id, "UserStoreChange", "close");
  410. foreach (string subid in idlist)
  411. {
  412. int id = int.Parse(subid);
  413. Dictionary<string, object> Fields = new Dictionary<string, object>();
  414. Fields.Add("Status", 0);
  415. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("UserStoreChange", Fields, id);
  416. }
  417. db.SaveChanges();
  418. return "success";
  419. }
  420. #endregion
  421. #region 排序
  422. /// <summary>
  423. /// 排序
  424. /// </summary>
  425. /// <param name="Id"></param>
  426. public string Sort(int Id, int Sort)
  427. {
  428. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("UserStoreChange", Sort, Id);
  429. AddSysLog(Id.ToString(), "UserStoreChange", "sort");
  430. return "success";
  431. }
  432. #endregion
  433. #region 导入数据
  434. /// <summary>
  435. /// 导入数据
  436. /// </summary>
  437. /// <param name="ExcelData"></param>
  438. public string Import(string ExcelData)
  439. {
  440. ExcelData = HttpUtility.UrlDecode(ExcelData);
  441. JsonData list = JsonMapper.ToObject(ExcelData);
  442. for (int i = 1; i < list.Count; i++)
  443. {
  444. JsonData dr = list[i];
  445. db.UserStoreChange.Add(new UserStoreChange()
  446. {
  447. CreateDate = DateTime.Now,
  448. UpdateDate = DateTime.Now,
  449. });
  450. db.SaveChanges();
  451. }
  452. AddSysLog("0", "UserStoreChange", "Import");
  453. return "success";
  454. }
  455. #endregion
  456. #region 导出Excel
  457. /// <summary>
  458. /// 导出Excel
  459. /// </summary>
  460. /// <returns></returns>
  461. public JsonResult ExportExcel(UserStoreChange data, string UserIdMakerCode, string UserIdRealName, string BindMerchantIdMerchantNo, string BindMerchantIdMerchantName, string BrandIdSelect, string TransTypeSelect, string StockOpDirectSelect, string SnStatusSelect, string BindStatusSelect, string ActiveStatusSelect, string BrandTypeSelect)
  462. {
  463. Dictionary<string, string> Fields = new Dictionary<string, string>();
  464. Fields.Add("CreateDate", "3"); //时间
  465. Fields.Add("SnNo", "1"); //SN编号
  466. string condition = " and Status>-1";
  467. //创客编号
  468. if (!string.IsNullOrEmpty(UserIdMakerCode))
  469. {
  470. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  471. }
  472. //创客真实姓名
  473. if (!string.IsNullOrEmpty(UserIdRealName))
  474. {
  475. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  476. }
  477. //产品类型
  478. if (!string.IsNullOrEmpty(BrandIdSelect))
  479. {
  480. condition += " and BrandId=" + BrandIdSelect;
  481. }
  482. //交易类型
  483. if (!string.IsNullOrEmpty(TransTypeSelect))
  484. {
  485. condition += " and TransType=" + TransTypeSelect;
  486. }
  487. //库存操作方向
  488. if (!string.IsNullOrEmpty(StockOpDirectSelect))
  489. {
  490. condition += " and StockOpDirect=" + StockOpDirectSelect;
  491. }
  492. //SN状态
  493. if (!string.IsNullOrEmpty(SnStatusSelect))
  494. {
  495. condition += " and SnStatus=" + SnStatusSelect;
  496. }
  497. //绑定状态
  498. if (!string.IsNullOrEmpty(BindStatusSelect))
  499. {
  500. condition += " and BindStatus=" + BindStatusSelect;
  501. }
  502. //激活状态
  503. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  504. {
  505. condition += " and ActiveStatus=" + ActiveStatusSelect;
  506. }
  507. //绑定商户商户编号
  508. if (!string.IsNullOrEmpty(BindMerchantIdMerchantNo))
  509. {
  510. condition += " and BindMerchantId in (select MerchantId from MerchantForCode where Code='" + BindMerchantIdMerchantNo + "')";
  511. }
  512. //绑定商户商户姓名
  513. if (!string.IsNullOrEmpty(BindMerchantIdMerchantName))
  514. {
  515. condition += " and BindMerchantId in (select MerchantId from MerchantForName where Name='" + BindMerchantIdMerchantName + "')";
  516. }
  517. //品牌类型
  518. if (!string.IsNullOrEmpty(BrandTypeSelect))
  519. {
  520. condition += " and BrandType=" + BrandTypeSelect;
  521. }
  522. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("UserStoreChange", Fields, "Id desc", "0", 1, 20000, condition, "UserId,BrandId,TransType,SnNo,SnType,StockOpDirect,ToUserId,ToStoreId,SourceStoreId,SnStatus,BindStatus,BindMerchantId,ActiveStatus,ActRewardUserId,FromUserId,CreateDate", false);
  523. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  524. foreach (Dictionary<string, object> dic in diclist)
  525. {
  526. //创客
  527. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  528. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  529. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  530. dic["UserIdRealName"] = userid_Users.RealName;
  531. dic.Remove("UserId");
  532. //产品类型
  533. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  534. //交易类型
  535. int TransType = int.Parse(dic["TransType"].ToString());
  536. if (TransType == 10) dic["TransType"] = "领取";
  537. if (TransType == 11) dic["TransType"] = "划拨";
  538. if (TransType == 13) dic["TransType"] = "退货";
  539. if (TransType == 0) dic["TransType"] = "";
  540. //SN机具类型
  541. int SnType = int.Parse(dic["SnType"].ToString());
  542. if (SnType == 0) dic["SnType"] = "购买机具";
  543. if (SnType == 1) dic["SnType"] = "赠送机具";
  544. //库存操作方向
  545. int StockOpDirect = int.Parse(dic["StockOpDirect"].ToString());
  546. if (StockOpDirect == 0) dic["StockOpDirect"] = "入库";
  547. if (StockOpDirect == 1) dic["StockOpDirect"] = "出库";
  548. //收货创客
  549. int ToUserId = int.Parse(function.CheckInt(dic["ToUserId"].ToString()));
  550. Users touserid_Users = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  551. dic["ToUserIdMakerCode"] = touserid_Users.MakerCode;
  552. dic["ToUserIdRealName"] = touserid_Users.RealName;
  553. dic.Remove("ToUserId");
  554. //创客退货收货仓库
  555. int ToStoreId = int.Parse(function.CheckInt(dic["ToStoreId"].ToString()));
  556. StoreHouse tostoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == ToStoreId) ?? new StoreHouse();
  557. dic["ToStoreIdStoreNo"] = tostoreid_StoreHouse.StoreNo;
  558. dic["ToStoreIdStoreName"] = tostoreid_StoreHouse.StoreName;
  559. dic.Remove("ToStoreId");
  560. //源仓库
  561. int SourceStoreId = int.Parse(function.CheckInt(dic["SourceStoreId"].ToString()));
  562. StoreHouse sourcestoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == SourceStoreId) ?? new StoreHouse();
  563. dic["SourceStoreIdStoreNo"] = sourcestoreid_StoreHouse.StoreNo;
  564. dic["SourceStoreIdStoreName"] = sourcestoreid_StoreHouse.StoreName;
  565. dic.Remove("SourceStoreId");
  566. //SN状态
  567. int SnStatus = int.Parse(dic["SnStatus"].ToString());
  568. if (SnStatus == 0) dic["SnStatus"] = "未拨出";
  569. if (SnStatus == 1) dic["SnStatus"] = "已拨出";
  570. //绑定状态
  571. int BindStatus = int.Parse(dic["BindStatus"].ToString());
  572. if (BindStatus == 0) dic["BindStatus"] = "未绑定";
  573. if (BindStatus == 1) dic["BindStatus"] = "已绑定";
  574. //绑定商户
  575. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  576. MerchantInfo bindmerchantid_MerchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new MerchantInfo();
  577. dic["BindMerchantIdMerchantNo"] = "";
  578. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.Name;
  579. dic.Remove("BindMerchantId");
  580. //激活状态
  581. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  582. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  583. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  584. //激活奖励创客
  585. int ActRewardUserId = int.Parse(function.CheckInt(dic["ActRewardUserId"].ToString()));
  586. Users actrewarduserid_Users = db.Users.FirstOrDefault(m => m.Id == ActRewardUserId) ?? new Users();
  587. dic["ActRewardUserIdMakerCode"] = actrewarduserid_Users.MakerCode;
  588. dic["ActRewardUserIdRealName"] = actrewarduserid_Users.RealName;
  589. dic.Remove("ActRewardUserId");
  590. //出货创客
  591. int FromUserId = int.Parse(function.CheckInt(dic["FromUserId"].ToString()));
  592. Users fromuserid_Users = db.Users.FirstOrDefault(m => m.Id == FromUserId) ?? new Users();
  593. dic["FromUserIdMakerCode"] = fromuserid_Users.MakerCode;
  594. dic["FromUserIdRealName"] = fromuserid_Users.RealName;
  595. dic.Remove("FromUserId");
  596. }
  597. Dictionary<string, object> result = new Dictionary<string, object>();
  598. result.Add("Status", "1");
  599. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  600. result.Add("Obj", diclist);
  601. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  602. ReturnFields.Add("UserIdMakerCode", "创客编号");
  603. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  604. ReturnFields.Add("BrandId", "产品类型");
  605. ReturnFields.Add("TransType", "交易类型");
  606. ReturnFields.Add("SnNo", "SN编号");
  607. ReturnFields.Add("SnType", "SN机具类型");
  608. ReturnFields.Add("StockOpDirect", "库存操作方向");
  609. ReturnFields.Add("ToUserIdMakerCode", "收货创客编号");
  610. ReturnFields.Add("ToUserIdRealName", "收货创客真实姓名");
  611. ReturnFields.Add("ToStoreIdStoreNo", "创客退货收货仓库编号");
  612. ReturnFields.Add("ToStoreIdStoreName", "创客退货收货仓库名称");
  613. ReturnFields.Add("SourceStoreIdStoreNo", "源仓库编号");
  614. ReturnFields.Add("SourceStoreIdStoreName", "源仓库名称");
  615. ReturnFields.Add("SnStatus", "SN状态");
  616. ReturnFields.Add("BindStatus", "绑定状态");
  617. ReturnFields.Add("BindMerchantIdMerchantNo", "绑定商户编号");
  618. ReturnFields.Add("BindMerchantIdMerchantName", "绑定商户姓名");
  619. ReturnFields.Add("ActiveStatus", "激活状态");
  620. ReturnFields.Add("ActRewardUserIdMakerCode", "激活奖励创客编号");
  621. ReturnFields.Add("ActRewardUserIdRealName", "激活奖励创客真实姓名");
  622. ReturnFields.Add("FromUserIdMakerCode", "出货创客编号");
  623. ReturnFields.Add("FromUserIdRealName", "出货创客真实姓名");
  624. ReturnFields.Add("CreateDate", "变动时间");
  625. result.Add("Fields", ReturnFields);
  626. AddSysLog("0", "UserStoreChange", "ExportExcel");
  627. return Json(result);
  628. }
  629. #endregion
  630. }
  631. }