// return -1 error,1 auto login 0 need redirect login private static int SaveOrderMeal(OrderMealUserData userData, List<OrderMealData> orderData, out int orderId, out string message) { orderId = -1; if (!CheckUserData(userData, out message)) return -1; SysCompany company = SysCompany.FetchByID(userData.companyId); if (company == null) { message = "你选择的商家不存在."; return -1; } if (Formatter.ToEnum<CompanyType>(company.CompanyType.Value) != CompanyType.MealCompany) { message = "你选择的商家不是快餐店."; return -1; } SysCompanyItem companyItem = userData.itemId > 0 ? SysCompanyItem.FetchByID(userData.itemId) : null; var menuDict = MealMenuBLL.LoadCompanyMenu(company.Id).ToDictionary(dr => Convert.ToInt32(dr[SysTakeawayMenu.IdColumn.ColumnName]), dr => { SysTakeawayMenu m = new SysTakeawayMenu( ); m.Load(dr); return m; }); int qty = 0; decimal orderSum = 0; orderData.Sort((t1, t2) => { if (t1.sort == t2.sort) return 0; else if (t1.sort > t2.sort) return 1; else return -1; }); foreach (var pair in orderData) { if (!pair.isCompanyItem && !menuDict.ContainsKey(pair.menudId)) { message = "你选择了一个已经缺货或不存在的菜单,请重新下订."; return -1; } if (pair.menuAmount <= 0) { message = "订餐的数量不能小于或等于零."; return -1; } if (!pair.isCompanyItem) { var m = menuDict[pair.menudId]; pair.menudId = m.Id; pair.menuPrice = (m.Price ?? (decimal?)0).Value; pair.menuName = m.Name; } else if (companyItem != null) { pair.menudId = -userData.itemId; pair.menuPrice = (companyItem.ItemNeedPay ?? (decimal?)0).Value; pair.menuName = companyItem.ItemTitle; } orderSum += (pair.menuPrice.Value * pair.menuAmount); qty += pair.menuAmount; } orderSum = Math.Round(orderSum, 1); Order order = null; if (userData.orderId > 0) { lock (LockScopeAction(userData.orderId)) { order = Order.FetchByID(userData.orderId); if (order == null) { message = "你选择了一个不存在的订单."; return -1; } if (Formatter.ToEnum<OrderType>(order.OrderType.Value) != OrderType.OrderMeal) { message = "你选择了一个不存在的订单."; return -1; } if (order.OrderStatus == (int)OrderStatus.Completed || order.OrderStatus == (int)OrderStatus.Canceled) { message = "此订单不允许修改."; return -1; } return SaveOrder(userData, orderData, order, company, companyItem, orderSum, qty, false, out orderId, out message); } } else { order = new Order( ); order.OrderCode = OrderBLL.GetOrderCode(company); return SaveOrder(userData, orderData, order, company, companyItem, orderSum, qty, true, out orderId, out message); } }
public static Dictionary<CompanyMealMenuId, SysTakeawayMenu> GetMealDirMappingByCompanyId(int companyId) { if (_companyMealMenuMapping == null) _companyMealMenuMapping = new Dictionary<int, Dictionary<CompanyMealMenuId, SysTakeawayMenu>>( ); if (!_companyMealMenuMapping.ContainsKey(companyId)) { var dict = LoadCompanyMenu(companyId, true).ToDictionary(dr => CompanyMealMenuId.GetCompanyMealMenuId(dr[SysTakeawayDirectory.DirNameColumn.ColumnName].ToString( ), dr[SysTakeawayMenu.NameColumn.ColumnName].ToString( )), dr => { SysTakeawayMenu m = new SysTakeawayMenu( ); m.Load(dr); return m; }); _companyMealMenuMapping.Add(companyId, dict); return dict; } return _companyMealMenuMapping[companyId]; }