PreSendStockDetailUtil.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using Library;
  2. using MySystem.Models.Main;
  3. using MySystem.Service.Main;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace MySystem
  8. {
  9. /// <summary>
  10. /// 预发货库存明细工具类
  11. /// </summary>
  12. public class PreSendStockDetailUtil
  13. {
  14. public static List<PreSendStockDetail> LPD = new List<PreSendStockDetail>();
  15. public static List<PosMachinesTwo> LPos = new List<PosMachinesTwo>();
  16. #region 创客-首页-仓库管理-小分仓-确认发货
  17. /// <summary>
  18. /// 创客-首页-仓库管理-小分仓-确认发货
  19. /// </summary>
  20. /// <param name="UserId">发货人Id</param>
  21. /// <param name="ToUserId">收货人Id</param>
  22. /// <param name="FromStoreId">出货仓库Id</param>
  23. /// <param name="BrandId">产品类型Id</param>
  24. /// <param name="SnIds">机具Id</param>
  25. /// <returns></returns>
  26. public static string SendDo(int UserId, int ToUserId, int FromStoreId, int BrandId, string SnIds)
  27. {
  28. //分割SN
  29. string[] strids = SnIds.Split(',');
  30. var count = strids.ToList().Count();
  31. var smallStoreHouse = SmallStoreHouseService.Query("UserId='" + ToUserId + "'");
  32. //判断是否符合预发货规范(总库存数<=10)
  33. if (smallStoreHouse.LaveNum > 0 && smallStoreHouse.TotalNum < 10)
  34. {
  35. if (smallStoreHouse.LaveNum - count < 0 || smallStoreHouse.TotalNum + count > 10)
  36. {
  37. return "*发货失败,发货后该创客预发机超过10台";
  38. }
  39. //循环添加到数据库
  40. foreach (var item in strids)
  41. {
  42. var preSendStockDetail = PreSendStockDetailService.Query("FromUserId='" + UserId + "' and Status>=0 and Status<=1 and SnId='" + item + "'");
  43. if (preSendStockDetail.Id > 0)
  44. {
  45. return "*发货失败,请勿重复提交";
  46. }
  47. var posMachinesTwo = PosMachinesTwoService.Query(int.Parse(item));
  48. posMachinesTwo.PreUserId = ToUserId;
  49. //赋值机具预发机所属人信息
  50. PosMachinesTwoUtil.SetPosMachinesTwoValue(posMachinesTwo.Id, ToUserId);
  51. //赋值预发货库存明细(创客-首页-仓库管理-小分仓-确认发货)
  52. SetPreSendStockDetailValue(UserId, ToUserId, posMachinesTwo.SourceStoreId, BrandId, posMachinesTwo.PosSn, FromStoreId, smallStoreHouse.Id, smallStoreHouse.Id, Convert.ToInt32(item));
  53. }
  54. //修改机具预发机所属人标记
  55. PosMachinesTwoUtil.EditPosPreUserIdValue(LPos);
  56. //修改小仓库库存(创客-首页-仓库管理-小分仓-确认发货)
  57. SmallStoreHouseUtil.EditStoreStock(smallStoreHouse.Id, smallStoreHouse.LaveNum -= count, smallStoreHouse.TotalNum += count);
  58. string text = string.Format("创客-首页-仓库管理-小分仓-确认发货,UserId: '" + UserId + "',ToUserId: '" + ToUserId + "',LaveNum:'" + smallStoreHouse.LaveNum + "',TotalNum:'" + smallStoreHouse.TotalNum + "',ChangeCount:'" + count + "',Time'" + DateTime.Now + "'");
  59. function.WriteLog(text, "smallstorehouse");//小分仓记录日志
  60. var storeHouse = StoreHouseService.Query(FromStoreId);
  61. //修改仓库剩余库存数
  62. StoreHouseUtil.EditStoreLaveNum(storeHouse.Id, storeHouse.LaveNum -= count);
  63. //添加预发货库存明细
  64. AddPreSendStockDetail(LPD);
  65. }
  66. else
  67. {
  68. return "*发货失败,该创客已有10台预发机";
  69. }
  70. return "success";
  71. }
  72. #endregion
  73. #region 创客-首页-仓库管理-小分仓-撤回
  74. /// <summary>
  75. /// 创客-首页-仓库管理-小分仓-撤回
  76. /// </summary>
  77. /// <param name="UserId">发货人Id</param>
  78. /// <param name="Id">记录Id</param>
  79. public static string CancelDo(int UserId, int Id)
  80. {
  81. RedisDbconn.Instance.Set("SmallStoreCancel:" + UserId, "wait");
  82. RedisDbconn.Instance.SetExpire("SmallStoreCancel:" + UserId, 300);
  83. var query = PreSendStockDetailService.Query("FromUserId='" + UserId + "' and Id='" + Id + "'");
  84. var userAccount = UserAccountService.Query(UserId);
  85. var tuserAccount = UserAccountService.Query(query.ToUserId);
  86. var brandInfo = KqProductsService.Query(query.BrandId);
  87. var date = DateTime.Now.AddDays(-30);
  88. var amount = 0;
  89. if (query.Id > 0)
  90. {
  91. var posMachinesTwo = PosMachinesTwoService.Query(query.SnId);
  92. var storeHouse = StoreHouseService.Query(query.FromStoreId);
  93. var pm = PosMachinesTwoService.Query(query.SnId);
  94. if (brandInfo.Kind == 1)
  95. {
  96. amount = 200;
  97. }
  98. if (brandInfo.Kind == 2)
  99. {
  100. amount = 300;
  101. }
  102. if (pm != null)
  103. {
  104. if (pm.BindingState == 1)
  105. {
  106. return "机具已绑定,不可撤回!请创客申请机具后补录!";
  107. }
  108. var smallStoreHouse = SmallStoreHouseService.Query("UserId='" + query.ToUserId + "'");
  109. //赋值机具预发机所属人信息
  110. PosMachinesTwoUtil.SetPosMachinesTwoValue(posMachinesTwo.Id, 0);
  111. //修改机具预发机所属人标记
  112. PosMachinesTwoUtil.EditPosPreUserIdValue(LPos);
  113. //修改预发货库存明细(创客-首页-仓库管理-小分仓-撤回)
  114. EditPreSendStockDetail(query.Id, -1, 1);
  115. //修改仓库剩余库存数
  116. StoreHouseUtil.EditStoreLaveNum(storeHouse.Id, storeHouse.LaveNum += 1);
  117. //修改小仓库库存
  118. SmallStoreHouseUtil.EditStoreStock(smallStoreHouse.Id, smallStoreHouse.LaveNum += 1, smallStoreHouse.TotalNum -= 1);
  119. if (query.CreateDate <= date)
  120. {
  121. //撤回占用小分仓额度的增加接收创客的小分仓可用额度
  122. if (query.AuthFlag == 1 && tuserAccount.SmallStoreDeposit >= amount)
  123. {
  124. //扣减分仓可用额度
  125. Dictionary<string, object> userAccountData = new Dictionary<string, object>();
  126. userAccountData.Add("ValidAmount", userAccount.ValidAmount -= amount);
  127. UserAccountService.Edit(userAccountData, userAccount.Id);
  128. //增加小分仓可用额度
  129. Dictionary<string, object> tuserAccountData = new Dictionary<string, object>();
  130. tuserAccountData.Add("SmallStoreDeposit", tuserAccount.SmallStoreDeposit -= amount);
  131. tuserAccountData.Add("ValidPreAmount", tuserAccount.ValidPreAmount += amount);
  132. UserAccountService.Edit(tuserAccountData, userAccount.Id);
  133. //预发机撤回退还小分仓押金
  134. UserAccountRecordUtil.AddRecordForCanclePos("小分仓押金退还", 66, tuserAccount.SmallStoreDeposit + amount, tuserAccount.SmallStoreDeposit, amount, tuserAccount.Id);
  135. }
  136. }
  137. else
  138. {
  139. //撤回占用小分仓额度的增加接收创客的小分仓可用额度
  140. if (query.AuthFlag == 1)
  141. {
  142. //扣减分仓可用额度
  143. Dictionary<string, object> userAccountData = new Dictionary<string, object>();
  144. userAccountData.Add("ValidAmount", userAccount.ValidAmount -= amount);
  145. UserAccountService.Edit(userAccountData, userAccount.Id);
  146. //增加小分仓可用额度
  147. Dictionary<string, object> tuserAccountData = new Dictionary<string, object>();
  148. tuserAccountData.Add("ValidPreAmount", tuserAccount.ValidPreAmount += amount);
  149. UserAccountService.Edit(tuserAccountData, userAccount.Id);
  150. }
  151. }
  152. string text = string.Format("创客-首页-仓库管理-小分仓-撤回,UserId: '" + UserId + "',ToUserId: '" + smallStoreHouse.UserId + "',LaveNum:'" + smallStoreHouse.LaveNum + "',TotalNum:'" + smallStoreHouse.TotalNum + "',ChangeCount:'" + 1 + "',Time'" + DateTime.Now + "'");
  153. function.WriteLog(text, "smallstorehouse");//小分仓记录日志
  154. if (smallStoreHouse.LaveNum > 10 || smallStoreHouse.TotalNum < 0)
  155. {
  156. return "*库存已重置,不可撤回!";
  157. }
  158. BaseClass.SendPersonalMsg(query.ToUserId, 0, "预发机撤回通知", "<div class='f16'>您的预发机 SN:<br/>" + query.SnNo + "<br/>已被" + storeHouse.StoreName + " 撤回!</div>", "您的预发机: " + brandInfo.Name + " sn:" + query.SnNo + "已被 " + storeHouse.StoreName + " 撤回!");
  159. var toUser = UsersService.Query(query.ToUserId);
  160. BaseClass.SendPersonalMsg(query.FromUserId, 0, "预发机撤回通知", "<div class='f16'>已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:<br/>" + query.SnNo + "</div>", "已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:" + query.SnNo + "");
  161. }
  162. }
  163. RedisDbconn.Instance.SetExpire("SmallStoreCancel:" + UserId, 1);
  164. return "success";
  165. }
  166. #endregion
  167. #region 赋值预发货库存明细(创客-首页-仓库管理-小分仓-确认发货)
  168. /// <summary>
  169. /// 赋值预发货库存明细(创客-首页-仓库管理-小分仓-确认发货)
  170. /// </summary>
  171. public static void SetPreSendStockDetailValue(int FromUserId, int ToUserId, int SourceStoreId, int BrandId, string SnNo, int FromStoreId, int ToStoreId, int StoreId, int SnId)
  172. {
  173. PreSendStockDetail pd = new PreSendStockDetail();
  174. pd.CreateDate = DateTime.Now; //创建时间
  175. pd.FromUserId = FromUserId;//发货人Id
  176. pd.ToUserId = ToUserId; //收货人Id
  177. pd.SourceStoreId = SourceStoreId; //源仓库Id
  178. pd.BrandId = BrandId; //产品类型Id
  179. pd.SnNo = SnNo; //机具SN
  180. pd.FromStoreId = FromStoreId; //出货仓库Id
  181. pd.ToStoreId = ToStoreId; //收货仓库Id
  182. pd.StoreId = ToStoreId; //仓库Id
  183. pd.SnId = SnId;
  184. LPD.Add(pd);
  185. }
  186. #endregion
  187. #region 添加预发货库存明细(创客-首页-仓库管理-小分仓-确认发货)
  188. /// <summary>
  189. /// 添加预发货库存明细(创客-首页-仓库管理-小分仓-确认发货)
  190. /// </summary>
  191. public static void AddPreSendStockDetail(List<PreSendStockDetail> pds)
  192. {
  193. foreach (var item in pds)
  194. {
  195. Dictionary<string, object> query = new Dictionary<string, object>();
  196. query.Add("FromUserId", item.FromUserId);//发货人Id
  197. query.Add("ToUserId", item.ToUserId); //收货人Id
  198. query.Add("SourceStoreId", item.SourceStoreId); //源仓库Id
  199. query.Add("BrandId", item.BrandId); //产品类型Id
  200. query.Add("SnNo", item.SnNo); //机具SN
  201. query.Add("FromStoreId", item.FromStoreId); //出货仓库Id
  202. query.Add("ToStoreId", item.ToStoreId); //收货仓库Id
  203. query.Add("StoreId", item.StoreId); //仓库Id
  204. query.Add("SnId", item.SnId);
  205. PreSendStockDetailService.Add(query);
  206. }
  207. }
  208. #endregion
  209. #region 修改预发货库存明细(创客-首页-仓库管理-小分仓-撤回)
  210. /// <summary>
  211. /// 修改预发货库存明细(创客-首页-仓库管理-小分仓-撤回)
  212. /// </summary>
  213. /// <param name="Id">记录Id</param>
  214. /// <param name="Status">状态</param>
  215. /// <param name="CancelFlag">撤回标记</param>
  216. public static void EditPreSendStockDetail(int Id, int Status, int CancelFlag)
  217. {
  218. Dictionary<string, object> query = new Dictionary<string, object>();
  219. query.Add("Status", Status);
  220. query.Add("CancelFlag", CancelFlag);
  221. PreSendStockDetailService.Edit(query, Id);
  222. }
  223. #endregion
  224. }
  225. }