123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Microsoft.AspNetCore.Authorization;
- using System.Web;
- using MySystem.MainModels;
- using LitJson;
- using Library;
- namespace MySystem.Areas.Api.Controllers.v1
- {
- [Area("Api")]
- [Route("Api/v1/[controller]/[action]")]
- public class StoreStockChangeController : BaseController
- {
- public StoreStockChangeController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
- }
- #region 首页-仓库管理-整箱划拨
- [Authorize]
- public JsonResult TransferWhole(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = TransferWholeDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson TransferWholeDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int OrderId = int.Parse(function.CheckInt(data["OrderId"].ToString()));
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
- int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人
- string SnNo = data["SnNo"].ToString(); //首台SN编号
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- if (string.IsNullOrEmpty(SnNo))
- {
- return new AppResultJson() { Status = "-1", Info = "请选择机具" };
- }
- StoreHouse store = maindb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
- string[] SnIdList = SnNo.Split(',');
- string SnNos = ""; //划拨的机具号(多个)
- Orders order = maindb.Orders.FirstOrDefault(m => m.Id == OrderId);
- if (order != null)
- {
- if (order.Status == 2)
- {
- return new AppResultJson() { Status = "-1", Info = "该订单已处理,请勿重复操作" };
- }
- int ApplyType = 0; // 申请类型,1-机具SN,2-200兑换码,3-300券
- List<string> SourceSnNos = new List<string>();
- if (order.Sort > 0)
- {
- MachineApply Apply = maindb.MachineApply.FirstOrDefault(m => m.Id == order.Sort);
- if (Apply != null)
- {
- Apply.Status = 1;
- Apply.QueryCount = order.Id;
- ApplyType = Apply.Sort;
- if (!string.IsNullOrEmpty(Apply.SwapSnExpand))
- {
- string[] SwapSnExpands = Apply.SwapSnExpand.Split('\n');
- foreach (string sub in SwapSnExpands)
- {
- if (!string.IsNullOrEmpty(sub))
- {
- SourceSnNos.Add(sub.Split(':')[0]);
- }
- }
- }
- }
- }
- Dictionary<int, string> couponIds = new Dictionary<int, string>();
- int SnIndex = 0;
- foreach (string SnId in SnIdList)
- {
- string ChangeNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
- int SnIdNum = int.Parse(SnId);
- int LeaderUserId = 0;
- // int OpId = 0;
- DateTime RecycEndDate = DateTime.Now.AddDays(360);
- if (SourceSnNos.Count > SnIndex)
- {
- string SourceSnNo = SourceSnNos[SnIndex];
- if (ApplyType <= 1)
- {
- MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSnNo) ?? new MachineForSnNo();
- PosMachinesTwo spos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
- RecycEndDate = spos.RecycEndDate == null ? RecycEndDate = DateTime.Now.AddDays(360) : spos.RecycEndDate.Value;
- LeaderUserId = spos.LeaderUserId;
- // OpId = spos.OpId;
- }
- else if (ApplyType > 1)
- {
- PosCoupons coupon = maindb.PosCoupons.FirstOrDefault(m => m.ExchangeCode == SourceSnNo) ?? new PosCoupons();
- LeaderUserId = coupon.LeaderUserId;
- if (coupon.OpId > 0)
- {
- if (couponIds.ContainsKey(coupon.OpId))
- {
- string[] datas = couponIds[coupon.OpId].Split(',');
- int Num = int.Parse(datas[2]) + 1;
- couponIds[coupon.OpId] = datas[0] + "," + datas[1] + "," + Num;
- }
- else
- {
- couponIds.Add(coupon.OpId, coupon.Id + "," + coupon.QueryCount + ",1");
- }
- // OpId = coupon.OpId;
- }
- }
- }
- PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum) ?? new PosMachinesTwo();
- //扣减分仓所关联的运营中心总机具数
- if (pos.OpId > 0)
- {
- var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == pos.OpId) ?? new OpModels.SysAdmin();
- if (sysAdmin.Id > 0)
- {
- sysAdmin.TotalMachineCount -= 1;
- opdb.SaveChanges();
- }
- }
- SnNos += pos.PosSn + ",";
- Users toUser = UsersDbconn.Instance.Get(ToUserId) ?? new Users();
- StoreStockChange query = maindb.StoreStockChange.Add(new StoreStockChange()
- {
- CreateDate = DateTime.Now,
- StoreId = StoreId, //仓库
- BrandId = pos.BrandId, //产品类型
- ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
- ChangeNo = ChangeNo, //变更单号
- TransType = 10, //交易类型
- SnNo = pos.PosSn, //SN编号
- SnType = pos.PosSnType, //SN机具类型
- StockOpDirect = 1, //库存操作方向
- DeviceType = pos.DeviceType, //设备类型
- FromUserId = store.UserId, //出货人
- FromDate = DateTime.Now, //出库时间
- ToUserId = ToUserId, //收货人
- ToStoreId = StoreId, //退货收货仓库
- OpId = pos.OpId
- }).Entity;
- UserStoreChange userstore = maindb.UserStoreChange.Add(new UserStoreChange()
- {
- CreateDate = DateTime.Now,
- UserId = store.UserId, //创客
- BrandId = pos.BrandId, //产品类型
- ChangeRecordNo = ChangeNo, //变更记录单号
- TransType = 0, //交易类型
- SnNo = pos.PosSn, //SN编号
- SnType = pos.PosSnType, //SN机具类型
- StockOpDirect = 0, //库存操作方向
- DeviceVendor = pos.DeviceName, //设备厂商
- DeviceType = pos.DeviceKind, //设备类型
- DeviceModel = pos.DeviceType, //设备型号
- ToUserId = ToUserId, //收货创客
- ToDate = DateTime.Now, //入库时间
- SourceStoreId = pos.SourceStoreId, //源仓库
- SnStatus = 1, //SN状态
- BindStatus = (int)pos.BindingState, //绑定状态
- BindMerchantId = pos.BindMerchantId, //绑定商户
- ActiveStatus = (int)pos.ActivationState, //激活状态
- ActRewardUserId = pos.BuyUserId, //激活奖励创客
- BrandType = pos.DeviceType, //品牌类型
- }).Entity;
- StoreChangeHistory history = maindb.StoreChangeHistory.Add(new StoreChangeHistory()
- {
- CreateDate = DateTime.Now,
- UserId = store.UserId, //创客
- BrandId = pos.BrandId, //产品类型
- ChangeRecordNo = ChangeNo, //变更记录单号
- TransType = 2, //交易类型
- SnNo = pos.PosSn, //SN编号
- SnType = pos.PosSnType, //SN机具类型
- StockOpDirect = 1, //库存操作方向
- DeviceVendor = pos.DeviceName, //设备厂商
- DeviceModel = pos.DeviceKind, //设备型号
- DeviceType = pos.DeviceType, //设备类型
- ToUserId = ToUserId, //收货创客
- FromUserId = store.UserId, //出货创客
- FromDate = DateTime.Now, //出库时间
- SourceStoreId = pos.SourceStoreId, //源仓库
- StoreId = store.Id, //仓库
- OpId = pos.OpId
- }).Entity;
- maindb.SaveChanges();
- PublicFunction.StatUserMachineData(ToUserId, pos.BrandId, 1);
- store.LaveNum -= 1;
- store.OutNum += 1;
- pos.OrderId = OrderId;
- pos.BuyUserId = ToUserId;
- pos.UserId = ToUserId;
- pos.TransferTime = DateTime.Now;
- pos.RecycEndDate = RecycEndDate; // 循环结束时间
- pos.PosSnType = order.QueryCount; //机具类型,0-兑换机,1-循环机
- pos.LeaderUserId = LeaderUserId;
- // pos.OpId = OpId;
- maindb.SaveChanges();
- SnIndex += 1;
- }
- order.Status = 2;
- order.SendStatus = 1;
- order.SendDate = DateTime.Now;
- order.SnNos = SnNos.TrimEnd(',');
- maindb.SaveChanges();
- //扣减分仓所关联的运营和中心总机具数
- if (store.OpId > 0)
- {
- var count = SnIdList.Count();
- var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == store.OpId) ?? new OpModels.SysAdmin();
- if (sysAdmin.Id > 0)
- {
- sysAdmin.TotalMachineCount -= count;
- opdb.SaveChanges();
- }
- }
- string SendData = "{\"Kind\":\"4\",\"Data\":{\"StoreId\":\"" + StoreId + "\",\"SnIds\":\"" + SnNo + "\"}}";
- //只给对应分仓增加可用额度
- RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
- // if(ApplyType > 1)
- // {
- // // 兑换成机具将向运营中心返还对应机具额度
- // foreach(int OpId in couponIds.Keys)
- // {
- // string[] datalist = couponIds[OpId].Split(',');
- // decimal OperateAmount = 200 + int.Parse(datalist[2]);
- // if(datalist[1] == "2") OperateAmount = 300 + int.Parse(datalist[2]);
- // string OperateData = "{\"UserId\":\"" + OpId + "\",\"DataId\":\"" + datalist[0] + "\",\"Kind\":\"1\",\"Amount\":\"" + OperateAmount + "\"}";
- // RedisDbconn.Instance.AddList("OperateAmountQueue", OperateData);
- // }
- // }
- }
- maindb.Dispose();
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 首页-仓库管理-逐台划拨
- [Authorize]
- public JsonResult TransferOne(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = TransferOneDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson TransferOneDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int OrderId = int.Parse(function.CheckInt(data["OrderId"].ToString()));
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
- int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人
- string SnIds = data["SnIds"].ToString(); //SN的Id集合
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- if (string.IsNullOrEmpty(SnIds))
- {
- return new AppResultJson() { Status = "-1", Info = "请选择机具" };
- }
- StoreHouse store = maindb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
- string[] SnIdList = SnIds.Split(',');
- string SnNos = ""; //划拨的机具号(多个)
- Orders order = maindb.Orders.FirstOrDefault(m => m.Id == OrderId);
- if (order != null)
- {
- if (order.Status == 2)
- {
- return new AppResultJson() { Status = "-1", Info = "该订单已处理,请勿重复操作" };
- }
- int ApplyType = 0; // 申请类型,1-机具SN,2-200兑换码,3-300券
- List<string> SourceSnNos = new List<string>();
- if (order.Sort > 0)
- {
- MachineApply Apply = maindb.MachineApply.FirstOrDefault(m => m.Id == order.Sort);
- if (Apply != null)
- {
- Apply.Status = 1;
- Apply.QueryCount = order.Id;
- ApplyType = Apply.Sort;
- if (!string.IsNullOrEmpty(Apply.SwapSnExpand))
- {
- string[] SwapSnExpands = Apply.SwapSnExpand.Split('\n');
- foreach (string sub in SwapSnExpands)
- {
- if (!string.IsNullOrEmpty(sub))
- {
- SourceSnNos.Add(sub.Split(':')[0]);
- }
- }
- }
- }
- }
- Dictionary<int, string> couponIds = new Dictionary<int, string>();
- int SnIndex = 0;
- foreach (string SnId in SnIdList)
- {
- string ChangeNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
- int SnIdNum = int.Parse(SnId);
- DateTime RecycEndDate = DateTime.Now.AddDays(360);
- int LeaderUserId = 0;
- // int OpId = 0;
- if (SourceSnNos.Count > SnIndex)
- {
- string SourceSnNo = SourceSnNos[SnIndex];
- if (ApplyType <= 1)
- {
- MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSnNo) ?? new MachineForSnNo();
- PosMachinesTwo spos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
- RecycEndDate = spos.RecycEndDate == null ? RecycEndDate = DateTime.Now.AddDays(360) : spos.RecycEndDate.Value;
- LeaderUserId = spos.LeaderUserId;
- // OpId = spos.OpId;
- }
- else if (ApplyType > 1)
- {
- PosCoupons coupon = maindb.PosCoupons.FirstOrDefault(m => m.ExchangeCode == SourceSnNo) ?? new PosCoupons();
- LeaderUserId = coupon.LeaderUserId;
- if (coupon.OpId > 0)
- {
- if (couponIds.ContainsKey(coupon.OpId))
- {
- string[] datas = couponIds[coupon.OpId].Split(',');
- int Num = int.Parse(datas[2]) + 1;
- couponIds[coupon.OpId] = datas[0] + "," + datas[1] + "," + Num;
- }
- else
- {
- couponIds.Add(coupon.OpId, coupon.Id + "," + coupon.QueryCount + ",1");
- }
- }
- }
- }
- PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum) ?? new PosMachinesTwo();
- //扣减分仓所关联的运营中心总机具数
- if (pos.OpId > 0)
- {
- var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == pos.OpId) ?? new OpModels.SysAdmin();
- if (sysAdmin.Id > 0)
- {
- sysAdmin.TotalMachineCount -= 1;
- opdb.SaveChanges();
- }
- }
- if (StoreId == 0)
- {
- StoreId = pos.StoreId;
- }
- SnNos += pos.PosSn + ",";
- Users toUser = UsersDbconn.Instance.Get(ToUserId) ?? new Users();
- StoreStockChange query = maindb.StoreStockChange.Add(new StoreStockChange()
- {
- CreateDate = DateTime.Now,
- StoreId = StoreId, //仓库
- BrandId = pos.BrandId, //产品类型
- ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
- ChangeNo = ChangeNo, //变更单号
- TransType = 11, //交易类型
- SnNo = pos.PosSn, //SN编号
- SnType = pos.PosSnType, //SN机具类型
- StockOpDirect = 1, //库存操作方向
- DeviceType = pos.DeviceType, //设备类型
- FromUserId = store.UserId, //出货人
- FromDate = DateTime.Now, //出库时间
- ToUserId = ToUserId, //收货人
- ToStoreId = StoreId, //退货收货仓库
- OpId = pos.OpId
- }).Entity;
- UserStoreChange userstore = maindb.UserStoreChange.Add(new UserStoreChange()
- {
- CreateDate = DateTime.Now,
- UserId = store.UserId, //创客
- BrandId = pos.BrandId, //产品类型
- ChangeRecordNo = ChangeNo, //变更记录单号
- TransType = 0, //交易类型
- SnNo = pos.PosSn, //SN编号
- SnType = pos.PosSnType, //SN机具类型
- StockOpDirect = 0, //库存操作方向
- DeviceVendor = pos.DeviceName, //设备厂商
- DeviceType = pos.DeviceKind, //设备类型
- DeviceModel = pos.DeviceType, //设备型号
- ToUserId = ToUserId, //收货创客
- ToDate = DateTime.Now, //入库时间
- SourceStoreId = pos.SourceStoreId, //源仓库
- SnStatus = 1, //SN状态
- BindStatus = (int)pos.BindingState, //绑定状态
- BindMerchantId = pos.BindMerchantId, //绑定商户
- ActiveStatus = (int)pos.ActivationState, //激活状态
- ActRewardUserId = pos.BuyUserId, //激活奖励创客
- BrandType = pos.DeviceType, //品牌类型
- }).Entity;
- StoreChangeHistory history = maindb.StoreChangeHistory.Add(new StoreChangeHistory()
- {
- CreateDate = DateTime.Now,
- UserId = store.UserId, //创客
- BrandId = pos.BrandId, //产品类型
- ChangeRecordNo = ChangeNo, //变更记录单号
- TransType = 2, //交易类型
- SnNo = pos.PosSn, //SN编号
- SnType = pos.PosSnType, //SN机具类型
- StockOpDirect = 1, //库存操作方向
- DeviceVendor = pos.DeviceName, //设备厂商
- DeviceModel = pos.DeviceKind, //设备型号
- DeviceType = pos.DeviceType, //设备类型
- ToUserId = ToUserId, //收货创客
- FromUserId = store.UserId, //出货创客
- FromDate = DateTime.Now, //出库时间
- SourceStoreId = pos.SourceStoreId, //源仓库
- StoreId = store.Id, //仓库
- OpId = pos.OpId
- }).Entity;
- maindb.SaveChanges();
- PublicFunction.StatUserMachineData(ToUserId, pos.BrandId, 1);
- store.LaveNum -= 1;
- store.OutNum += 1;
- pos.OrderId = OrderId;
- pos.BuyUserId = ToUserId;
- pos.UserId = ToUserId;
- pos.TransferTime = DateTime.Now;
- pos.RecycEndDate = RecycEndDate; // 循环结束时间
- pos.PosSnType = order.QueryCount;
- pos.LeaderUserId = LeaderUserId;
- //机子无标记就赋运营中心的值
- // if ((pos.OpId == 0 && ApplyType > 1) || ApplyType <= 1)
- // {
- // pos.OpId = OpId;
- // }
- maindb.SaveChanges();
- SnIndex += 1;
- }
- order.Status = 2;
- order.SendStatus = 1;
- order.SendDate = DateTime.Now;
- order.SnNos = SnNos.TrimEnd(',');
- maindb.SaveChanges();
- string SendData = "{\"Kind\":\"4\",\"Data\":{\"StoreId\":\"" + StoreId + "\",\"SnIds\":\"" + SnIds + "\"}}";
- RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
- // if(ApplyType > 1)
- // {
- // // 兑换成机具将向运营中心返还对应机具额度
- // foreach(int OpId in couponIds.Keys)
- // {
- // string[] datalist = couponIds[OpId].Split(',');
- // decimal OperateAmount = 200 + int.Parse(datalist[2]);
- // if(datalist[1] == "2") OperateAmount = 300 + int.Parse(datalist[2]);
- // string OperateData = "{\"UserId\":\"" + OpId + "\",\"DataId\":\"" + datalist[0] + "\",\"Kind\":\"1\",\"Amount\":\"" + OperateAmount + "\"}";
- // RedisDbconn.Instance.AddList("OperateAmountQueue", OperateData);
- // }
- // }
- }
- maindb.Dispose();
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 首页-仓库管理-售后单-划拨
- [Authorize]
- public JsonResult TransferForChange(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = TransferForChangeDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson TransferForChangeDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int OrderId = int.Parse(function.CheckInt(data["OrderId"].ToString()));
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
- string SnIds = data["SnIds"].ToString(); //SN的Id集合
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- if (string.IsNullOrEmpty(SnIds))
- {
- return new AppResultJson() { Status = "-1", Info = "请选择机具" };
- }
- int CheckCount = maindb.MachineChange.Count(m => m.OutStoreId == StoreId && m.AuditResult == 0);
- if (CheckCount >= 10)
- {
- return new AppResultJson() { Status = "-1", Info = "待审核订单超过10单,请等待管理员审核" };
- }
- StoreHouse store = maindb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
- string[] SnIdList = SnIds.Split(',');
- string SnNos = ""; //划拨的机具号(多个)
- Orders order = maindb.Orders.FirstOrDefault(m => m.Id == OrderId);
- if (order != null)
- {
- if (order.Status == 2)
- {
- return new AppResultJson() { Status = "-1", Info = "该订单已处理,请勿重复操作" };
- }
- int ToUserId = order.UserId;
- int ChangeId = 0;
- List<string> SourceSnNos = new List<string>();
- if (order.Sort > 0)
- {
- MachineChange Apply = maindb.MachineChange.FirstOrDefault(m => m.Id == order.Sort);
- if (Apply != null)
- {
- Apply.Status = 1;
- if (!string.IsNullOrEmpty(Apply.ChangeSnExpand))
- {
- string[] ChangeSnExpand = Apply.ChangeSnExpand.Split('\n');
- foreach (string sub in ChangeSnExpand)
- {
- if (!string.IsNullOrEmpty(sub))
- {
- SourceSnNos.Add(sub.Split(':')[0]);
- }
- }
- }
- ChangeId = Apply.Id;
- }
- }
- int SnIndex = 0;
- List<string> contents = new List<string>();
- foreach (string SnId in SnIdList)
- {
- string ChangeNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
- int SnIdNum = int.Parse(SnId);
- DateTime RecycEndDate = DateTime.Now.AddDays(360);
- string SourceSnNo = "";
- if (SourceSnNos.Count > SnIndex)
- {
- SourceSnNo = SourceSnNos[SnIndex];
- MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSnNo) ?? new MachineForSnNo();
- PosMachinesTwo spos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
- RecycEndDate = spos.RecycEndDate == null ? RecycEndDate = DateTime.Now.AddDays(360) : spos.RecycEndDate.Value;
- }
- PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum) ?? new PosMachinesTwo();
- //扣减分仓所关联的运营中心总机具数
- if (pos.OpId > 0)
- {
- var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == pos.OpId) ?? new OpModels.SysAdmin();
- if (sysAdmin.Id > 0)
- {
- sysAdmin.TotalMachineCount -= 1;
- opdb.SaveChanges();
- }
- }
- PosMerchantInfo merchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
- SnNos += pos.PosSn + ",";
- Users toUser = UsersDbconn.Instance.Get(ToUserId) ?? new Users();
- StoreStockChange query = maindb.StoreStockChange.Add(new StoreStockChange()
- {
- CreateDate = DateTime.Now,
- StoreId = StoreId, //仓库
- BrandId = pos.BrandId, //产品类型
- ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
- ChangeNo = ChangeNo, //变更单号
- TransType = 11, //交易类型
- SnNo = pos.PosSn, //SN编号
- SnType = pos.PosSnType, //SN机具类型
- StockOpDirect = 1, //库存操作方向
- DeviceType = pos.DeviceType, //设备类型
- FromUserId = store.UserId, //出货人
- FromDate = DateTime.Now, //出库时间
- ToUserId = ToUserId, //收货人
- ToStoreId = StoreId, //退货收货仓库
- }).Entity;
- UserStoreChange userstore = maindb.UserStoreChange.Add(new UserStoreChange()
- {
- CreateDate = DateTime.Now,
- UserId = store.UserId, //创客
- BrandId = pos.BrandId, //产品类型
- ChangeRecordNo = ChangeNo, //变更记录单号
- TransType = 0, //交易类型
- SnNo = pos.PosSn, //SN编号
- SnType = pos.PosSnType, //SN机具类型
- StockOpDirect = 0, //库存操作方向
- DeviceVendor = pos.DeviceName, //设备厂商
- DeviceType = pos.DeviceKind, //设备类型
- DeviceModel = pos.DeviceType, //设备型号
- ToUserId = ToUserId, //收货创客
- ToDate = DateTime.Now, //入库时间
- SourceStoreId = pos.SourceStoreId, //源仓库
- SnStatus = 1, //SN状态
- BindStatus = (int)pos.BindingState, //绑定状态
- BindMerchantId = pos.BindMerchantId, //绑定商户
- ActiveStatus = (int)pos.ActivationState, //激活状态
- ActRewardUserId = pos.BuyUserId, //激活奖励创客
- BrandType = pos.DeviceType, //品牌类型
- }).Entity;
- StoreChangeHistory history = maindb.StoreChangeHistory.Add(new StoreChangeHistory()
- {
- CreateDate = DateTime.Now,
- UserId = store.UserId, //创客
- BrandId = pos.BrandId, //产品类型
- ChangeRecordNo = ChangeNo, //变更记录单号
- TransType = 2, //交易类型
- SnNo = pos.PosSn, //SN编号
- SnType = pos.PosSnType, //SN机具类型
- StockOpDirect = 1, //库存操作方向
- DeviceVendor = pos.DeviceName, //设备厂商
- DeviceModel = pos.DeviceKind, //设备型号
- DeviceType = pos.DeviceType, //设备类型
- ToUserId = ToUserId, //收货创客
- FromUserId = store.UserId, //出货创客
- FromDate = DateTime.Now, //出库时间
- SourceStoreId = pos.SourceStoreId, //源仓库
- StoreId = store.Id, //仓库
- }).Entity;
- maindb.SaveChanges();
- PublicFunction.StatUserMachineData(ToUserId, pos.BrandId, 1);
- store.LaveNum -= 1;
- store.OutNum += 1;
- pos.OrderId = OrderId;
- pos.BuyUserId = ToUserId;
- pos.UserId = ToUserId;
- pos.TransferTime = DateTime.Now;
- pos.RecycEndDate = RecycEndDate; // 循环结束时间
- pos.PosSnType = order.QueryCount;
- maindb.SaveChanges();
- SnIndex += 1;
- string content = "{"; //执行机具数据同步
- content += "\"OldSn\":\"" + SourceSnNo + "\",";
- content += "\"NewSn\":\"" + pos.PosSn + "\",";
- content += "\"MerNo\":\"" + merchant.KqMerNo + "\",";
- content += "\"ChangeId\":\"" + ChangeId + "\"";
- content += "}";
- contents.Add(content);
- }
- order.Status = 2;
- order.SendStatus = 1;
- order.SendDate = DateTime.Now;
- order.SnNos = SnNos.TrimEnd(',');
- maindb.SaveChanges();
- foreach (string content in contents)
- {
- RedisDbconn.Instance.AddList("ChangePosTimerQueue", content);
- }
- string SendData = "{\"Kind\":\"4\",\"Data\":{\"StoreId\":\"" + StoreId + "\",\"SnIds\":\"" + SnIds + "\"}}";
- RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
- }
- maindb.Dispose();
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 首页-仓库管理-售后单-划拨验证
- [Authorize]
- public JsonResult TransferForCheck(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = TransferForCheckDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson TransferForCheckDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
- int CheckCount = maindb.MachineChange.Count(m => m.OutStoreId == StoreId && m.AuditResult == 0);
- if (CheckCount >= 10)
- {
- return new AppResultJson() { Status = "-1", Info = "待审核订单超过10单,请等待管理员审核" };
- }
- return new AppResultJson() { Status = "1", Info = "" };
- }
- #endregion
- #region 首页-仓库管理-售后单-驳回
- [Authorize]
- public JsonResult RefuseForChange(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = RefuseForChangeDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson RefuseForChangeDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int OrderId = int.Parse(function.CheckInt(data["OrderId"].ToString()));
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
- Orders order = maindb.Orders.FirstOrDefault(m => m.Id == OrderId && m.StoreId == StoreId);
- if (order != null)
- {
- order.Status = -1;
- MachineChange change = maindb.MachineChange.FirstOrDefault(m => m.Id == order.Sort);
- if (change != null)
- {
- change.AuditResult = 2;
- }
- maindb.SaveChanges();
- maindb.Dispose();
- return new AppResultJson() { Status = "1", Info = "" };
- }
- maindb.Dispose();
- return new AppResultJson() { Status = "-1", Info = "" };
- }
- #endregion
- #region 创客-首页-仓库管理-划拨记录-拨入
- [Authorize]
- public JsonResult In(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = InDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> InDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string SearchKey = data["SearchKey"].ToString();
- int ToStoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //退货收货仓库
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- IQueryable<StoreStockChange> query = maindb.StoreStockChange.Where(m => m.ToStoreId == ToStoreId);
- if (!string.IsNullOrEmpty(SearchKey))
- {
- query = query.Where(m => m.SnNo == SearchKey);
- }
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- query = query.OrderByDescending(m => m.Id);
- foreach (var subdata in query.ToList())
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("StoreId", subdata.StoreId); //仓库
- Dictionary<string, object> StoreInfo = new Dictionary<string, object>();
- StoreHouse StoreHouseData = maindb.StoreHouse.FirstOrDefault(m => m.Id == subdata.StoreId) ?? new StoreHouse();
- StoreInfo.Add("StoreName", StoreHouseData.StoreName); //仓库名称
- curData.Add("StoreInfo", StoreInfo);
- curData.Add("SnNo", subdata.SnNo); //SN编号
- curData.Add("FromUserId", subdata.FromUserId); //出货人
- Dictionary<string, object> UserInfo = new Dictionary<string, object>();
- Users UsersData = maindb.Users.FirstOrDefault(m => m.Id == subdata.FromUserId) ?? new Users();
- UserInfo.Add("RealName", UsersData.RealName); //真实姓名
- UserInfo.Add("MakerCode", UsersData.MakerCode); //创客编号
- UserInfo.Add("Mobile", UsersData.Mobile); //手机号
- curData.Add("UserInfo", UserInfo);
- curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 创客-首页-仓库管理-划拨记录-拨出
- [Authorize]
- public JsonResult Out(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = OutDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> OutDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string SearchKey = data["SearchKey"].ToString();
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- IQueryable<StoreStockChange> query = maindb.StoreStockChange.Where(m => m.StoreId == StoreId && m.ToUserId > 0);
- if (!string.IsNullOrEmpty(SearchKey))
- {
- query = query.Where(m => m.SnNo == SearchKey);
- }
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- query = query.OrderByDescending(m => m.Id);
- foreach (var subdata in query.ToList())
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("ChangeNo", subdata.ChangeNo); //变更单号
- curData.Add("SnNo", subdata.SnNo); //SN编号
- curData.Add("ToUserId", subdata.ToUserId); //收货人
- Dictionary<string, object> UserInfo = new Dictionary<string, object>();
- Users UsersData = maindb.Users.FirstOrDefault(m => m.Id == subdata.ToUserId) ?? new Users();
- UserInfo.Add("RealName", UsersData.RealName); //真实姓名
- UserInfo.Add("MakerCode", UsersData.MakerCode); //创客编号
- UserInfo.Add("Mobile", UsersData.Mobile); //手机号
- curData.Add("UserInfo", UserInfo);
- curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 创客-首页-仓库管理-出货记录-按天
- [Authorize]
- public JsonResult ForDate(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = ForDateDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> ForDateDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
- // int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
- string Month = data["Month"].ToString(); //月份
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- DataTable dt = OtherMySqlConn.dtable("SELECT DATE_FORMAT(CreateDate,'%Y%m%d') date,COUNT(0) count FROM StoreStockChange WHERE StoreId = '" + StoreId + "' AND TransType in (2,10,11) AND DATE_FORMAT(CreateDate,'%Y%m') = '" + Month + "' GROUP BY DATE_FORMAT(CreateDate,'%Y%m%d') ORDER BY DATE_FORMAT(CreateDate,'%Y%m%d') DESC");
- foreach (DataRow item in dt.Rows)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("Date", item["date"]); //时间
- curData.Add("ActTotal", Convert.ToInt32(function.CheckInt(item["count"].ToString()))); //总激活
- List<Dictionary<string, object>> snList = new List<Dictionary<string, object>>();
- DataTable dts = OtherMySqlConn.dtable("SELECT DATE_FORMAT(CreateDate,'%Y%m%d') date,SnNo FROM StoreStockChange WHERE StoreId = '" + StoreId + "' AND TransType in (2,10,11) AND DATE_FORMAT(CreateDate,'%Y%m%d') = '" + item["date"] + "'");
- foreach (DataRow items in dts.Rows)
- {
- Dictionary<string, object> sn = new Dictionary<string, object>();
- sn.Add("Date", items["date"]); //时间
- sn.Add("Sn", items["SnNo"]); //Sn
- snList.Add(sn);
- }
- curData.Add("SnList", snList);
- dataList.Add(curData);
- }
- dataList = dataList.Skip((PageNum - 1) * PageSize).Take(PageSize).ToList();//分页的重点
- return dataList;
- }
- #endregion
- #region 创客-首页-仓库管理-出货记录-按月
- [Authorize]
- public JsonResult ForMonth(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = ForMonthDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> ForMonthDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
- // int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- DataTable dt = OtherMySqlConn.dtable("SELECT DATE_FORMAT(CreateDate,'%Y%m') date,COUNT(0) count FROM StoreStockChange WHERE StoreId = '" + StoreId + "' AND TransType in (2,10,11) GROUP BY DATE_FORMAT(CreateDate,'%Y%m') ORDER BY DATE_FORMAT(CreateDate,'%Y%m') DESC");
- foreach (DataRow item in dt.Rows)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("Date", item["date"]); //时间
- curData.Add("ActTotal", Convert.ToInt32(function.CheckInt(item["count"].ToString()))); //总激活
- dataList.Add(curData);
- }
- dataList = dataList.Skip((PageNum - 1) * PageSize).Take(PageSize).ToList();//分页的重点
- return dataList;
- }
- #endregion
- #region 检查签名是否合法,合法返回1,不合法返回提示信息
- /// <summary>
- /// 检查签名是否合法,合法返回1,不合法返回提示信息
- /// </summary>
- /// <param name="value">请求的参数(json字符串)</param>
- /// <param name="signField">要签名的字段</param>
- /// <returns></returns>
- private string CheckSign(string value, string[] signField)
- {
- JsonData json = JsonMapper.ToObject(value);
- Dictionary<string, string> dic = new Dictionary<string, string>();
- for (int i = 0; i < signField.Length; i++)
- {
- dic.Add(signField[i], json[signField[i]].ToString());
- }
- string sign = json["sign"].ToString(); //客户端签名字符串
- return new Sign().sign(dic, sign);
- }
- #endregion
- }
- }
|