//设置支付信息 public static void SetPayInfo(long SOID, SOPayInfo SOPayInfo, bool Paid, out string Message) { using (var TS = new TransactionScope()) { using (var EF = new EF()) { var so_exist = EF.SalesOrders.FirstOrDefault(i => i.ID == SOID); if (so_exist == null) { Message = "订单号" + SOID + "不存在"; return; } var pay_exist = EF.SOPayInfos.FirstOrDefault(i => i.SOID == so_exist.ID); pay_exist.PrePayID = SOPayInfo.PrePayID; pay_exist.PayID = SOPayInfo.PayID; EF.SaveChanges(); if (Paid) { so_exist.StateID = State.FirstOrDefault(i => i.Name == "Paid").ID; pay_exist.StateID = Ziri.BLL.WeChat.WxTradeState.FirstOrDefault(i => i.Name == "SUCCESS").ID; EF.SaveChanges(); } TS.Complete(); Message = null; } } }
//设置订单信息 public static SOInfo SetSalesOrder(SOInfo SOInfo, out string Message) { using (var EF = new EF()) { //检查单号 if (!string.IsNullOrWhiteSpace(SOInfo.SalesOrder.BillNO)) { var billno_check = EF.SalesOrders.FirstOrDefault(i => i.ID != SOInfo.SalesOrder.ID && i.BillNO == SOInfo.SalesOrder.BillNO); if (billno_check != null) { Message = "单号已被占用,请重试。"; return(null); } } using (var TS = new TransactionScope()) { //主表信息 MDL.SalesOrder order_exist = null; if (SOInfo.SalesOrder.ID == 0) { EF.SalesOrders.Add(order_exist = new MDL.SalesOrder { //WxUserID = salesOrder.WxUserID, BillNO = "SO" + DateTime.Now.ToString("yyyyMMddHHmmssffff"), StateID = State.FirstOrDefault(i => i.Name == "Create").ID, CreateTime = DateTime.Now, }); } else { order_exist = EF.SalesOrders.FirstOrDefault(i => i.ID == SOInfo.SalesOrder.ID); if (order_exist == null) { Message = "订单编号" + SOInfo.SalesOrder.ID + "不存在"; return(null); } //检查 var order_state = State.FirstOrDefault(i => i.ID == order_exist.StateID); if (order_state.ID != State.FirstOrDefault(i => i.Name == "Create").ID) { Message = "订单状态为" + order_state.Title + ",不能修改!"; return(null); } var customer_check = EF.SOCustomerInfos.FirstOrDefault(i => i.SOID == order_exist.ID); if (customer_check.CustomerID != SOInfo.SOCustomerInfo.CustomerID) { Message = "不能修改其他客户的订单"; return(null); } //通过 order_exist.UpdateTime = DateTime.Now; } order_exist.Remark = SOInfo.SalesOrder.Remark; EF.SaveChanges(); //分录信息 var items_check = EF.SalesOrderItems.Where(i => i.SOID == order_exist.ID).ToList(); if (items_check != null) { EF.SalesOrderItems.RemoveRange(items_check); } var items_exist = new List <SalesOrderItem>(); var item_goods_id = SOInfo.SalesOrderItems.Select(j => j.GoodsID); var item_goods = EF.GoodsInfos.Where(i => item_goods_id.Contains(i.ID)).ToList(); foreach (var item in SOInfo.SalesOrderItems) { var counter = EF.GoodsCounter.FirstOrDefault(i => i.ID == item.CounterID); var item_exist = new SalesOrderItem { SOID = order_exist.ID, OrderID = SOInfo.SalesOrderItems.IndexOf(item) + 1, GoodsID = item.GoodsID, SpecID = item.SpecID, CounterID = item.CounterID, //Counter = item.Counter, Quantity = item.Quantity, Price = counter.Price, Amount = item.Quantity * counter.Price, }; EF.SalesOrderItems.Add(item_exist); items_exist.Add(item_exist); } //客户信息 var customer_exist = EF.SOCustomerInfos.FirstOrDefault(i => i.SOID == order_exist.ID); if (customer_exist == null) { EF.SOCustomerInfos.Add(customer_exist = new SOCustomerInfo { SOID = order_exist.ID, }); } customer_exist.CustomerTypeID = SOInfo.SOCustomerInfo.CustomerTypeID; customer_exist.CustomerID = SOInfo.SOCustomerInfo.CustomerID; //收货信息 var receive_exist = EF.SOReceiveInfos.FirstOrDefault(i => i.SOID == order_exist.ID); if (receive_exist == null) { EF.SOReceiveInfos.Add(receive_exist = new SOReceiveInfo { SOID = order_exist.ID, }); } receive_exist.Consignee = SOInfo.SOReceiveInfo.Consignee; receive_exist.Phone = SOInfo.SOReceiveInfo.Phone; receive_exist.ReceiveTypeID = SOInfo.SOReceiveInfo.ReceiveTypeID; receive_exist.StoreID = SOInfo.SOReceiveInfo.StoreID; receive_exist.Address = SOInfo.SOReceiveInfo.Address; receive_exist.AddressCheck = SOInfo.SOReceiveInfo.AddressCheck; //支付信息 var pay_exist = EF.SOPayInfos.FirstOrDefault(i => i.SOID == order_exist.ID); if (pay_exist == null) { EF.SOPayInfos.Add(pay_exist = new SOPayInfo { SOID = order_exist.ID, StateID = WeChat.WxTradeState.FirstOrDefault(i => i.Name == "NOTPAY").ID, }); } pay_exist.PayTypeID = SOInfo.SOPayInfo.PayTypeID; //保存 EF.SaveChanges(); TS.Complete(); Message = null; return(new SOInfo { SalesOrder = order_exist, SalesOrderItems = items_exist, SOCustomerInfo = customer_exist, SOReceiveInfo = receive_exist, SOPayInfo = pay_exist, GoodsInfos = item_goods, }); } } }