Beispiel #1
0
 public object CreateCustomerByPhone(string fullName, string mobile, string tel)
 {
     try
     {
         var svc = new CommonService();
         if (mobile != "" || tel != "")
         {
             var isExits = false;
             if (mobile != "")
             {
                 isExits = context.Customers.Any(p => p.Mobile == mobile);
             }
             else
             {
                 isExits = context.Customers.Any(p => p.Tel == tel);
             }
             if (isExits)
             {
                 return(new { status = false, message = "添加失败:联系号码已存在" });
             }
             FCake.Domain.Entities.Customers customer = new FCake.Domain.Entities.Customers();
             customer.FullName              = fullName;
             customer.Mobile                = mobile;
             customer.Tel                   = tel;
             customer.IsDeleted             = 0;
             customer.Id                    = FCake.Core.Common.DataHelper.GetSystemID();
             customer.CustomerType          = 2;            //2=电话会员
             customer.MemberLevelValue      = 1;            //首次创建默认为普通卡会员
             customer.UpdateMemberLevelTime = DateTime.Now; //首次创建默认为当前时间
             context.Customers.Add(customer);
             int result = context.SaveChanges();
             if (result > 0)
             {
                 return new
                        {
                            status   = true,
                            message  = "添加成功",
                            customer = new
                            {
                                Id           = customer.Id,
                                FullName     = customer.FullName,
                                Tel          = customer.Tel,
                                Mobile       = customer.Mobile,
                                Email        = customer.Email + "",
                                Sex          = EnumHelper.GetDescription(((Sex)(customer.Sex ?? 3))),
                                CustomerType = svc.GetDictionaryName("CustomerCategory", customer.CustomerType + "")
                            }
                        }
             }
             ;
             else
             {
                 return new { status = false, message = "添加失败" }
             };
         }
         else
         {
             return(new { status = false, message = "添加失败,手机号码、固定电话至少填一项" });
         }
     }
     catch (Exception e)
     {
         return(new { status = false, message = "添加出错:" + e.Message });
     }
 }
        public ActionResult AddOrder(string orderid = "", string customerid = "")
        {
            orderid    = orderid.Trim();
            customerid = customerid.Trim();
            bool invoice  = false;
            bool isperson = true;

            if (customerid.IsNullOrTrimEmpty() == false)
            {
                var customer = osv.SingleOrDefault <Customers>(a => a.Id.Equals(customerid, StringComparison.OrdinalIgnoreCase));
                //var customer = new CustomersService().GetById(customerid);
                if (customer == null)
                {
                    return(Redirect("/order/addorder"));
                }
            }
            var times = new FCake.Bll.CommonService().GetDictionaryByCode("DistributionTime");

            ViewBag.invoicetype = "";
            if (orderid.IsNullOrTrimEmpty() == false)
            {
                var order = osv.SingleOrDefault <Orders>(a => a.No.Equals(orderid));
                //var order = new OrderService().GetByNo(orderid);
                if (order == null)
                {
                    return(Redirect("/order/addorder"));
                }
                customerid = order.CustomerId;
                var delivertime = order.RequiredTime == null ? "" : ((DateTime)order.RequiredTime).ToString("yyyy-MM-dd");
                var deliverHour = order.RequiredTime == null ? "" : ((DateTime)order.RequiredTime).ToString("yyyy-MM-dd HH:mm:ss").Split(' ')[1].Substring(0, 5);

                //匹配新旧时间下拉数据信息
                foreach (var item in times.OrderBy(t => t.Sorting))
                {
                    var itemVal    = item.Value.Split(':')[0].ToInt32();
                    var deliverVal = deliverHour.Split(':')[0].ToInt32();
                    if (itemVal >= deliverVal)
                    {
                        deliverHour = item.Value;
                        break;
                    }
                }
                ViewBag.delivertime       = delivertime;
                ViewBag.deliverHour       = deliverHour;
                ViewBag.status            = order.Status;
                ViewBag.source            = order.OrderSource;
                ViewBag.productenableedit = order.TradeStatus == TradeStatus.NotPay && order.Status == OrderStatus.HadPaid;
                ViewBag.revierName        = order.Receiver;
                ViewBag.revierPhone       = order.ReceiverMobile ?? order.ReceiverTel;
                //发票中的ORDERID存的是ID  不是NO!!
                var oid      = order.Id;
                var invoices = osv.SingleOrDefault <Invoice>(a => a.OrderId.Equals(oid));
                //var invoices = new InvoiceService().GetByOrderId(orderid);     //context.Invoices.SingleOrDefault(a => a.IsDeleted == 0 && a.OrderId.Equals(orderid));
                invoice = (invoices != null);
                if (invoice)
                {
                    ViewBag.invoicetype  = invoices.InvoiceType;
                    ViewBag.invoicetitle = invoices.InvoiceTitle;
                }
            }
            ViewBag.times      = times;
            ViewBag.isperson   = isperson;
            ViewBag.orderid    = orderid;
            ViewBag.customerid = customerid;

            //取用户积分
            if (customerid != "")
            {
                var customerInfo = new CustomersService().GetMemberByMemberId(customerid);
                ViewBag.Integral = customerInfo.Integral;
            }
            else
            {
                ViewBag.Integral = 0;
            }
            //取积分兑换比例
            ViewBag.integralDeductionCashRate = CommonRules.IntegralDeductionCashRate;


            return(View());
        }