| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031 |
- /*
- * 运营中心机具申请记录
- */
- using System;
- using System.Web;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using MySystem.OpModels;
- using Library;
- using LitJson;
- using MySystemLib;
- namespace MySystem.Areas.Admin.Controllers
- {
- [Area("Admin")]
- [Route("Admin/[controller]/[action]")]
- public class StoreMachineApplyOperateController : BaseController
- {
- public StoreMachineApplyOperateController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 运营中心机具申请记录列表
- /// <summary>
- /// 根据条件查询运营中心机具申请记录列表
- /// </summary>
- /// <returns></returns>
- public IActionResult Index(StoreMachineApply data, string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 根据条件查询运营中心机具申请记录列表
- /// <summary>
- /// 运营中心机具申请记录列表
- /// </summary>
- /// <returns></returns>
- public JsonResult IndexData(StoreMachineApply data, string MakerCode, string OpCode, string CreateDateData, string StatusSelect, int page = 1, int limit = 30)
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- Fields.Add("ApplyNo", "1"); //申请单号
- Fields.Add("SendMode", "1"); //发货方式
- string condition = " and Status>-1 and Sort=0";
- if (!string.IsNullOrEmpty(CreateDateData))
- {
- string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- string start = datelist[0];
- string end = datelist[1];
- condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
- }
- //创客编号
- if (!string.IsNullOrEmpty(MakerCode))
- {
- condition += " and UserId in (select UserId from SysAdmin where MakerCode='" + MakerCode + "')";
- }
- //运营中心编号
- if (!string.IsNullOrEmpty(OpCode))
- {
- condition += " and UserId in (select UserId from SysAdmin where OpCode='" + OpCode + "')";
- }
- if (!string.IsNullOrEmpty(StatusSelect))
- {
- condition += " and Status=" + StatusSelect + "";
- }
- Dictionary<string, object> obj = new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).IndexData("StoreMachineApply", Fields, "Id desc", "0", page, limit, condition);
- List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
- foreach (Dictionary<string, object> dic in diclist)
- {
- //品牌
- dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
- int Status = int.Parse(dic["Status"].ToString());
- if (Status == 0) dic["StatusName"] = "待配货";
- if (Status == 1) dic["StatusName"] = "已发货";
- if (Status == 2) dic["StatusName"] = "已驳回";
- //创客
- int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
- SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.UserId == UserId) ?? new SysAdmin();
- dic["MakerName"] = sysAdmin.MakerName;
- dic["MakerCode"] = sysAdmin.MakerCode;
- dic["OpCode"] = sysAdmin.OpCode;
- dic.Remove("UserId");
- }
- return Json(obj);
- }
- #endregion
- #region 运营中心机具券申请记录列表
- /// <summary>
- /// 根据条件查询运营中心机具券申请记录列表
- /// </summary>
- /// <returns></returns>
- public IActionResult Indexs(StoreMachineApply data, string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 根据条件查询运营中心机具券申请记录列表
- /// <summary>
- /// 运营中心机具券申请记录列表
- /// </summary>
- /// <returns></returns>
- public JsonResult IndexsData(StoreMachineApply data, string MakerCode, string OpCode, string CreateDateData, string StatusSelect, int page = 1, int limit = 30)
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- Fields.Add("ApplyNo", "1"); //申请单号
- Fields.Add("SendMode", "1"); //发货方式
- string condition = " and Status>-1 and Sort=1";
- if (!string.IsNullOrEmpty(CreateDateData))
- {
- string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- string start = datelist[0];
- string end = datelist[1];
- condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
- }
- //创客编号
- if (!string.IsNullOrEmpty(MakerCode))
- {
- condition += " and UserId in (select UserId from SysAdmin where MakerCode='" + MakerCode + "')";
- }
- //运营中心编号
- if (!string.IsNullOrEmpty(OpCode))
- {
- condition += " and UserId in (select UserId from SysAdmin where OpCode='" + OpCode + "')";
- }
- if (!string.IsNullOrEmpty(StatusSelect))
- {
- condition += " and Status=" + StatusSelect + "";
- }
- Dictionary<string, object> obj = new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).IndexData("StoreMachineApply", Fields, "Id desc", "0", page, limit, condition);
- List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
- foreach (Dictionary<string, object> dic in diclist)
- {
- //品牌
- dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
- int Status = int.Parse(dic["Status"].ToString());
- if (Status == 0) dic["StatusName"] = "待配货";
- if (Status == 1) dic["StatusName"] = "已发货";
- if (Status == 2) dic["StatusName"] = "已驳回";
- //创客
- int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
- SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.UserId == UserId) ?? new SysAdmin();
- dic["MakerName"] = sysAdmin.MakerName;
- dic["MakerCode"] = sysAdmin.MakerCode;
- dic["OpCode"] = sysAdmin.OpCode;
- dic.Remove("UserId");
- }
- return Json(obj);
- }
- #endregion
- #region 增加分仓机具申请记录
- /// <summary>
- /// 增加或修改分仓机具申请记录信息
- /// </summary>
- /// <returns></returns>
- public IActionResult Add(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 增加分仓机具申请记录
- /// <summary>
- /// 增加或修改分仓机具申请记录信息
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public string Add(StoreMachineApply data)
- {
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("BrandId", data.BrandId); //品牌
- Fields.Add("ApplyNo", data.ApplyNo); //申请单号
- Fields.Add("ApplyNum", data.ApplyNum); //申请台数
- Fields.Add("SendNum", data.SendNum); //发货台数
- Fields.Add("UseAmount", data.UseAmount); //使用额度
- Fields.Add("SendMode", data.SendMode); //发货方式
- Fields.Add("ErpCode", data.ErpCode); //快递单号
- Fields.Add("SendSn", data.SendSn); //发货SN数据
- Fields.Add("UserId", data.UserId); //创客
- Fields.Add("SeoTitle", data.SeoTitle);
- Fields.Add("SeoKeyword", data.SeoKeyword);
- Fields.Add("SeoDescription", data.SeoDescription);
- int Id = new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Add("StoreMachineApply", Fields, 0);
- AddSysLog(data.Id.ToString(), "StoreMachineApply", "add");
- opdb.SaveChanges();
- return "success";
- }
- #endregion
- #region 修改分仓机具申请记录
- /// <summary>
- /// 增加或修改分仓机具申请记录信息
- /// </summary>
- /// <returns></returns>
- public IActionResult Edit(string right, int Id = 0)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- StoreMachineApply editData = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
- ViewBag.data = editData;
- Models.WebCMSEntities db = new Models.WebCMSEntities();
- SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Status == 0 && m.UserId == editData.UserId) ?? new SysAdmin();
- ViewBag.UserId = sysAdmin.UserId;
- ViewBag.MakerCode = sysAdmin.MakerCode;
- ViewBag.MakerName = sysAdmin.MakerName;
- ViewBag.UseAmount = editData.UseAmount;
- JsonData SendSnList = new JsonData();
- SendSnList = JsonMapper.ToObject(editData.SendSn);//申请数据
- List<Dictionary<string, object>> KsProductList = new List<Dictionary<string, object>>();
- for (int i = 0; i < SendSnList.Count; i++)
- {
- int BrandId = Convert.ToInt32(SendSnList[i]["BrandId"].ToString());
- int Num = Convert.ToInt32(SendSnList[i]["ApplyNum"].ToString());
- var products = db.KqProducts.Where(m => m.Id == BrandId).ToList();
- foreach (var product in products)
- {
- Dictionary<string, object> item = new Dictionary<string, object>();
- item.Add("BrandId", BrandId); //商品Id
- item.Add("Name", product.Name); //商品名称
- item.Add("Num", Num); //商品数量
- KsProductList.Add(item);
- }
- }
- ViewBag.KsProductList = KsProductList;
- return View();
- }
- #endregion
- #region 修改分仓机具申请记录
- /// <summary>
- /// 增加或修改分仓机具申请记录信息
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public string Edit(StoreMachineApply data)
- {
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("SendSn", data.SendSn); //发货SN数据
- JsonData SendSnList = new JsonData();
- SendSnList = JsonMapper.ToObject(data.SendSn);//申请数据
- int ApplyNum = 0;
- for (int i = 0; i < SendSnList.Count; i++)
- {
- int num = Convert.ToInt32(SendSnList[i]["ApplyNum"].ToString());
- ApplyNum += num;
- }
- Fields.Add("BrandId", data.BrandId); //品牌
- Fields.Add("ApplyNo", data.ApplyNo); //申请单号
- Fields.Add("ApplyNum", ApplyNum); //申请台数
- Fields.Add("SendNum", data.SendNum); //发货台数
- Fields.Add("UseAmount", data.UseAmount); //使用额度
- Fields.Add("SendMode", data.SendMode); //发货方式
- Fields.Add("ErpCode", data.ErpCode); //快递单号
- Fields.Add("UserId", data.UserId); //创客
- Fields.Add("SeoKeyword", data.SeoKeyword);
- Fields.Add("SeoDescription", data.SeoDescription);
- new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, data.Id);
- AddSysLog(data.Id.ToString(), "OpStoreMachineApply", "update");
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 删除分仓机具申请记录信息
- /// <summary>
- /// 删除分仓机具申请记录信息
- /// </summary>
- /// <returns></returns>
- public string Delete(string Id)
- {
- string[] idlist = Id.Split(new char[] { ',' });
- AddSysLog(Id, "StoreMachineApply", "del");
- foreach (string subid in idlist)
- {
- int id = int.Parse(subid);
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("Status", -1);
- new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, id);
- }
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 开启
- /// <summary>
- /// 开启
- /// </summary>
- /// <returns></returns>
- public string Open(string Id)
- {
- string[] idlist = Id.Split(new char[] { ',' });
- AddSysLog(Id, "StoreMachineApply", "open");
- foreach (string subid in idlist)
- {
- int id = int.Parse(subid);
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("Status", 1);
- new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, id);
- }
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 关闭
- /// <summary>
- /// 关闭
- /// </summary>
- /// <returns></returns>
- public string Close(string Id)
- {
- string[] idlist = Id.Split(new char[] { ',' });
- AddSysLog(Id, "StoreMachineApplyOperate", "close");
- foreach (string subid in idlist)
- {
- int id = int.Parse(subid);
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("Status", 2);
- var query = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == id);
- string[] amountlist = query.SeoTitle.Split(',');
- decimal ValidAmount = decimal.Parse(amountlist[0]);
- decimal TotalAmt = decimal.Parse(amountlist[1]);
- decimal ValidForGetAmount = decimal.Parse(amountlist[2]);
- var users = opdb.UserAccount.FirstOrDefault(m => m.Status == 0 && m.UserId == query.UserId) ?? new UserAccount();
- if (users.Id > 0)
- {
- OpAmountItem opAmountItem = new OpAmountItem
- {
- UserId = query.UserId,//创客Id
- OperateType = 0,//操作类型(0 总和 1 增加 2 减少)
- ChangeType = 11,//类别
- Remark = "机具申请驳回",//备注
- UseAmount = query.UseAmount,//变更总额度
- UseValidForGetAmount = ValidForGetAmount,//变更可提现额度
- UseTotalAmt = TotalAmt,//变更未使用额度
- UseValidAmount = ValidAmount,//变更关联分仓额度
- DataType = 3,//来源类型,区分表(1订单,2机具,3申请记录,4购买运营中心,5预扣款 6兑换大盟主 7仓库)
- DataId = query.Id//来源Id,表的主键Id
- };
- RedisDbconn.Instance.AddList("OperateAmountRecordServiceQueue", opAmountItem);
- // var amountRecord = opdb.AmountRecord.Add(new AmountRecord()
- // {
- // CreateDate = DateTime.Now,
- // CreateMan = SysUserName + "-" + SysRealName,
- // SeoDescription = "机具申请驳回",
- // OperateType = 1,//增加
- // BeforeAmount = users.ValidAmount + users.TotalAmt + users.ValidForGetAmount,
- // AfterAmount = users.ValidAmount + users.TotalAmt + users.ValidForGetAmount + query.UseAmount,
- // AfterTotalAmt = users.TotalAmt + TotalAmt,
- // AfterValidForGetAmount = users.ValidForGetAmount + ValidForGetAmount,
- // AfterValidAmount = users.ValidAmount + ValidAmount,
- // UseAmount = query.UseAmount,
- // UserId = query.UserId,
- // ApplyId = query.Id,
- // }).Entity;
- // for (int a = 1; a <= 3; a++)
- // {
- // var UseAmount = 0.00M;
- // var BeforeAmount = 0.00M;
- // var AfterAmount = 0.00M;
- // if (a == 1)
- // {
- // UseAmount = TotalAmt;
- // BeforeAmount = users.TotalAmt + UseAmount;
- // AfterAmount = users.TotalAmt;
- // }
- // if (a == 2)
- // {
- // UseAmount = ValidForGetAmount;
- // BeforeAmount = users.ValidForGetAmount + UseAmount;
- // AfterAmount = users.ValidForGetAmount;
- // }
- // if (a == 3)
- // {
- // UseAmount = ValidAmount;
- // BeforeAmount = users.ValidAmount + UseAmount;
- // AfterAmount = users.ValidAmount;
- // }
- // if (a > 0 && UseAmount > 0)
- // {
- // var amountChangeRecord = opdb.AmountChangeRecord.Add(new OpModels.AmountChangeRecord()
- // {
- // AmountType = a,//1 未使用额度 2 可提现额度 3 关联分仓额度
- // CreateDate = DateTime.Now,
- // Title = "机具申请驳回",
- // UserId = query.UserId, //运营中心Id
- // Operater = SysUserName + "-" + SysRealName,
- // BeforeAmount = BeforeAmount,//使用前剩余额度
- // AfterAmount = AfterAmount,//使用后剩余额度
- // ChangeAmount = UseAmount,//操作金额
- // OperateType = 1,//操作类别
- // }).Entity;
- // }
- // }
- users.ValidAmount += ValidAmount;
- users.TotalAmt += TotalAmt;
- users.ValidForGetAmount += ValidForGetAmount;
- opdb.SaveChanges();
- }
- new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, id);
- }
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 排序
- /// <summary>
- /// 排序
- /// </summary>
- /// <param name="Id"></param>
- public string Sort(int Id, int Sort)
- {
- new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Sort("StoreMachineApply", Sort, Id);
- AddSysLog(Id.ToString(), "StoreMachineApply", "sort");
- return "success";
- }
- #endregion
- #region 导入数据
- /// <summary>
- /// 导入数据
- /// </summary>
- /// <param name="ExcelData"></param>
- public string Import(string ExcelData)
- {
- ExcelData = HttpUtility.UrlDecode(ExcelData);
- JsonData list = JsonMapper.ToObject(ExcelData);
- for (int i = 1; i < list.Count; i++)
- {
- JsonData dr = list[i];
- opdb.StoreMachineApply.Add(new StoreMachineApply()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- });
- db.SaveChanges();
- }
- AddSysLog("0", "OpStoreMachineApply", "Import");
- return "success";
- }
- #endregion
- #region 导出Excel
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <returns></returns>
- public JsonResult ExportExcel(StoreMachineApply data, string BrandIdSelect, string UserIdRealName, string UserIdMakerCode)
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- Fields.Add("CreateDate", "3"); //时间
- Fields.Add("ApplyNo", "1"); //申请单号
- Fields.Add("SendMode", "1"); //发货方式
- string condition = " and Status>-1";
- //品牌
- if (!string.IsNullOrEmpty(BrandIdSelect))
- {
- condition += " and BrandId=" + BrandIdSelect;
- }
- //创客真实姓名
- if (!string.IsNullOrEmpty(UserIdRealName))
- {
- condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
- }
- //创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- Dictionary<string, object> obj = new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).IndexData("StoreMachineApply", Fields, "Id desc", "0", 1, 20000, condition, "BrandId,ApplyNo,ApplyNum,SendNum,UseAmount,SendMode,ErpCode,UserId", false);
- List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
- foreach (Dictionary<string, object> dic in diclist)
- {
- //品牌
- dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
- dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
- //运营中心
- int OpId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
- SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Id == OpId) ?? new SysAdmin();
- dic["MakerName"] = sysAdmin.MakerName;
- dic["MakerCode"] = sysAdmin.MakerCode;
- dic["OpCode"] = sysAdmin.OpCode;
- dic.Remove("OpId");
- }
- Dictionary<string, object> result = new Dictionary<string, object>();
- result.Add("Status", "1");
- result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
- result.Add("Obj", diclist);
- Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
- ReturnFields.Add("BrandId", "品牌");
- ReturnFields.Add("ApplyNo", "申请单号");
- ReturnFields.Add("ApplyNum", "申请台数");
- ReturnFields.Add("SendNum", "发货台数");
- ReturnFields.Add("UseAmount", "使用额度");
- ReturnFields.Add("SendMode", "发货方式");
- ReturnFields.Add("ErpCode", "快递单号");
- ReturnFields.Add("MakerName", "创客真实姓名");
- ReturnFields.Add("MakerName", "创客编号");
- ReturnFields.Add("OpCode", "运营中心编号");
- result.Add("Fields", ReturnFields);
- AddSysLog("0", "OpStoreMachineApply", "ExportExcel");
- return Json(result);
- }
- #endregion
- #region 审核发货
- public IActionResult AuditSend(string right, int Id = 0)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- StoreMachineApply editData = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
- ViewBag.data = editData;
- SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Status == 0 && m.UserId == editData.UserId) ?? new SysAdmin();
- ViewBag.OpCode = sysAdmin.OpCode;
- ViewBag.MakerCode = sysAdmin.MakerCode;
- ViewBag.MakerName = sysAdmin.MakerName;
- return View();
- }
- #endregion
- #region 审核发货
- [HttpPost]
- public string AuditSend(StoreMachineApply data, string ExcelData)
- {
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("ApplyNum", data.ApplyNum); //申请数
- Fields.Add("SendNum", data.ApplyNum); //发货数
- Fields.Add("ErpCode", data.ErpCode); //快递单号
- Fields.Add("SendMode", data.SendMode); //发货方式
- Fields.Add("SeoKeyword", data.SeoKeyword); //申请描述
- Fields.Add("Status", 1);
- AddSysLog(data.Id.ToString(), "StoreMachineApply", "AuditSend");
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- List<SendInfo> sendInfos = new List<SendInfo>();
- List<CheckSendInfo> checksendInfos = new List<CheckSendInfo>();
- StoreMachineApply apply = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == data.Id) ?? new StoreMachineApply();
- string[] amountlist = apply.SeoTitle.Split(',');
- decimal ValidAmount = decimal.Parse(amountlist[0]);
- decimal TotalAmt = decimal.Parse(amountlist[1]);
- decimal ValidForGetAmount = decimal.Parse(amountlist[2]);
- JsonData ApplyList = JsonMapper.ToObject(apply.SendSn);
- decimal ApplyAmount = 0;
- decimal Amount = 0;
- for (int i = 0; i < ApplyList.Count; i++)
- {
- int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
- int BrandIds = Convert.ToInt32(ApplyList[i]["BrandId"].ToString());
- //自动匹配品牌
- var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds);
- if (brandInfo.Name.Contains("电签"))
- {
- ApplyAmount += num * 100;
- }
- if (brandInfo.Name.Contains("大POS"))
- {
- ApplyAmount += num * 150;
- }
- }
- Amount = apply.UseAmount - ApplyAmount;
- Models.StoreHouse tostore = new Models.StoreHouse();
- Models.StoreHouse fromstore = new Models.StoreHouse();
- var BrandId = 0;
- var FromStoreId = 0;
- string error = "";
- if (string.IsNullOrEmpty(ExcelData))
- {
- return "Warning|" + "请选择要导入的数据";
- }
- ExcelData = HttpUtility.UrlDecode(ExcelData);
- JsonData list = JsonMapper.ToObject(ExcelData);
- //判断各品牌发货数量是否符合
- if (list.Count - 1 > apply.ApplyNum)
- {
- return "Warning|" + "机具发货数量过多!";
- }
- if (list.Count - 1 < apply.ApplyNum)
- {
- return "Warning|" + "机具发货数量不足!";
- }
- for (int index = 1; index < list.Count; index++)
- {
- JsonData dr = list[index];
- string itemJson = dr.ToJson();
- string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
- string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
- string BatchNo = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
- string OutNote = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
- BrandId = Convert.ToInt32(Brand);
- var kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == BrandId) ?? new Models.KqProducts();
- FromStoreId = kqProducts.MainStoreId;
- CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandId);
- if (items == null)
- {
- CheckSendInfo rows = new CheckSendInfo()
- {
- BrandId = BrandId,
- Num = 1
- };
- checksendInfos.Add(rows);
- }
- else
- {
- items.Num += 1;
- }
- }
- for (int i = 0; i < ApplyList.Count; i++)
- {
- int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
- int BrandIds = Convert.ToInt32(ApplyList[i]["BrandId"].ToString());
- var kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds) ?? new Models.KqProducts();
- FromStoreId = kqProducts.MainStoreId;
- var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds);
- CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandIds) ?? new CheckSendInfo();
- if (items.Num > num)
- {
- return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量过多!";
- }
- if (items.Num < num)
- {
- return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量不足!";
- }
- }
- List<string> PosSnList = new List<string>();
- for (int index = 1; index < list.Count; index++)
- {
- JsonData dr = list[index];
- string itemJson = dr.ToJson();
- string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
- string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
- BrandId = Convert.ToInt32(Brand);
- var kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == BrandId) ?? new Models.KqProducts();
- FromStoreId = kqProducts.MainStoreId;
- Models.MachineForSnNo posInfo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new Models.MachineForSnNo();
- var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posInfo.SnId && m.StoreId == FromStoreId && m.UserId == 0 && m.BuyUserId == 0 && m.PreUserId == 0) ?? new Models.PosMachinesTwo();
- if (pos.BindingState == 1 || pos.ActivationState == 1)
- {
- error += "以下操作失败" + SnNo + ',' + "该机具已绑定或已激活" + '\n';
- }
- if (posInfo.SnId > 0)
- {
- if (pos.Id > 0)
- {
- if (pos.BrandId != BrandId)
- {
- error += "以下操作失败" + SnNo + ',' + "该机具品牌填写错误" + '\n';
- }
- }
- if (PosSnList.Contains(SnNo))
- {
- error += "以下操作失败" + SnNo + ',' + "该机具重复发货" + '\n';
- }
- PosSnList.Add(SnNo);
- }
- else
- {
- error += "以下操作失败" + SnNo + ',' + "未找到该机具或者该机具不符合发货条件" + '\n';
- }
- }
- if (!string.IsNullOrEmpty(error))
- {
- return "Warning|" + error;
- }
- Dictionary<string, int> storeData = new Dictionary<string, int>();
- Dictionary<string, int> toStoreData = new Dictionary<string, int>();
- var amount = 0;
- for (int index = 1; index < list.Count; index++)
- {
- JsonData dr = list[index];
- string itemJson = dr.ToJson();
- string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
- string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
- string BatchNo = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
- string OutNote = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
- BrandId = Convert.ToInt32(Brand);
- var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandId);
- if (brandInfo != null)
- {
- if (brandInfo.Name.Contains("电签"))
- {
- amount = 100;
- }
- if (brandInfo.Name.Contains("大POS"))
- {
- amount = 150;
- }
- }
- var kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == BrandId) ?? new Models.KqProducts();
- FromStoreId = kqProducts.MainStoreId;
- tostore = db.StoreHouse.FirstOrDefault(m => m.Sort > 0 && m.UserId == apply.UserId && m.BrandId == BrandId.ToString() && m.Status == 1);
- SendInfo item = sendInfos.FirstOrDefault(m => m.FromStoreId == FromStoreId && m.ToStoreId == tostore.Id && m.BrandId == BrandId);
- if (item == null)
- {
- SendInfo row = new SendInfo()
- {
- FromStoreId = FromStoreId,
- ToStoreId = tostore.Id,
- BrandId = BrandId,
- Num = 1
- };
- sendInfos.Add(row);
- }
- else
- {
- item.Num += 1;
- }
- apply.SeoDescription = function.CheckString(SnNo) + ',';
- fromstore = db.StoreHouse.FirstOrDefault(m => m.Id == FromStoreId);
- Models.MachineForSnNo machinefor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new Models.MachineForSnNo();
- Models.PosMachinesTwo machine = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machinefor.SnId && m.BuyUserId == 0 && m.UserId == 0) ?? new Models.PosMachinesTwo();
- if (machine.Id > 0)
- {
- if (machine.BrandId != BrandId)
- {
- return machine.PosSn + "与表格里填写的品牌不一致";
- }
- else
- {
- Models.StoreStockChange stockchange = db.StoreStockChange.Add(new Models.StoreStockChange()
- {
- CreateDate = DateTime.Now,
- CreateMan = SysUserName,
- Sort = data.Id,//库存变动关联申请记录表
- StoreId = FromStoreId, //出货仓库
- BrandId = BrandId, //产品类型
- ProductName = RelationClass.GetKqProductBrandInfo(BrandId), //产品名称
- BizBatchNo = BatchNo, //业务批次号
- TransType = 1, //交易类型
- SnNo = SnNo, //SN编号
- StockOpDirect = 1, //库存操作方向
- SnStatus = 1, //SN状态
- DeviceVendor = machine.DeviceName, //设备厂商
- DeviceModel = machine.DeviceKind, //设备型号
- DeviceType = machine.DeviceType, //设备类型
- FromUserId = fromstore.UserId, //出货人
- FromDate = DateTime.Now, //出库时间
- FromRemark = OutNote, //出库备注
- ToUserId = tostore.UserId, //收货人
- ToStoreId = fromstore.Id, //退货收货仓库
- SourceStoreId = machine.SourceStoreId, //源仓库编号
- BrandType = machine.DeviceType, //品牌类型
- }).Entity;
- string ChangeNo = "CS";
- int StoreStockChangeId = stockchange.Id;
- string StoreStockChangeIdString = StoreStockChangeId.ToString();
- for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
- {
- StoreStockChangeIdString = "0" + StoreStockChangeIdString;
- }
- ChangeNo += StoreStockChangeIdString;
- stockchange.ChangeNo = ChangeNo; //交易流水编号
- machine.StoreId = tostore.Id;
- db.StoreChangeHistory.Add(new Models.StoreChangeHistory()
- {
- CreateDate = DateTime.Now,
- UserId = fromstore.UserId, //创客
- BrandId = BrandId, //产品类型
- ChangeRecordNo = ChangeNo, //变更记录单号
- BizBatchNo = BatchNo, //业务批次号
- TransType = 1, //交易类型
- SnNo = SnNo, //SN编号
- SnType = machine.PosSnType, //SN机具类型
- StockOpDirect = 1, //库存操作方向
- DeviceVendor = machine.DeviceName, //设备厂商
- DeviceModel = machine.DeviceKind, //设备型号
- DeviceType = machine.DeviceType, //设备类型
- FromUserId = fromstore.UserId, //出货创客
- FromDate = DateTime.Now, //出库时间
- FromRemark = OutNote, //出库备注
- SourceStoreId = machine.SourceStoreId, //源仓库
- StoreId = fromstore.Id, //仓库
- ToUserId = tostore.UserId,//收货创客
- });
- //修改机具所属仓库
- machine.StoreId = tostore.Id;
- machine.UpdateDate = DateTime.Now;
- //添加机具所属运营中心
- machine.OpId = tostore.UserId;
- if (ValidAmount >= amount)
- {
- ValidAmount -= amount;
- machine.OpReserve3 = amount;
- machine.OpReserve1 = 0;
- machine.OpReserve2 = 0;
- }
- else
- {
- if (TotalAmt >= amount)
- {
- TotalAmt -= amount - ValidAmount;
- machine.OpReserve3 = ValidAmount;
- machine.OpReserve1 = amount - ValidAmount;
- machine.OpReserve2 = 0;
- }
- else
- {
- if (ValidForGetAmount >= amount)
- {
- ValidForGetAmount -= amount - TotalAmt;
- machine.OpReserve3 = 0;
- machine.OpReserve1 = TotalAmt;
- machine.OpReserve2 = amount - TotalAmt;
- }
- }
- }
- db.SaveChanges();
- }
- }
- else
- {
- return "总仓无该机具";
- }
- }
- foreach (var item in sendInfos)
- {
- //出货仓库数据调整
- Models.StoreHouse storeCH = db.StoreHouse.FirstOrDefault(m => m.Id == item.FromStoreId) ?? new Models.StoreHouse();
- Models.StoreBalance balance = db.StoreBalance.Add(new Models.StoreBalance()
- {
- CreateDate = DateTime.Now,
- StoreId = storeCH.Id, //仓库
- TransType = 1, //交易类型
- BrandId = BrandId, //产品类型
- OpStoreNum = item.Num, //操作库存数
- OpSymbol = "-", //操作符
- BeforeTotalNum = storeCH.TotalNum, //操作前总库存数
- AfterTotalNum = storeCH.TotalNum - item.Num, //操作后总库存数
- BeforeLaveNum = storeCH.LaveNum, //操作前剩余库存数
- AfterLaveNum = storeCH.LaveNum - item.Num, //操作后剩余库存数
- BeforeOutNum = storeCH.OutNum, //操作前出库数
- AfterOutNum = storeCH.OutNum + item.Num, //操作后出库数
- }).Entity;
- string ChangeNo1 = "CS";
- int StoreStockChangeId1 = balance.Id;
- string StoreStockChangeId1String = StoreStockChangeId1.ToString();
- for (int i = 0; i < 18 - StoreStockChangeId1.ToString().Length; i++)
- {
- StoreStockChangeId1String = "0" + StoreStockChangeId1String;
- }
- ChangeNo1 += StoreStockChangeId1String;
- balance.TransRecordNo = ChangeNo1; //交易流水编号
- storeCH.LaveNum -= item.Num;
- storeCH.OutNum += item.Num;
- //收货仓库数据调整
- Models.StoreHouse storeSH = db.StoreHouse.FirstOrDefault(m => m.Id == item.ToStoreId) ?? new Models.StoreHouse();
- balance = db.StoreBalance.Add(new Models.StoreBalance()
- {
- CreateDate = DateTime.Now,
- StoreId = storeSH.Id, //仓库
- TransType = 0, //交易类型
- BrandId = BrandId, //产品类型
- OpStoreNum = item.Num, //操作库存数
- OpSymbol = "+", //操作符
- BeforeTotalNum = storeSH.TotalNum, //操作前总库存数
- AfterTotalNum = storeSH.TotalNum + item.Num, //操作后总库存数
- BeforeLaveNum = storeSH.LaveNum, //操作前剩余库存数
- AfterLaveNum = storeSH.LaveNum + item.Num, //操作后剩余库存数
- BeforeOutNum = storeSH.OutNum, //操作前出库数
- AfterOutNum = storeSH.OutNum, //操作后出库数
- }).Entity;
- string ChangeNo2 = "CS";
- int StoreStockChangeId2 = balance.Id;
- string StoreStockChangeId2String = StoreStockChangeId2.ToString();
- for (int i = 0; i < 18 - StoreStockChangeId2.ToString().Length; i++)
- {
- StoreStockChangeId2String = "0" + StoreStockChangeId2String;
- }
- ChangeNo2 += StoreStockChangeId2String;
- balance.TransRecordNo = ChangeNo2; //交易流水编号
- storeSH.TotalNum += item.Num;
- storeSH.LaveNum += item.Num;
- var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.Status == 0 && m.UserId == storeSH.UserId) ?? new SysAdmin();
- if (sysAdmin.Id > 0)
- {
- sysAdmin.TotalMachineCount += item.Num;
- opdb.SaveChanges();
- }
- }
- apply.SeoTitle = SysUserName + '-' + SysRealName;//添加操作人信息
- apply.UseAmount = ApplyAmount;
- db.SaveChanges();
- new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, data.Id);
- string SendData = "{\"Kind\":\"2\",\"Data\":{\"UserId\":\"" + apply.UserId + "\",\"Amount\":\"" + Amount + "\",\"OperateType\":\"1\"}}";
- RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
- return "success";
- }
- #endregion
- //发货信息实体类
- private class SendInfo
- {
- public int FromStoreId { get; set; }
- public int ToStoreId { get; set; }
- public int BrandId { get; set; }
- public int Num { get; set; }
- }
- //检查发货信息实体类
- private class CheckSendInfo
- {
- public int BrandId { get; set; }
- public int Num { get; set; }
- }
- }
- }
|