UserStoreChangeController.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. namespace MySystem.Areas.Api.Controllers.v1.pos
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/pos/[controller]/[action]")]
  17. public class UserStoreChangeController : BaseController
  18. {
  19. public UserStoreChangeController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 首页-客小爽产品-机具管理-未绑定-划拨
  23. [Authorize]
  24. public JsonResult Transfer(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. AppResultJson result = TransferDo(value);
  29. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  30. }
  31. public AppResultJson TransferDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  35. int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
  36. string SnIds = data["SnIds"].ToString(); //SN列表返回的Id
  37. int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //划拨对象创客Id
  38. Dictionary<string, object> Obj = new Dictionary<string, object>();
  39. bool checkUser = maindb.Users.Any(m => m.Id == ToUserId);
  40. if (!checkUser)
  41. {
  42. return new AppResultJson() { Status = "-1", Info = "请输入正确的创客编号", Data = Obj };
  43. }
  44. Users user = maindb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  45. Users touser = maindb.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  46. if (!function.CheckNull(touser.ParentNav).Contains("," + UserId + ",") || function.CheckNull(user.ParentNav).Contains("," + ToUserId + ","))
  47. {
  48. return new AppResultJson() { Status = "-1", Info = "划拨对象不在您的权限范围", Data = Obj };
  49. }
  50. if (!string.IsNullOrEmpty(SnIds))
  51. {
  52. string[] SnIdList = SnIds.Split(',');
  53. foreach (string SnId in SnIdList)
  54. {
  55. int SnIdNum = int.Parse(SnId);
  56. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.Id == SnIdNum) ?? new PosMachinesTwo();
  57. if (pos.PosSnType == 1)
  58. {
  59. return new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "是循环机,请勿划拨", Data = Obj };
  60. }
  61. StoreHouse store = StoreHouseDbconn.Instance.Get(pos.StoreId) ?? new StoreHouse();
  62. string ChangeRecordNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  63. UserStoreChange query = maindb.UserStoreChange.Add(new UserStoreChange()
  64. {
  65. CreateDate = DateTime.Now,
  66. UserId = UserId, //创客
  67. BrandId = BrandId, //产品类型
  68. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  69. TransType = 11, //交易类型
  70. SnNo = pos.PosSn, //SN编号
  71. SnType = pos.PosSnType, //SN机具类型
  72. StockOpDirect = 1, //库存操作方向
  73. ToUserId = ToUserId, //收货创客
  74. SnStatus = 0, //SN状态
  75. BindStatus = (int)pos.BindingState, //绑定状态
  76. BindMerchantId = pos.BindMerchantId, //绑定商户
  77. ActiveStatus = (int)pos.ActivationState, //激活状态
  78. FromUserId = UserId, //出货创客
  79. }).Entity;
  80. maindb.SaveChanges();
  81. StoreChangeHistory history = maindb.StoreChangeHistory.Add(new StoreChangeHistory()
  82. {
  83. CreateDate = DateTime.Now,
  84. UserId = UserId, //创客
  85. BrandId = BrandId, //产品类型
  86. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  87. TransType = 2, //交易类型
  88. SnNo = pos.PosSn, //SN编号
  89. SnType = pos.PosSnType, //SN机具类型
  90. StockOpDirect = 1, //库存操作方向
  91. DeviceVendor = pos.DeviceName, //设备厂商
  92. DeviceModel = pos.DeviceKind, //设备型号
  93. DeviceType = pos.DeviceType, //设备类型
  94. ToUserId = ToUserId, //收货创客
  95. FromUserId = store.UserId, //出货创客
  96. FromDate = DateTime.Now, //出库时间
  97. SourceStoreId = pos.SourceStoreId, //源仓库
  98. StoreId = store.Id, //仓库
  99. }).Entity;
  100. maindb.SaveChanges();
  101. StoreChangeItem item = new StoreChangeItem()
  102. {
  103. SnNo = pos.PosSn,
  104. SnType = pos.PosSnType,
  105. FromDate = DateTime.Now,
  106. Id = query.Id,
  107. UserId = ToUserId,
  108. };
  109. string IdBrand = UserId + "_" + BrandId;
  110. PublicFunction.StatUserMachineData(UserId, BrandId, -1);
  111. PublicFunction.StatUserMachineData(ToUserId, BrandId, 1);
  112. pos.BuyUserId = ToUserId;
  113. pos.UserId = ToUserId;
  114. pos.TransferTime = DateTime.Now;
  115. maindb.SaveChanges();
  116. }
  117. }
  118. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  119. }
  120. #endregion
  121. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  122. /// <summary>
  123. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  124. /// </summary>
  125. /// <param name="value">请求的参数(json字符串)</param>
  126. /// <param name="signField">要签名的字段</param>
  127. /// <returns></returns>
  128. private string CheckSign(string value, string[] signField)
  129. {
  130. JsonData json = JsonMapper.ToObject(value);
  131. Dictionary<string, string> dic = new Dictionary<string, string>();
  132. for (int i = 0; i < signField.Length; i++)
  133. {
  134. dic.Add(signField[i], json[signField[i]].ToString());
  135. }
  136. string sign = json["sign"].ToString(); //客户端签名字符串
  137. return new Sign().sign(dic, sign);
  138. }
  139. #endregion
  140. }
  141. }