123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- using Library;
- using MySystem.Models.Main;
- using MySystem.Service.Main;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace MySystem
- {
- /// <summary>
- /// 预发货库存明细工具类
- /// </summary>
- public class PreSendStockDetailUtil
- {
- public static List<PreSendStockDetail> LPD = new List<PreSendStockDetail>();
- public static List<PosMachinesTwo> LPos = new List<PosMachinesTwo>();
- #region 创客-首页-仓库管理-小分仓-确认发货
- /// <summary>
- /// 创客-首页-仓库管理-小分仓-确认发货
- /// </summary>
- /// <param name="UserId">发货人Id</param>
- /// <param name="ToUserId">收货人Id</param>
- /// <param name="FromStoreId">出货仓库Id</param>
- /// <param name="BrandId">产品类型Id</param>
- /// <param name="SnIds">机具Id</param>
- /// <returns></returns>
- public static string SendDo(int UserId, int ToUserId, int FromStoreId, int BrandId, string SnIds)
- {
- //分割SN
- string[] strids = SnIds.Split(',');
- var count = strids.ToList().Count();
- var smallStoreHouse = SmallStoreHouseService.Query("UserId='" + ToUserId + "'");
- //判断是否符合预发货规范(总库存数<=10)
- if (smallStoreHouse.LaveNum > 0 && smallStoreHouse.TotalNum < 10)
- {
- if (smallStoreHouse.LaveNum - count < 0 || smallStoreHouse.TotalNum + count > 10)
- {
- return "*发货失败,发货后该创客预发机超过10台";
- }
- //循环添加到数据库
- foreach (var item in strids)
- {
- var preSendStockDetail = PreSendStockDetailService.Query("FromUserId='" + UserId + "' and Status>=0 and Status<=1 and SnId='" + item + "'");
- if (preSendStockDetail.Id > 0)
- {
- return "*发货失败,请勿重复提交";
- }
- var posMachinesTwo = PosMachinesTwoService.Query(int.Parse(item));
- posMachinesTwo.PreUserId = ToUserId;
- //赋值机具预发机所属人信息
- PosMachinesTwoUtil.SetPosMachinesTwoValue(posMachinesTwo.Id, ToUserId);
- //赋值预发货库存明细(创客-首页-仓库管理-小分仓-确认发货)
- SetPreSendStockDetailValue(UserId, ToUserId, posMachinesTwo.SourceStoreId, BrandId, posMachinesTwo.PosSn, FromStoreId, smallStoreHouse.Id, smallStoreHouse.Id, Convert.ToInt32(item));
- }
- //修改机具预发机所属人标记
- PosMachinesTwoUtil.EditPosPreUserIdValue(LPos);
- //修改小仓库库存(创客-首页-仓库管理-小分仓-确认发货)
- SmallStoreHouseUtil.EditStoreStock(smallStoreHouse.Id, smallStoreHouse.LaveNum -= count, smallStoreHouse.TotalNum += count);
- string text = string.Format("创客-首页-仓库管理-小分仓-确认发货,UserId: '" + UserId + "',ToUserId: '" + ToUserId + "',LaveNum:'" + smallStoreHouse.LaveNum + "',TotalNum:'" + smallStoreHouse.TotalNum + "',ChangeCount:'" + count + "',Time'" + DateTime.Now + "'");
- function.WriteLog(text, "smallstorehouse");//小分仓记录日志
- var storeHouse = StoreHouseService.Query(FromStoreId);
- //修改仓库剩余库存数
- StoreHouseUtil.EditStoreLaveNum(storeHouse.Id, storeHouse.LaveNum -= count);
- //添加预发货库存明细
- AddPreSendStockDetail(LPD);
- }
- else
- {
- return "*发货失败,该创客已有10台预发机";
- }
- return "success";
- }
- #endregion
- #region 创客-首页-仓库管理-小分仓-撤回
- /// <summary>
- /// 创客-首页-仓库管理-小分仓-撤回
- /// </summary>
- /// <param name="UserId">发货人Id</param>
- /// <param name="Id">记录Id</param>
- public static string CancelDo(int UserId, int Id)
- {
- RedisDbconn.Instance.Set("SmallStoreCancel:" + UserId, "wait");
- RedisDbconn.Instance.SetExpire("SmallStoreCancel:" + UserId, 300);
- var query = PreSendStockDetailService.Query("FromUserId='" + UserId + "' and Id='" + Id + "'");
- var userAccount = UserAccountService.Query(UserId);
- var tuserAccount = UserAccountService.Query(query.ToUserId);
- var brandInfo = KqProductsService.Query(query.BrandId);
- var date = DateTime.Now.AddDays(-30);
- var amount = 0;
- if (query.Id > 0)
- {
- var posMachinesTwo = PosMachinesTwoService.Query(query.SnId);
- var storeHouse = StoreHouseService.Query(query.FromStoreId);
- var pm = PosMachinesTwoService.Query(query.SnId);
- if (brandInfo.Kind == 1)
- {
- amount = 200;
- }
- if (brandInfo.Kind == 2)
- {
- amount = 300;
- }
- if (pm != null)
- {
- if (pm.BindingState == 1)
- {
- return "机具已绑定,不可撤回!请创客申请机具后补录!";
- }
- var smallStoreHouse = SmallStoreHouseService.Query("UserId='" + query.ToUserId + "'");
- //赋值机具预发机所属人信息
- PosMachinesTwoUtil.SetPosMachinesTwoValue(posMachinesTwo.Id, 0);
- //修改机具预发机所属人标记
- PosMachinesTwoUtil.EditPosPreUserIdValue(LPos);
- //修改预发货库存明细(创客-首页-仓库管理-小分仓-撤回)
- EditPreSendStockDetail(query.Id, -1, 1);
- //修改仓库剩余库存数
- StoreHouseUtil.EditStoreLaveNum(storeHouse.Id, storeHouse.LaveNum += 1);
- //修改小仓库库存
- SmallStoreHouseUtil.EditStoreStock(smallStoreHouse.Id, smallStoreHouse.LaveNum += 1, smallStoreHouse.TotalNum -= 1);
- if (query.CreateDate <= date)
- {
- //撤回占用小分仓额度的增加接收创客的小分仓可用额度
- if (query.AuthFlag == 1 && tuserAccount.SmallStoreDeposit >= amount)
- {
- //扣减分仓可用额度
- Dictionary<string, object> userAccountData = new Dictionary<string, object>();
- userAccountData.Add("ValidAmount", userAccount.ValidAmount -= amount);
- UserAccountService.Edit(userAccountData, userAccount.Id);
- //增加小分仓可用额度
- Dictionary<string, object> tuserAccountData = new Dictionary<string, object>();
- tuserAccountData.Add("SmallStoreDeposit", tuserAccount.SmallStoreDeposit -= amount);
- tuserAccountData.Add("ValidPreAmount", tuserAccount.ValidPreAmount += amount);
- UserAccountService.Edit(tuserAccountData, userAccount.Id);
- //预发机撤回退还小分仓押金
- UserAccountRecordUtil.AddRecordForCanclePos("小分仓押金退还", 66, tuserAccount.SmallStoreDeposit + amount, tuserAccount.SmallStoreDeposit, amount, tuserAccount.Id);
- }
- }
- else
- {
- //撤回占用小分仓额度的增加接收创客的小分仓可用额度
- if (query.AuthFlag == 1)
- {
- //扣减分仓可用额度
- Dictionary<string, object> userAccountData = new Dictionary<string, object>();
- userAccountData.Add("ValidAmount", userAccount.ValidAmount -= amount);
- UserAccountService.Edit(userAccountData, userAccount.Id);
- //增加小分仓可用额度
- Dictionary<string, object> tuserAccountData = new Dictionary<string, object>();
- tuserAccountData.Add("ValidPreAmount", tuserAccount.ValidPreAmount += amount);
- UserAccountService.Edit(tuserAccountData, userAccount.Id);
- }
- }
- string text = string.Format("创客-首页-仓库管理-小分仓-撤回,UserId: '" + UserId + "',ToUserId: '" + smallStoreHouse.UserId + "',LaveNum:'" + smallStoreHouse.LaveNum + "',TotalNum:'" + smallStoreHouse.TotalNum + "',ChangeCount:'" + 1 + "',Time'" + DateTime.Now + "'");
- function.WriteLog(text, "smallstorehouse");//小分仓记录日志
- if (smallStoreHouse.LaveNum > 10 || smallStoreHouse.TotalNum < 0)
- {
- return "*库存已重置,不可撤回!";
- }
- BaseClass.SendPersonalMsg(query.ToUserId, 0, "预发机撤回通知", "<div class='f16'>您的预发机 SN:<br/>" + query.SnNo + "<br/>已被" + storeHouse.StoreName + " 撤回!</div>", "您的预发机: " + brandInfo.Name + " sn:" + query.SnNo + "已被 " + storeHouse.StoreName + " 撤回!");
- var toUser = UsersService.Query(query.ToUserId);
- BaseClass.SendPersonalMsg(query.FromUserId, 0, "预发机撤回通知", "<div class='f16'>已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:<br/>" + query.SnNo + "</div>", "已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:" + query.SnNo + "");
- }
- }
- RedisDbconn.Instance.SetExpire("SmallStoreCancel:" + UserId, 1);
- return "success";
- }
- #endregion
- #region 赋值预发货库存明细(创客-首页-仓库管理-小分仓-确认发货)
- /// <summary>
- /// 赋值预发货库存明细(创客-首页-仓库管理-小分仓-确认发货)
- /// </summary>
- public static void SetPreSendStockDetailValue(int FromUserId, int ToUserId, int SourceStoreId, int BrandId, string SnNo, int FromStoreId, int ToStoreId, int StoreId, int SnId)
- {
- PreSendStockDetail pd = new PreSendStockDetail();
- pd.CreateDate = DateTime.Now; //创建时间
- pd.FromUserId = FromUserId;//发货人Id
- pd.ToUserId = ToUserId; //收货人Id
- pd.SourceStoreId = SourceStoreId; //源仓库Id
- pd.BrandId = BrandId; //产品类型Id
- pd.SnNo = SnNo; //机具SN
- pd.FromStoreId = FromStoreId; //出货仓库Id
- pd.ToStoreId = ToStoreId; //收货仓库Id
- pd.StoreId = ToStoreId; //仓库Id
- pd.SnId = SnId;
- LPD.Add(pd);
- }
- #endregion
- #region 添加预发货库存明细(创客-首页-仓库管理-小分仓-确认发货)
- /// <summary>
- /// 添加预发货库存明细(创客-首页-仓库管理-小分仓-确认发货)
- /// </summary>
- public static void AddPreSendStockDetail(List<PreSendStockDetail> pds)
- {
- foreach (var item in pds)
- {
- Dictionary<string, object> query = new Dictionary<string, object>();
- query.Add("FromUserId", item.FromUserId);//发货人Id
- query.Add("ToUserId", item.ToUserId); //收货人Id
- query.Add("SourceStoreId", item.SourceStoreId); //源仓库Id
- query.Add("BrandId", item.BrandId); //产品类型Id
- query.Add("SnNo", item.SnNo); //机具SN
- query.Add("FromStoreId", item.FromStoreId); //出货仓库Id
- query.Add("ToStoreId", item.ToStoreId); //收货仓库Id
- query.Add("StoreId", item.StoreId); //仓库Id
- query.Add("SnId", item.SnId);
- PreSendStockDetailService.Add(query);
- }
- }
- #endregion
- #region 修改预发货库存明细(创客-首页-仓库管理-小分仓-撤回)
- /// <summary>
- /// 修改预发货库存明细(创客-首页-仓库管理-小分仓-撤回)
- /// </summary>
- /// <param name="Id">记录Id</param>
- /// <param name="Status">状态</param>
- /// <param name="CancelFlag">撤回标记</param>
- public static void EditPreSendStockDetail(int Id, int Status, int CancelFlag)
- {
- Dictionary<string, object> query = new Dictionary<string, object>();
- query.Add("Status", Status);
- query.Add("CancelFlag", CancelFlag);
- PreSendStockDetailService.Edit(query, Id);
- }
- #endregion
- }
- }
|