12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289 |
- /*
- * 创客订单
- */
- using System;
- using System.Web;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Data;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using MySystem.KxsMainModels;
- using Library;
- using LitJson;
- using MySystemLib;
- using NPOI.HSSF.UserModel;
- using NPOI.XSSF.UserModel;
- using NPOI.SS.UserModel;
- using NPOI.HSSF.Util;
- namespace MySystem.Areas.Admin.Controllers
- {
- [Area("Admin")]
- [Route("Admin/[controller]/[action]")]
- public class OrdersController : BaseController
- {
- public OrdersController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- OtherMySqlConn.connstr = ConfigurationManager.AppSettings["KxsSqlConnStr"].ToString();
- }
- #region 创客订单列表
- /// <summary>
- /// 根据条件查询创客订单列表
- /// </summary>
- /// <returns></returns>
- public IActionResult Index(Orders data, string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 根据条件查询创客订单列表
- /// <summary>
- /// 创客订单列表
- /// </summary>
- /// <returns></returns>
- public JsonResult IndexData(Orders data, string OrderNo, string TradeNo, string RealName, string Mobile, string StoreContact, string ErpCode, string SnNos, string PayDateData, string CreateDateData, string SendDateData, string UserIdMakerCode, string UserIdRealName, string PayModeSelect, string StoreIdStoreNo, string StoreIdStoreName, string RefundStatusSelect, string DeliveryTypeSelect, string SendStatusSelect, string ProductIdSelect, string StoreTypeSelect, string StoreUserIdMakerCode, string StoreUserIdRealName, string PayStatusSelect, int page = 1, int limit = 30)
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- Fields.Add("OrderNo", "1"); //订单号
- Fields.Add("RealName", "1"); //姓名
- Fields.Add("Mobile", "1"); //手机号
- Fields.Add("ErpCode", "1"); //运单号
- Fields.Add("TradeNo", "1"); //支付交易号
- Fields.Add("StoreContact", "1"); //仓库联系人
- Fields.Add("SnNos", "2"); //SN编号
- Fields.Add("TopUserId", "0");
- string condition = " and Status>-1 and ProductId=52";
- //平台订单号
- if (!string.IsNullOrEmpty(OrderNo))
- {
- condition += " and OrderNo like '" + OrderNo + "'";
- }
- //渠道订单号
- if (!string.IsNullOrEmpty(TradeNo))
- {
- condition += " and TradeNo=" + TradeNo;
- }
- //收件人姓名
- if (!string.IsNullOrEmpty(RealName))
- {
- condition += " and RealName=" + RealName;
- }
- //收件人电话
- if (!string.IsNullOrEmpty(Mobile))
- {
- condition += " and Mobile=" + Mobile;
- }
- //创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- //创客真实姓名
- if (!string.IsNullOrEmpty(UserIdRealName))
- {
- condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
- }
- //支付方式
- if (!string.IsNullOrEmpty(PayModeSelect))
- {
- condition += " and PayMode=" + PayModeSelect;
- }
- //仓库编号
- if (!string.IsNullOrEmpty(StoreIdStoreNo))
- {
- condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
- }
- //仓库名称
- if (!string.IsNullOrEmpty(StoreIdStoreName))
- {
- condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
- }
- //仓库联系人
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- //仓库归属创客编号
- if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
- {
- condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
- }
- //仓库归属创客真实姓名
- if (!string.IsNullOrEmpty(StoreUserIdRealName))
- {
- condition += " and StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
- }
- //快递单号
- if (!string.IsNullOrEmpty(ErpCode))
- {
- condition += " and ErpCode=" + ErpCode;
- }
- //SN
- if (!string.IsNullOrEmpty(SnNos))
- {
- condition += " and SnNos=" + SnNos;
- }
- //支付时间
- if (!string.IsNullOrEmpty(PayDateData))
- {
- string[] datelist = PayDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- string start = datelist[0];
- string end = datelist[1];
- condition += " and PayDate>='" + start + " 00:00:00' and PayDate<='" + end + " 23:59:59'";
- }
- //下单时间
- 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(SendDateData))
- {
- string[] datelist = SendDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- string start = datelist[0];
- string end = datelist[1];
- condition += " and SendDate>='" + start + " 00:00:00' and SendDate<='" + end + " 23:59:59'";
- }
- //退款状态
- if (!string.IsNullOrEmpty(RefundStatusSelect))
- {
- condition += " and RefundStatus=" + RefundStatusSelect;
- }
- //提货类型
- if (!string.IsNullOrEmpty(DeliveryTypeSelect))
- {
- condition += " and DeliveryType=" + DeliveryTypeSelect;
- }
- //发货状态
- if (!string.IsNullOrEmpty(SendStatusSelect))
- {
- condition += " and SendStatus=" + SendStatusSelect;
- }
- //商品类型名称
- if (!string.IsNullOrEmpty(ProductIdSelect))
- {
- condition += " and Id in (select OrderId from OrderProduct where ProductId=" + ProductIdSelect + ")";//表数据量过大时不适用
- }
- //仓库类型
- if (!string.IsNullOrEmpty(StoreTypeSelect))
- {
- condition += " and StoreType=" + StoreTypeSelect;
- }
- //支付状态
- if (!string.IsNullOrEmpty(PayStatusSelect))
- {
- condition += " and PayStatus=" + PayStatusSelect;
- }
- Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).IndexData("Orders", 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["OrderNo"] = dic["OrderNo"].ToString() + "<br />" + dic["TradeNo"].ToString();
- dic["StoreContact"] = dic["StoreContact"].ToString() + "<br />" + dic["StoreContactMobile"].ToString();
- dic["Address"] = dic["Areas"].ToString() + dic["Address"].ToString();
- dic["RecieveInfo"] = dic["RealName"].ToString() + "<br />" + dic["Mobile"].ToString();
- dic["ErpInfo"] = dic["ErpCode"].ToString() + "<br />" + dic["ErpName"].ToString();
- //创客
- int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
- Users userid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- dic["UserInfo"] = userid_Users.MakerCode + "<br />" + userid_Users.RealName;
- dic.Remove("UserId");
- //物流名称
- dic["ErpName"] = RelationClass.GetErpCompanysInfo(dic["ErpName"].ToString());
- //支付方式
- int PayMode = int.Parse(dic["PayMode"].ToString());
- if (PayMode == 1) dic["PayMode"] = "支付宝";
- if (PayMode == 2) dic["PayMode"] = "微信";
- if (PayMode == 3) dic["PayMode"] = "账户余额";
- if (PayMode == 0) dic["PayMode"] = "";
- //仓库
- int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
- StoreHouse storeid_StoreHouse = kxsdb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
- //仓库类型
- int StoreType = int.Parse(dic["StoreType"].ToString());
- if (StoreType == 0) dic["StoreType"] = "总仓";
- if (StoreType == 1) dic["StoreType"] = "分仓";
- dic["Store"] = storeid_StoreHouse.StoreNo + "<br />" + dic["StoreType"].ToString();
- dic.Remove("StoreId");
- //退款状态
- int RefundStatus = int.Parse(dic["RefundStatus"].ToString());
- if (RefundStatus == 0) dic["RefundStatusName"] = "未退款";
- if (RefundStatus == 1) dic["RefundStatusName"] = "已退款";
- //提货类型
- int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
- if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
- if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
- if (DeliveryType == 0) dic["DeliveryType"] = "";
- //发货状态
- int SendStatus = int.Parse(dic["SendStatus"].ToString());
- if (SendStatus == 0) dic["SendStatusName"] = "未发货";
- if (SendStatus == 1) dic["SendStatusName"] = "已发货";
- if (SendStatus == 2) dic["SendStatusName"] = "已退货";
- if (SendStatus == 0)
- {
- dic["SendInfo"] = dic["SendStatus"].ToString();
- }
- else
- {
- dic["SendInfo"] = dic["SendStatusName"].ToString() + "<br />" + dic["SendDate"].ToString();
- }
- //商品名称
- dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
- //商品名称
- int Id = int.Parse(function.CheckInt(dic["Id"].ToString()));
- OrderProduct orderProducts = kxsdb.OrderProduct.FirstOrDefault(m => m.OrderId == Id) ?? new OrderProduct();
- dic["ProductName"] = orderProducts.ProductName;
- //仓库归属创客
- int StoreUserId = int.Parse(function.CheckInt(dic["StoreUserId"].ToString()));
- Users storeuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
- dic["StoreFrom"] = storeuserid_Users.MakerCode + "<br />" + storeid_StoreHouse.StoreName;
- dic.Remove("StoreUserId");
- //顶级创客
- int TopUserId = int.Parse(function.CheckInt(dic["TopUserId"].ToString()));
- Users topuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
- dic["TopUserInfo"] = topuserid_Users.MakerCode + "<br />" + topuserid_Users.RealName;
- dic.Remove("TopUserId");
- //支付状态
- int PayStatus = int.Parse(dic["PayStatus"].ToString());
- if (PayStatus == 0) dic["PayStatus"] = "未支付";
- if (PayStatus == 1) dic["PayStatus"] = "支付成功";
- if (PayStatus == 2) dic["PayStatus"] = "支付失败";
- if (PayStatus == 3) dic["PayStatus"] = "支付锁定中";
- if (PayStatus == 4) dic["PayStatus"] = "支付处理中";
- }
- Dictionary<string, object> other = new Dictionary<string, object>();
- string SuccessAmount = "0.00";//支付成功总金额
- string FailAmount = "0.00";//支付失败总金额
- DataTable dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
- if (dt.Rows.Count > 0)
- {
- SuccessAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
- }
- dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=2" + condition);
- if (dt.Rows.Count > 0)
- {
- FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
- }
- other.Add("SuccessAmount", SuccessAmount);
- other.Add("FailAmount", FailAmount);
- obj.Add("other", other);
- return Json(obj);
- }
- public JsonResult IndexDatas(string UserIdMakerCode, string UserIdRealName, string PayModeSelect, string StoreIdStoreNo, string StoreIdStoreName, string RefundStatusSelect, string DeliveryTypeSelect, string SendStatusSelect, string ProductIdSelect, string StoreTypeSelect, string StoreUserIdMakerCode, string StoreUserIdRealName, string PayStatusSelect, int page = 1, int limit = 30)
- {
- string condition = " and Status>-1";
- //创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- //创客真实姓名
- if (!string.IsNullOrEmpty(UserIdRealName))
- {
- condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
- }
- //支付方式
- if (!string.IsNullOrEmpty(PayModeSelect))
- {
- condition += " and PayMode=" + PayModeSelect;
- }
- //仓库编号
- if (!string.IsNullOrEmpty(StoreIdStoreNo))
- {
- condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
- }
- //仓库名称
- if (!string.IsNullOrEmpty(StoreIdStoreName))
- {
- condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
- }
- //退款状态
- if (!string.IsNullOrEmpty(RefundStatusSelect))
- {
- condition += " and RefundStatus=" + RefundStatusSelect;
- }
- //提货类型
- if (!string.IsNullOrEmpty(DeliveryTypeSelect))
- {
- condition += " and DeliveryType=" + DeliveryTypeSelect;
- }
- //发货状态
- if (!string.IsNullOrEmpty(SendStatusSelect))
- {
- condition += " and SendStatus=" + SendStatusSelect;
- }
- //商品名称
- if (!string.IsNullOrEmpty(ProductIdSelect))
- {
- condition += " and ProductId=" + ProductIdSelect;
- }
- //仓库类型
- if (!string.IsNullOrEmpty(StoreTypeSelect))
- {
- condition += " and StoreType=" + StoreTypeSelect;
- }
- //仓库归属创客编号
- if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
- {
- condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
- }
- //仓库归属创客真实姓名
- if (!string.IsNullOrEmpty(StoreUserIdRealName))
- {
- condition += " and StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
- }
- //支付状态
- if (!string.IsNullOrEmpty(PayStatusSelect))
- {
- condition += " and PayStatus=" + PayStatusSelect;
- }
- List<Dictionary<string, object>> other = new List<Dictionary<string, object>>();
- Dictionary<string, object> obj = new Dictionary<string, object>();
- DataTable dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=0" + condition);
- return null;
- }
- #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(Orders data)
- {
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("RealName", data.RealName); //姓名
- Fields.Add("ErpName", data.ErpName); //物流名称
- Fields.Add("ErpCode", data.ErpCode); //运单号
- Fields.Add("StoreId", data.StoreId); //仓库
- Fields.Add("SnNos", data.SnNos); //SN编号
- Fields.Add("SeoTitle", data.SeoTitle);
- Fields.Add("SeoKeyword", data.SeoKeyword);
- Fields.Add("SeoDescription", data.SeoDescription);
- int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Add("Orders", Fields, 0);
- AddSysLog(data.Id.ToString(), "Orders", "add");
- kxsdb.SaveChanges();
- return "success";
- }
- #endregion
- #region 修改创客订单
- /// <summary>
- /// 增加或修改创客订单信息
- /// </summary>
- /// <returns></returns>
- public IActionResult Edit(string right, int Id = 0)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- Orders editData = kxsdb.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
- ViewBag.data = editData;
- return View();
- }
- #endregion
- #region 修改创客订单
- /// <summary>
- /// 增加或修改创客订单信息
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public string Edit(Orders data)
- {
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("RealName", data.RealName); //姓名
- Fields.Add("ErpName", data.ErpName); //物流名称
- Fields.Add("ErpCode", data.ErpCode); //运单号
- Fields.Add("StoreId", data.StoreId); //仓库
- Fields.Add("SnNos", data.SnNos); //SN编号
- Fields.Add("SeoTitle", data.SeoTitle);
- Fields.Add("SeoKeyword", data.SeoKeyword);
- Fields.Add("SeoDescription", data.SeoDescription);
- new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Edit("Orders", Fields, data.Id);
- AddSysLog(data.Id.ToString(), "Orders", "update");
- kxsdb.SaveChanges();
- return "success";
- }
- #endregion
- #region 发货
- public IActionResult Send(string right, int Id = 0)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- Orders editData = kxsdb.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
- ViewBag.data = editData;
- Users user = kxsdb.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
- ViewBag.MakerCode = user.MakerCode;
- ViewBag.RealName = user.RealName;
- StoreHouse store = kxsdb.StoreHouse.FirstOrDefault(m => m.Id == editData.StoreId) ?? new StoreHouse();
- ViewBag.StoreName = store.StoreName;
- List<OrderProduct> products = kxsdb.OrderProduct.Where(m => m.OrderId == editData.Id).ToList();
- ViewBag.products = products;
- return View();
- }
- #endregion
- #region 发货
- [HttpPost]
- public string Send(Orders data, string IdList, string StoreIdList, string SnNosList)
- {
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("ErpName", data.ErpName); //物流名称
- Fields.Add("ErpCode", data.ErpCode); //运单号
- Fields.Add("SnNos", SnNosList); //SN编号
- Fields.Add("SendStatus", 1); //发货状态
- Fields.Add("SendDate", DateTime.Now); //发货时间
- string[] Ids = IdList.TrimEnd('#').Split('#');
- string[] StoreIds = StoreIdList.TrimEnd('#').Split('#');
- string[] SnNoss = SnNosList.TrimEnd('\n').Split('\n');
- string err = "";
- for (int i = 0; i < Ids.Length; i++)
- {
- string SnNos = SnNoss[i];
- bool check = db.PosMachinesTwo.Any(m => m.PosSn == SnNos);
- if(!check)
- {
- err += SnNos + "不存在\n";
- }
- }
- if(!string.IsNullOrEmpty(err))
- {
- return err;
- }
- int StoreId = 1;
- if(StoreIds.Length > 0) StoreId = int.Parse(StoreIds[0]);
- Fields.Add("StoreId", StoreId);
- new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Edit("Orders", Fields, data.Id);
- PublicFunction.StatUserMachineData(data.UserId, 0, SnNoss.Length);
- PublicFunction.SendRecord(db, 0, data.UserId, StoreId, SnNoss);
- AddSysLog(data.Id.ToString(), "Orders", "Send");
- kxsdb.SaveChanges();
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 退货
- public IActionResult Return(string right, int Id = 0)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- Orders editData = kxsdb.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
- ViewBag.data = editData;
- return View();
- }
- #endregion
- #region 退货
- [HttpPost]
- public string Return(Orders data)
- {
- AddSysLog(data.Id.ToString(), "Orders", "Return");
- Orders order = kxsdb.Orders.FirstOrDefault(m => m.Id == data.Id);
- if (order != null)
- {
- // TODO: 调用支付接口退款,需要测试
- // PublicAccountSet set = new AlipayFunction(_accessor.HttpContext).SetData();
- // string result = new Alipay.AlipayPublicClass(_accessor.HttpContext).Refund(set.AlipayAppId, set.AlipayPrivateKey, set.AlipayPublicKey, order.OrderNo, order.TotalPrice);
- // if (result.StartsWith("success"))
- // {
- if (order.PayStatus > 0)
- {
- return "已支付订单不可退货";
- }
- else
- {
- order.RefundActAmount = data.RefundActAmount;
- order.RefundReason = data.RefundReason;
- order.RefundStatus = 1;
- kxsdb.SaveChanges();
- return "success";
- }
- // }
- // else
- // {
- // return result.Split('|')[1];
- // }
- }
- return "退货失败";
- }
- #endregion
- #region 订单详情
- public IActionResult Detail(string right, int Id = 0)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- Orders editData = kxsdb.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
- ViewBag.data = editData;
- Users user = kxsdb.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
- ViewBag.MakerCode = user.MakerCode;
- ViewBag.RealName = user.RealName;
- //支付状态
- int PayStatus = editData.PayStatus;
- if (PayStatus == 0) ViewBag.PayStatus = "未支付";
- if (PayStatus == 1) ViewBag.PayStatus = "支付成功";
- if (PayStatus == 2) ViewBag.PayStatus = "支付失败";
- if (PayStatus == 3) ViewBag.PayStatus = "支付锁定中";
- if (PayStatus == 4) ViewBag.PayStatus = "支付处理中";
- //支付方式
- int PayMode = editData.PayMode;
- if (PayMode == 1)
- {
- ViewBag.PayMode = "支付宝支付";
- ViewBag.PayModeCode = "Alipay";
- }
- if (PayMode == 2)
- {
- ViewBag.PayMode = "微信支付";
- ViewBag.PayModeCode = "WeChat";
- }
- if (PayMode == 3)
- {
- ViewBag.PayMode = "账户余额支付";
- ViewBag.PayModeCode = "AccBalancePay";
- }
- //发货状态
- int SendStatus = editData.SendStatus;
- if (SendStatus == 0) ViewBag.SendStatus = "未发货";
- if (SendStatus == 1) ViewBag.SendStatus = "已发货";
- if (SendStatus == 2) ViewBag.SendStatus = "已退货";
- //提货类型
- int DeliveryType = editData.DeliveryType;
- if (DeliveryType == 1) ViewBag.DeliveryType = "邮寄到付";
- if (DeliveryType == 2) ViewBag.DeliveryType = "上门自提";
- List<OrderProduct> products = kxsdb.OrderProduct.Where(m => m.OrderId == editData.Id).ToList();
- List<Dictionary<string, object>> ProductList = new List<Dictionary<string, object>>();
- foreach (OrderProduct product in products)
- {
- Dictionary<string, object> item = new Dictionary<string, object>();
- item.Add("ProductCode", product.ProductCode); //商品编号
- item.Add("ProductName", product.ProductName); //商品名称
- item.Add("ProductCount", product.ProductCount); //商品数量
- item.Add("ProductPrice", product.ProductPrice); //商品单价
- item.Add("SeoKeyword", product.SeoKeyword); //商品简介
- item.Add("SeoDescription", product.SeoDescription); //备注
- item.Add("ProductPhoto", SourceHost + product.ProductPhoto); //商品小图
- item.Add("NormDetail", product.NormDetail); //商品规格
- ProductList.Add(item);
- }
- ViewBag.ProductList = ProductList;
- return View();
- }
- #endregion
- #region 删除创客订单信息
- /// <summary>
- /// 删除创客订单信息
- /// </summary>
- /// <returns></returns>
- public string Delete(string Id)
- {
- string[] idlist = Id.Split(new char[] { ',' });
- AddSysLog(Id, "Orders", "del");
- foreach (string subid in idlist)
- {
- int id = int.Parse(subid);
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("Status", -1);
- new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Edit("Orders", Fields, id);
- }
- kxsdb.SaveChanges();
- return "success";
- }
- #endregion
- #region 开启
- /// <summary>
- /// 开启
- /// </summary>
- /// <returns></returns>
- public string Open(string Id)
- {
- string[] idlist = Id.Split(new char[] { ',' });
- AddSysLog(Id, "Orders", "open");
- foreach (string subid in idlist)
- {
- int id = int.Parse(subid);
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("Status", 1);
- new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Edit("Orders", Fields, id);
- }
- kxsdb.SaveChanges();
- return "success";
- }
- #endregion
- #region 关闭
- /// <summary>
- /// 关闭
- /// </summary>
- /// <returns></returns>
- public string Close(string Id)
- {
- string[] idlist = Id.Split(new char[] { ',' });
- AddSysLog(Id, "Orders", "close");
- foreach (string subid in idlist)
- {
- int id = int.Parse(subid);
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("Status", 0);
- new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Edit("Orders", Fields, id);
- }
- kxsdb.SaveChanges();
- return "success";
- }
- #endregion
- #region 排序
- /// <summary>
- /// 排序
- /// </summary>
- /// <param name="Id"></param>
- public string Sort(int Id, int Sort)
- {
- new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Sort("Orders", Sort, Id);
- AddSysLog(Id.ToString(), "Orders", "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];
- kxsdb.Orders.Add(new Orders()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- });
- kxsdb.SaveChanges();
- }
- AddSysLog("0", "Orders", "Import");
- return "success";
- }
- #endregion
- #region 导出Excel
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <returns></returns>
- public string ExportExcel(Orders data, string UserIdMakerCode, string UserIdRealName, string PayModeSelect, string StoreIdStoreNo, string StoreIdStoreName, string RefundStatusSelect, string DeliveryTypeSelect, string SendStatusSelect, string ProductIdSelect, string StoreTypeSelect, string StoreUserIdMakerCode, string StoreUserIdRealName, string PayStatusSelect, string RedisKey = "ExportKey")
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- Fields.Add("CreateDate", "3"); //时间
- Fields.Add("OrderNo", "1"); //订单号
- Fields.Add("RealName", "1"); //姓名
- Fields.Add("Mobile", "1"); //手机号
- Fields.Add("ErpCode", "1"); //运单号
- Fields.Add("SendDate", "3"); //发货时间
- Fields.Add("TradeNo", "1"); //支付交易号
- Fields.Add("StoreContact", "1"); //仓库联系人
- Fields.Add("SnNos", "2"); //SN编号
- Fields.Add("TopUserId", "0");
- string condition = " and Status>-1 and ProductId=52";
- //创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- //创客真实姓名
- if (!string.IsNullOrEmpty(UserIdRealName))
- {
- condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
- }
- //支付方式
- if (!string.IsNullOrEmpty(PayModeSelect))
- {
- condition += " and PayMode=" + PayModeSelect;
- }
- //仓库编号
- if (!string.IsNullOrEmpty(StoreIdStoreNo))
- {
- condition += " and StoreId in (select StoreId from StoreHouseForStoreNo where StoreNo='" + StoreIdStoreNo + "')";
- }
- //仓库名称
- if (!string.IsNullOrEmpty(StoreIdStoreName))
- {
- condition += " and StoreId in (select StoreId from StoreHouseForStoreName where StoreName='" + StoreIdStoreName + "')";
- }
- //退款状态
- if (!string.IsNullOrEmpty(RefundStatusSelect))
- {
- condition += " and RefundStatus=" + RefundStatusSelect;
- }
- //提货类型
- if (!string.IsNullOrEmpty(DeliveryTypeSelect))
- {
- condition += " and DeliveryType=" + DeliveryTypeSelect;
- }
- //发货状态
- if (!string.IsNullOrEmpty(SendStatusSelect))
- {
- condition += " and SendStatus=" + SendStatusSelect;
- }
- //商品名称
- if (!string.IsNullOrEmpty(ProductIdSelect))
- {
- condition += " and ProductId=" + ProductIdSelect;
- }
- //仓库类型
- if (!string.IsNullOrEmpty(StoreTypeSelect))
- {
- condition += " and StoreType=" + StoreTypeSelect;
- }
- //仓库归属创客编号
- if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
- {
- condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
- }
- //仓库归属创客真实姓名
- if (!string.IsNullOrEmpty(StoreUserIdRealName))
- {
- condition += " and StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
- }
- //支付状态
- if (!string.IsNullOrEmpty(PayStatusSelect))
- {
- condition += " and PayStatus=" + PayStatusSelect;
- }
- //创建工作薄
- var workbook = new XSSFWorkbook();
- //创建表
- var table = workbook.CreateSheet("Sheet1");
- Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).IndexData("Orders", Fields, "Id desc", "0", 1, 20000, condition, "UserId,OrderNo,RealName,Mobile,TotalPrice,Areas,Address,ErpName,ErpCode,SendDate,PayMode,TradeNo,StoreId,RefundStatus,DeliveryType,SendStatus,ProductId,StoreContact,StoreType,StoreUserId,TopUserId,PayStatus,BuyCount,Remark,Id", false);
- List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
- Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
- ReturnFields.Add("UserIdMakerCode", "创客编号");
- ReturnFields.Add("UserIdRealName", "创客真实姓名");
- ReturnFields.Add("OrderNo", "订单号");
- ReturnFields.Add("RealName", "姓名");
- ReturnFields.Add("Mobile", "手机号");
- ReturnFields.Add("TotalPrice", "总价");
- ReturnFields.Add("Areas", "所在地区");
- ReturnFields.Add("Address", "详细地址");
- ReturnFields.Add("ErpName", "物流名称");
- ReturnFields.Add("ErpCode", "运单号");
- ReturnFields.Add("SendDate", "发货时间");
- ReturnFields.Add("PayMode", "支付方式");
- ReturnFields.Add("TradeNo", "支付交易号");
- ReturnFields.Add("StoreIdStoreNo", "仓库编号");
- ReturnFields.Add("StoreIdStoreName", "仓库名称");
- ReturnFields.Add("RefundStatus", "退款状态");
- ReturnFields.Add("DeliveryType", "提货类型");
- ReturnFields.Add("SendStatus", "发货状态");
- ReturnFields.Add("ProductId", "商品名称");
- ReturnFields.Add("StoreContact", "仓库联系人");
- ReturnFields.Add("StoreType", "仓库类型");
- ReturnFields.Add("StoreUserIdMakerCode", "仓库归属创客编号");
- ReturnFields.Add("StoreUserIdRealName", "仓库归属创客姓名");
- ReturnFields.Add("TopUserIdMakerCode", "顶级创客编号");
- ReturnFields.Add("TopUserIdRealName", "顶级创客姓名");
- ReturnFields.Add("PayStatus", "支付状态");
- ReturnFields.Add("BuyCount", "下单数量");
- ReturnFields.Add("Remark", "订单备注");
- int i = 0;
- foreach (Dictionary<string, object> dic in diclist)
- {
- i += 1;
- //创客
- int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
- Users userid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- dic["UserIdMakerCode"] = userid_Users.MakerCode;
- dic["UserIdRealName"] = userid_Users.RealName;
- dic.Remove("UserId");
- //物流名称
- dic["ErpName"] = RelationClass.GetErpCompanysInfo(dic["ErpName"].ToString());
- //支付方式
- int PayMode = int.Parse(dic["PayMode"].ToString());
- if (PayMode == 1) dic["PayMode"] = "支付宝";
- if (PayMode == 2) dic["PayMode"] = "微信";
- if (PayMode == 3) dic["PayMode"] = "账户余额";
- if (PayMode == 0) dic["PayMode"] = "";
- //仓库
- int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
- StoreHouse storeid_StoreHouse = kxsdb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
- dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
- dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
- dic.Remove("StoreId");
- //退款状态
- int RefundStatus = int.Parse(dic["RefundStatus"].ToString());
- if (RefundStatus == 0) dic["RefundStatus"] = "未退款";
- if (RefundStatus == 1) dic["RefundStatus"] = "已退款";
- //提货类型
- int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
- if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
- if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
- if (DeliveryType == 0) dic["DeliveryType"] = "";
- //发货状态
- int SendStatus = int.Parse(dic["SendStatus"].ToString());
- if (SendStatus == 0) dic["SendStatus"] = "未发货";
- if (SendStatus == 1) dic["SendStatus"] = "已发货";
- if (SendStatus == 2) dic["SendStatus"] = "已退货";
- //商品名称
- dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
- //仓库类型
- int StoreType = int.Parse(dic["StoreType"].ToString());
- if (StoreType == 0) dic["StoreType"] = "总仓";
- if (StoreType == 1) dic["StoreType"] = "分仓";
- //仓库归属创客
- int StoreUserId = int.Parse(function.CheckInt(dic["StoreUserId"].ToString()));
- Users storeuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
- dic["StoreUserIdMakerCode"] = storeuserid_Users.MakerCode;
- dic["StoreUserIdRealName"] = storeuserid_Users.RealName;
- dic.Remove("StoreUserId");
- //顶级创客
- int TopUserId = int.Parse(function.CheckInt(dic["TopUserId"].ToString()));
- Users topuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
- dic["TopUserIdMakerCode"] = topuserid_Users.MakerCode;
- dic["TopUserIdRealName"] = topuserid_Users.RealName;
- dic.Remove("TopUserId");
- //支付状态
- int PayStatus = int.Parse(dic["PayStatus"].ToString());
- if (PayStatus == 0) dic["PayStatus"] = "未支付";
- if (PayStatus == 1) dic["PayStatus"] = "支付成功";
- if (PayStatus == 2) dic["PayStatus"] = "支付失败";
- if (PayStatus == 3) dic["PayStatus"] = "支付锁定中";
- if (PayStatus == 4) dic["PayStatus"] = "支付处理中";
- int OrderId = int.Parse(dic["Id"].ToString());
- List<OrderProduct> products = kxsdb.OrderProduct.Where(m => m.OrderId == OrderId).ToList();
- foreach (OrderProduct product in products)
- {
- dic["ProductCode"] = product.ProductCode; //商品编号
- dic["ProductName"] = product.ProductName; //商品名称
- dic["ProductCount"] = product.ProductCount; //商品数量
- dic["ProductPrice"] = product.ProductPrice; //商品单价
- dic["NormDetail"] = product.NormDetail; //商品规格
- if (i == 1)
- {
- ReturnFields.Add("ProductCode", "商品编号");
- ReturnFields.Add("ProductName", "商品名称");
- ReturnFields.Add("ProductCount", "商品数量");
- ReturnFields.Add("ProductPrice", "商品单价");
- ReturnFields.Add("NormDetail", "商品规格");
- }
- }
- dic.Remove("Id");
- var row = table.CreateRow(i);
- int index = 0;
- foreach (string key in ReturnFields.Keys)
- {
- var cell = row.CreateCell(index);
- string val = dic[key] == null ? "" : dic[key].ToString();
- ICellStyle style = workbook.CreateCellStyle();
- style.BorderBottom = BorderStyle.Thin;
- style.BorderTop = BorderStyle.Thin;
- style.BorderLeft = BorderStyle.Thin;
- style.BorderRight = BorderStyle.Thin;
- style.BottomBorderColor = HSSFColor.Black.Index;
- style.TopBorderColor = HSSFColor.Black.Index;
- style.LeftBorderColor = HSSFColor.Black.Index;
- style.RightBorderColor = HSSFColor.Black.Index;
- cell.CellStyle = style;
- cell.SetCellValue(val);
- index += 1;
- }
- RedisDbconn.Instance.Set("CheckExport:" + RedisKey, i.ToString() + " / " + diclist.Count);
- }
- // 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);
- var title = table.CreateRow(0);
- int j = 0;
- foreach (string key in ReturnFields.Keys)
- {
- var cell = title.CreateCell(j);
- ICellStyle style = workbook.CreateCellStyle();
- style.BorderBottom = BorderStyle.Thin;
- style.BorderTop = BorderStyle.Thin;
- style.BorderLeft = BorderStyle.Thin;
- style.BorderRight = BorderStyle.Thin;
- style.BottomBorderColor = HSSFColor.Black.Index;
- style.TopBorderColor = HSSFColor.Black.Index;
- style.LeftBorderColor = HSSFColor.Black.Index;
- style.RightBorderColor = HSSFColor.Black.Index;
- cell.CellStyle = style;
- cell.SetCellValue(ReturnFields[key].ToString());
- j += 1;
- }
- //打开xls文件,如没有则创建,如存在则在创建是不要打开该文件
- string FilePath = function.getPath("/static/export/");
- if (!System.IO.Directory.Exists(FilePath))
- {
- System.IO.Directory.CreateDirectory(FilePath);
- }
- string FileName = "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx";
- using (var fs = System.IO.File.OpenWrite(FilePath + FileName))
- {
- workbook.Write(fs); //向打开的这个xls文件中写入mySheet表并保存。
- }
- // result.Add("Fields", ReturnFields);
- AddSysLog("0", "Orders", "ExportExcel");
- RedisDbconn.Instance.Set("CheckExport:" + RedisKey, "finish");
- return "success|/static/export/" + FileName;
- }
- public string CheckExport(string RedisKey = "ExportKey")
- {
- string result = RedisDbconn.Instance.Get<string>("CheckExport:" + RedisKey);
- return result;
- }
- #endregion
- #region 导出Excel
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <returns></returns>
- public JsonResult ExportsExcel(Orders data, string UserIdMakerCode, string UserIdRealName, string PayModeSelect, string StoreIdStoreNo, string StoreIdStoreName, string RefundStatusSelect, string DeliveryTypeSelect, string SendStatusSelect, string ProductIdSelect, string StoreTypeSelect, string StoreUserIdMakerCode, string StoreUserIdRealName, string PayStatusSelect, string CreateDateData, string SendDateData, string PayDateData, string RedisKey = "ExportKey")
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- // Fields.Add("CreateDate", "3"); //时间
- Fields.Add("OrderNo", "1"); //订单号
- Fields.Add("RealName", "1"); //姓名
- Fields.Add("Mobile", "1"); //手机号
- Fields.Add("ErpCode", "1"); //运单号
- // Fields.Add("SendDate", "3"); //发货时间
- Fields.Add("TradeNo", "1"); //支付交易号
- Fields.Add("StoreContact", "1"); //仓库联系人
- Fields.Add("SnNos", "2"); //SN编号
- Fields.Add("TopUserId", "0");
- string condition = " and Status>-1 and ProductId=49";
- //创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- //创客真实姓名
- if (!string.IsNullOrEmpty(UserIdRealName))
- {
- condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
- }
- //支付方式
- if (!string.IsNullOrEmpty(PayModeSelect))
- {
- condition += " and PayMode=" + PayModeSelect;
- }
- //仓库编号
- if (!string.IsNullOrEmpty(StoreIdStoreNo))
- {
- condition += " and StoreId in (select StoreId from StoreHouseForStoreNo where StoreNo='" + StoreIdStoreNo + "')";
- }
- //仓库名称
- if (!string.IsNullOrEmpty(StoreIdStoreName))
- {
- condition += " and StoreId in (select StoreId from StoreHouseForStoreName where StoreName='" + StoreIdStoreName + "')";
- }
- //退款状态
- if (!string.IsNullOrEmpty(RefundStatusSelect))
- {
- condition += " and RefundStatus=" + RefundStatusSelect;
- }
- //提货类型
- if (!string.IsNullOrEmpty(DeliveryTypeSelect))
- {
- condition += " and DeliveryType=" + DeliveryTypeSelect;
- }
- //发货状态
- if (!string.IsNullOrEmpty(SendStatusSelect))
- {
- condition += " and SendStatus=" + SendStatusSelect;
- }
- //商品名称
- if (!string.IsNullOrEmpty(ProductIdSelect))
- {
- condition += " and ProductId=" + ProductIdSelect;
- }
- //仓库类型
- if (!string.IsNullOrEmpty(StoreTypeSelect))
- {
- condition += " and StoreType=" + StoreTypeSelect;
- }
- //仓库归属创客编号
- if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
- {
- condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
- }
- //仓库归属创客真实姓名
- if (!string.IsNullOrEmpty(StoreUserIdRealName))
- {
- condition += " and StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
- }
- //支付状态
- if (!string.IsNullOrEmpty(PayStatusSelect))
- {
- condition += " and PayStatus=" + PayStatusSelect;
- }
- //支付时间
- if (!string.IsNullOrEmpty(PayDateData))
- {
- string[] datelist = PayDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- string start = datelist[0];
- string end = datelist[1];
- condition += " and PayDate>='" + start + " 00:00:00' and PayDate<='" + end + " 23:59:59'";
- }
- //下单时间
- 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(SendDateData))
- {
- string[] datelist = SendDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- string start = datelist[0];
- string end = datelist[1];
- condition += " and SendDate>='" + start + " 00:00:00' and SendDate<='" + end + " 23:59:59'";
- }
- Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).IndexData("Orders", Fields, "Id desc", "0", 1, 20000, condition, "UserId,OrderNo,RealName,Mobile,TotalPrice,Areas,Address,ErpName,ErpCode,SendDate,PayMode,PayDate,TradeNo,StoreId,RefundStatus,DeliveryType,SendStatus,ProductId,StoreContact,StoreType,StoreUserId,TopUserId,PayStatus,BuyCount,Remark,Id", false);
- List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
- foreach (Dictionary<string, object> dic in diclist)
- {
- //创客
- int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
- Users userid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- dic["UserIdMakerCode"] = userid_Users.MakerCode;
- dic["UserIdRealName"] = userid_Users.RealName;
- dic.Remove("UserId");
- //物流名称
- dic["ErpName"] = RelationClass.GetErpCompanysInfo(dic["ErpName"].ToString());
- //支付方式
- int PayMode = int.Parse(dic["PayMode"].ToString());
- if (PayMode == 1) dic["PayMode"] = "支付宝";
- if (PayMode == 2) dic["PayMode"] = "微信";
- if (PayMode == 3) dic["PayMode"] = "账户余额";
- if (PayMode == 0) dic["PayMode"] = "";
- //仓库
- int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
- StoreHouse storeid_StoreHouse = kxsdb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
- dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
- dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
- dic.Remove("StoreId");
- //退款状态
- int RefundStatus = int.Parse(dic["RefundStatus"].ToString());
- if (RefundStatus == 0) dic["RefundStatus"] = "未退款";
- if (RefundStatus == 1) dic["RefundStatus"] = "已退款";
- //提货类型
- int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
- if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
- if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
- if (DeliveryType == 0) dic["DeliveryType"] = "";
- //发货状态
- int SendStatus = int.Parse(dic["SendStatus"].ToString());
- if (SendStatus == 0) dic["SendStatus"] = "未发货";
- if (SendStatus == 1) dic["SendStatus"] = "已发货";
- if (SendStatus == 2) dic["SendStatus"] = "已退货";
- //商品名称
- dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
- //仓库类型
- int StoreType = int.Parse(dic["StoreType"].ToString());
- if (StoreType == 0) dic["StoreType"] = "总仓";
- if (StoreType == 1) dic["StoreType"] = "分仓";
- //仓库归属创客
- int StoreUserId = int.Parse(function.CheckInt(dic["StoreUserId"].ToString()));
- Users storeuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
- dic["StoreUserIdMakerCode"] = storeuserid_Users.MakerCode;
- dic["StoreUserIdRealName"] = storeuserid_Users.RealName;
- dic.Remove("StoreUserId");
- //顶级创客
- int TopUserId = int.Parse(function.CheckInt(dic["TopUserId"].ToString()));
- Users topuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
- dic["TopUserIdMakerCode"] = topuserid_Users.MakerCode;
- dic["TopUserIdRealName"] = topuserid_Users.RealName;
- dic.Remove("TopUserId");
- //支付状态
- int PayStatus = int.Parse(dic["PayStatus"].ToString());
- if (PayStatus == 0) dic["PayStatus"] = "未支付";
- if (PayStatus == 1) dic["PayStatus"] = "支付成功";
- if (PayStatus == 2) dic["PayStatus"] = "支付失败";
- if (PayStatus == 3) dic["PayStatus"] = "支付锁定中";
- if (PayStatus == 4) dic["PayStatus"] = "支付处理中";
- int OrderId = int.Parse(dic["Id"].ToString());
- List<OrderProduct> products = kxsdb.OrderProduct.Where(m => m.OrderId == OrderId).ToList();
- foreach (OrderProduct product in products)
- {
- dic["ProductCode"] = product.ProductCode; //商品编号
- dic["ProductName"] = product.ProductName; //商品名称
- dic["ProductCount"] = product.ProductCount; //商品数量
- dic["ProductPrice"] = product.ProductPrice; //商品单价
- dic["NormDetail"] = product.NormDetail; //商品规格
- }
- dic.Remove("Id");
- }
- 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("UserIdMakerCode", "创客编号");
- ReturnFields.Add("UserIdRealName", "创客真实姓名");
- ReturnFields.Add("OrderNo", "订单号");
- ReturnFields.Add("RealName", "姓名");
- ReturnFields.Add("Mobile", "手机号");
- ReturnFields.Add("TotalPrice", "总价");
- ReturnFields.Add("Areas", "所在地区");
- ReturnFields.Add("Address", "详细地址");
- ReturnFields.Add("ErpName", "物流名称");
- ReturnFields.Add("ErpCode", "运单号");
- ReturnFields.Add("SendDate", "发货时间");
- ReturnFields.Add("PayMode", "支付方式");
- ReturnFields.Add("PayDate", "支付时间");
- ReturnFields.Add("TradeNo", "支付交易号");
- ReturnFields.Add("StoreIdStoreNo", "仓库编号");
- ReturnFields.Add("StoreIdStoreName", "仓库名称");
- ReturnFields.Add("RefundStatus", "退款状态");
- ReturnFields.Add("DeliveryType", "提货类型");
- ReturnFields.Add("SendStatus", "发货状态");
- ReturnFields.Add("ProductId", "商品名称");
- ReturnFields.Add("StoreContact", "仓库联系人");
- ReturnFields.Add("StoreType", "仓库类型");
- ReturnFields.Add("StoreUserIdMakerCode", "仓库归属创客编号");
- ReturnFields.Add("StoreUserIdRealName", "仓库归属创客姓名");
- ReturnFields.Add("TopUserIdMakerCode", "顶级创客编号");
- ReturnFields.Add("TopUserIdRealName", "顶级创客姓名");
- ReturnFields.Add("PayStatus", "支付状态");
- ReturnFields.Add("BuyCount", "下单数量");
- ReturnFields.Add("Remark", "订单备注");
- ReturnFields.Add("ProductCode", "商品编号");
- ReturnFields.Add("ProductName", "商品名称");
- ReturnFields.Add("ProductCount", "商品数量");
- ReturnFields.Add("ProductPrice", "商品单价");
- ReturnFields.Add("NormDetail", "商品规格");
- result.Add("Fields", ReturnFields);
- AddSysLog("0", "Orders", "ExportExcel");
- return Json(result);
- }
- #endregion
- }
- }
|