📄 order.cs
字号:
namespace PowerEasy.Shop
{
using PowerEasy.Accessories;
using PowerEasy.Common;
using PowerEasy.Components;
using PowerEasy.Crm;
using PowerEasy.Enumerations;
using PowerEasy.IDal.Shop;
using PowerEasy.Model.Accessories;
using PowerEasy.Model.Crm;
using PowerEasy.Model.Shop;
using PowerEasy.Model.UserManage;
using PowerEasy.UserManage;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
public sealed class Order
{
private static readonly IOrder dal = DataAccess.CreateOrder();
private static string m_MessgeOrMailContentOfCard;
private Order()
{
}
public static bool Add(OrderInfo orderInfo)
{
if (SiteConfig.ConfigInfo().ShopConfig.IsSetFunctionary)
{
string str = string.Empty;
foreach (AdministratorInfo info in Administrators.GetAdminListByOperateCode(0, Administrators.GetTotalOfAdmin(), 0x614719c))
{
str = str + info.AdminName + ",";
}
orderInfo.Functionary = AllotFunctionary(str.TrimEnd(new char[] { ',' }));
}
return dal.Add(DoHtmlEncode(orderInfo));
}
public static bool Add(OrderInfo orderInfo, OrderFlowInfo orderFlowInfo, bool processUserInfo)
{
if (processUserInfo && !string.IsNullOrEmpty(orderInfo.UserName))
{
UserInfo usersByUserName = Users.GetUsersByUserName(orderInfo.UserName);
orderFlowInfo.ConsigneeName = orderInfo.ContacterName;
orderFlowInfo.ZipCode = orderInfo.ZipCode;
orderFlowInfo.Email = orderInfo.Email;
orderFlowInfo.HomePhone = orderInfo.Phone;
orderFlowInfo.Mobile = orderInfo.Mobile;
ProcessSubscriber(orderFlowInfo, usersByUserName);
orderInfo.ClientId = usersByUserName.ClientId;
}
return Add(orderInfo);
}
public static int Add(OrderFlowInfo orderFlowInfo, UserInfo userInfo, string cartId, int couponId, decimal trueTotalMoney)
{
decimal num5;
int num6;
int num7;
if (string.IsNullOrEmpty(cartId))
{
return 1;
}
IList<ShoppingCartInfo> infoByCart = ShoppingCart.GetInfoByCart(cartId, false);
if (infoByCart.Count <= 0)
{
return 2;
}
IList<ShoppingCartInfo> shoppingCartPresentInfoList = ShoppingCart.GetInfoByCart(cartId, true);
OrderInfo orderInfo = new OrderInfo();
double totalWeight = 0.0;
decimal totalMoney = 0M;
double discount = PaymentType.GetPaymentTypeById(orderFlowInfo.PaymentType).Discount;
string userName = "";
int clientId = 0;
if (!userInfo.IsNull)
{
ProcessSubscriber(orderFlowInfo, userInfo);
userName = userInfo.UserName;
clientId = userInfo.ClientId;
}
AddOrder(orderFlowInfo, orderInfo, discount, userName, clientId);
AddOrderItems(orderFlowInfo, infoByCart, shoppingCartPresentInfoList, orderInfo, ref totalWeight, ref totalMoney, userInfo);
CheckPresentProject(orderFlowInfo, orderInfo, ref totalWeight, ref totalMoney, out num5, out num6, out num7);
decimal num8 = totalMoney;
PackageInfo packageByGoodsWeight = Package.GetPackageByGoodsWeight(totalWeight);
if (!packageByGoodsWeight.IsNull)
{
totalWeight += packageByGoodsWeight.PackageWeight;
}
decimal num9 = DeliverCharge.GetDeliverCharge(orderFlowInfo.DeliverType, totalWeight, orderFlowInfo.ZipCode, totalMoney, orderFlowInfo.NeedInvoice);
totalMoney += num9;
orderInfo.MoneyGoods = num8;
orderInfo.ChargeDeliver = num9;
if (couponId > 0)
{
orderInfo.MoneyTotal = trueTotalMoney;
orderInfo.CouponId = couponId;
}
else
{
orderInfo.MoneyTotal = totalMoney;
}
orderInfo.PresentMoney = num5;
orderInfo.PresentExp = num6;
orderInfo.PresentPoint = num7;
Update(DoHtmlDecode(orderInfo));
ShoppingCart.Delete(cartId);
SmsConfig smsConfig = SiteConfig.SmsConfig;
if ((smsConfig.IsAutoSendMessage && !string.IsNullOrEmpty(smsConfig.AdminPhoneNumber)) && !string.IsNullOrEmpty(smsConfig.OrderMessage))
{
AbstractMessageOfOrder order = new SmsOfOrder("", SendType.SendToAdmin, smsConfig.AdminPhoneNumber);
order.Implementor = new OrderFlow(orderInfo, "");
order.Send();
}
return 0x63;
}
private static void AddOrder(OrderFlowInfo orderFlowInfo, OrderInfo orderInfo, double paymentDiscount, string userName, int clientId)
{
if (orderFlowInfo.OrderId == 0)
{
orderInfo.OrderId = GetMaxId() + 1;
}
else
{
orderInfo.OrderId = orderFlowInfo.OrderId;
}
orderInfo.OrderNum = GetOrderNum();
orderInfo.UserName = userName;
orderInfo.ClientId = clientId;
orderInfo.ContacterName = orderFlowInfo.ConsigneeName;
if (orderFlowInfo.Country != "中华人民共和国")
{
orderInfo.Address = orderFlowInfo.Country;
}
string address = orderInfo.Address;
orderInfo.Address = address + orderFlowInfo.Province + orderFlowInfo.City + orderFlowInfo.Area + orderFlowInfo.Address;
orderInfo.ZipCode = orderFlowInfo.ZipCode;
orderInfo.Mobile = orderFlowInfo.Mobile;
orderInfo.Phone = orderFlowInfo.HomePhone;
orderInfo.Email = orderFlowInfo.Email;
orderInfo.PaymentType = orderFlowInfo.PaymentType;
orderInfo.DeliverType = orderFlowInfo.DeliverType;
orderInfo.NeedInvoice = orderFlowInfo.NeedInvoice;
orderInfo.InvoiceContent = orderFlowInfo.InvoiceContent;
orderInfo.Invoiced = false;
orderInfo.Remark = orderFlowInfo.Remark;
orderInfo.BeginDate = orderFlowInfo.BeginDate;
orderInfo.InputTime = DateTime.Now;
orderInfo.Status = OrderStatus.WaitForConfirm;
orderInfo.DeliverStatus = DeliverStatus.Preparative;
orderInfo.EnableDownload = false;
orderInfo.DiscountPayment = paymentDiscount;
orderInfo.ChargeDeliver = 0M;
orderInfo.AgentName = orderFlowInfo.AgentName;
orderInfo.OutOfStockProject = orderFlowInfo.OutOfStockProject;
Add(orderInfo);
}
private static void AddOrderItems(OrderFlowInfo orderFlowInfo, IList<ShoppingCartInfo> shoppingCartProductInfoList, IList<ShoppingCartInfo> shoppingCartPresentInfoList, OrderInfo orderInfo, ref double totalWeight, ref decimal totalMoney, UserInfo userInfo)
{
bool haveWholesalePurview = false;
if (!userInfo.UserPurview.IsNull)
{
haveWholesalePurview = userInfo.UserPurview.Enablepm;
}
foreach (ShoppingCartInfo info in shoppingCartProductInfoList)
{
ProductInfo productById = Product.GetProductById(info.ProductId, info.TableName);
if (!productById.IsNull)
{
AbstractItemInfo info3 = new ConcreteProductInfo(info.Quantity, info.Property, productById, userInfo, orderFlowInfo.NeedInvoice, true, haveWholesalePurview);
info3.GetItemInfo();
OrderItem.Add(info3.GetOrderItemInfo(orderInfo.OrderId));
totalMoney += info3.SubTotal;
totalWeight += info3.TotalWeight;
AddPressent(info.Quantity, shoppingCartPresentInfoList, ref totalWeight, ref totalMoney, productById, orderInfo.OrderId);
}
}
}
private static void AddPressent(int amount, IList<ShoppingCartInfo> shoppingCartPresentInfoList, ref double totalWeight, ref decimal totalMoney, ProductInfo productInfo, int orderId)
{
if ((productInfo.SalePromotionType > 0) && (amount >= productInfo.MinNumber))
{
AbstractItemInfo info = new ConcreteSalePromotionType(amount, productInfo, true, shoppingCartPresentInfoList);
info.GetItemInfo();
if (!info.IsNull)
{
totalWeight += info.TotalWeight;
totalMoney += info.SubTotal;
if (OrderItem.Add(info.GetOrderItemInfo(orderId)))
{
Product.AddOrderNum(info.ProductId, info.TableName, info.Amount);
}
}
}
}
public static void AddStockItemBySendCard(int stockId, OrderItemInfo orderItemInfo)
{
string productNum = string.Empty;
if (!string.IsNullOrEmpty(orderItemInfo.TableName))
{
ProductInfo productById = Product.GetProductById(orderItemInfo.ProductId);
productById.Stocks -= orderItemInfo.Amount;
productById.OrderNum -= orderItemInfo.Amount;
ProductCommon.Update(productById, productById.TableName);
productNum = productById.ProductNum;
}
else
{
PresentInfo presentById = Present.GetPresentById(orderItemInfo.ProductId);
presentById.Stocks -= orderItemInfo.Amount;
presentById.OrderNum -= orderItemInfo.Amount;
Present.UpdatePressent(presentById);
productNum = presentById.PresentNum;
}
StockItemInfo info3 = new StockItemInfo();
info3.Amount = orderItemInfo.Amount;
info3.Price = orderItemInfo.TruePrice;
info3.ProductId = orderItemInfo.ProductId;
info3.TableName = orderItemInfo.TableName;
info3.ProductName = orderItemInfo.ProductName;
info3.ProductNum = productNum;
info3.Property = orderItemInfo.Property;
info3.StockId = stockId;
info3.Unit = orderItemInfo.Unit;
StockItem.Add(info3, stockId);
}
private static string AllotFunctionary(string shopConfigFunctionary)
{
string[] strArray = shopConfigFunctionary.Split(new char[] { ',' });
if (strArray.Length == 0)
{
return string.Empty;
}
string str = string.Empty;
string lastFunctionary = GetLastFunctionary();
bool flag = false;
foreach (string str3 in strArray)
{
if (flag)
{
str = str3;
break;
}
if (str3 == lastFunctionary)
{
flag = true;
}
}
if (string.IsNullOrEmpty(str))
{
str = strArray[0];
}
return str;
}
public static bool CancelConfirm(int orderId)
{
return dal.CancelConfirm(orderId);
}
private static void CheckPresentProject(OrderFlowInfo orderFlowInfo, OrderInfo orderInfo, ref double totalWeight, ref decimal totalMoney, out decimal presentMoney, out int presentExp, out int presentPoint)
{
presentMoney = 0M;
presentExp = 0;
presentPoint = 0;
PresentProjectInfo presentProjectByTotalMoney = PresentProject.GetPresentProjectByTotalMoney(totalMoney);
if (!presentProjectByTotalMoney.IsNull)
{
if ((presentProjectByTotalMoney.PresentContent.Contains("1") && (orderFlowInfo.PresentId > 0)) && !Present.GetPresentById(orderFlowInfo.PresentId).IsNull)
{
AbstractItemInfo info3 = new ConcretePresentProject(orderFlowInfo.PresentId, presentProjectByTotalMoney);
info3.GetItemInfo();
if (!info3.IsNull)
{
totalMoney += info3.SubTotal;
totalWeight += info3.TotalWeight;
OrderItem.Add(info3.GetOrderItemInfo(orderInfo.OrderId));
Product.AddOrderNum(info3.ProductId, info3.TableName, 1);
}
}
if (presentProjectByTotalMoney.PresentContent.Contains("2"))
{
presentMoney = presentProjectByTotalMoney.Cash;
}
if (presentProjectByTotalMoney.PresentContent.Contains("3"))
{
presentExp = presentProjectByTotalMoney.PresentExp;
}
if (presentProjectByTotalMoney.PresentContent.Contains("4"))
{
presentPoint = presentProjectByTotalMoney.PresentPoint;
}
}
}
public static int Confirm(int orderId)
{
return dal.Confirm(orderId);
}
public static string Delete(string orderId)
{
return dal.Delete(DataSecurity.FilterBadChar(orderId));
}
public static bool DoDownload(int orderId, bool enableDownload)
{
bool flag = dal.DoDownload(orderId, enableDownload);
if (enableDownload && flag)
{
bool flag2 = false;
bool flag3 = false;
bool flag4 = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -