Exemplo n.º 1
0
 public IActionResult MachineBindUpload()
 {
     try
     {
         var    companyId        = Request.Headers["CompanyId"].ToString().ToInt();
         var    companyPid       = Request.Headers["CompanyPid"].ToString().ToInt();
         int    machineId        = Request.Form["machineId"].ToString().ToInt();
         string bindUid          = Request.Form["bindUid"].ToString();
         string bindComputerName = Request.Form["bindComputerName"].ToString();
         if (string.IsNullOrEmpty(bindUid))
         {
             return(Problem("绑定Uid不允许为空"));
         }
         SugarHandler db      = new SugarHandler();
         var          machine = db.Single <retail_machine>(x => x.Id == machineId && x.CompanyId == companyId);
         if (machine == null)
         {
             return(Problem("查询不到对应的机器"));
         }
         if (!string.IsNullOrEmpty(machine.BindUid) && !machine.BindUid.Equals(bindUid, StringComparison.OrdinalIgnoreCase))
         {
             return(Problem("该机器号已被绑定"));
         }
         db.Update <retail_machine>(x => new retail_machine()
         {
             BindUid = bindUid, BindComputerName = bindComputerName
         }, q => q.Id == machineId, false);
         return(Ok("机器绑定成功"));
     }
     catch (SqlSugar.SqlSugarException ex)
     {
         return(Problem(ex.Message));
     }
 }
Exemplo n.º 2
0
 public IActionResult GetCompanyInfo()
 {
     try
     {
         string code = Request.Form["code"].ToString();
         if (string.IsNullOrEmpty(code))
         {
             return(Problem("参数有误"));
         }
         SugarHandler db      = new SugarHandler();
         var          company = db.Single <retail_company>(x => x.UniqueCode == code);
         if (company == null || company.Id == 0)
         {
             return(Problem("编码有误"));
         }
         var machines  = db.GetList <retail_machine>(x => x.CompanyId == company.Id);
         var employees = db.GetList <retail_employee>(x => x.CompanyId == company.Id);
         Dictionary <string, object> dict = new Dictionary <string, object>();
         dict["Company"]   = company;
         dict["Machines"]  = machines;
         dict["Employees"] = employees;
         return(Ok(dict));
     }
     catch (SqlSugar.SqlSugarException ex)
     {
         return(Problem(ex.Message));
     }
 }
Exemplo n.º 3
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (context == null)
            {
                return;
            }
            var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;

            if (controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true)
                .Any(a => a.GetType().Equals(typeof(NoCompanyRequiredAttribute))))
            {
                return;
            }
            if (context.ModelState.IsValid)
            {
                var companyId  = context.HttpContext.Request.Headers["CompanyId"].ToString().ToInt();
                var companyPid = context.HttpContext.Request.Headers["CompanyPid"].ToString().ToInt();
                var isValid    = companyId > 0;
                if (isValid)
                {
                    try
                    {
                        SugarHandler db      = new SugarHandler();
                        var          company = db.Single <retail_company>(x => x.Id == companyId);
                        isValid = company != null && company.ParentId == companyPid;
                    }
                    catch (Exception ex)
                    {
                        LogHelper.WriteErrorLog(LogType.BASE, ex);
                        isValid = false;
                    }
                }
                if (!isValid)
                {
                    context.Result = new ObjectResult(new ProblemDetails()
                    {
                        Detail = "企业信息不正确"
                    });
                }
            }
        }
Exemplo n.º 4
0
        public IActionResult OrderInfoUpload()
        {
            var companyId  = Request.Headers["CompanyId"].ToString().ToInt();
            var companyPid = Request.Headers["CompanyPid"].ToString().ToInt();

            HttpContext.Response.ContentType = "application/json";
            string jsonOrder = "";

            using (var sr = new StreamReader(Request.Body, Encoding.UTF8))
            {
                var v = sr.ReadToEndAsync();//或者sr.ReadToEnd()
                                v.Wait();

                jsonOrder = v.Result;
            }
            JObject      orderObj   = (JObject)JsonConvert.DeserializeObject(jsonOrder);
            string       orderNum   = orderObj["OrderNum"].ToString();
            SugarHandler db         = new SugarHandler();
            var          orderModel = db.Single <retail_order>(x => x.OrderNum == orderNum);

            if (orderModel == null)
            {
                orderModel = new retail_order();
            }
            orderModel = orderObj.JObjectTransToModel <retail_order>();
            JArray jArray = (JArray)JsonConvert.DeserializeObject(orderObj["OrderDetail"].ObjToString());
            List <retail_order_item> orderDetails = new List <retail_order_item>();

            foreach (var item in jArray)
            {
                retail_order_item orderDetail = new retail_order_item();
                orderDetail = item.JTokenTransToModel <retail_order_item>();
                orderDetails.Add(orderDetail);
            }
            db.BeginTran();
            try
            {
                if (orderModel.Id > 0)
                {
                    db.Update <retail_order>(x => new retail_order()
                    {
                        CustomId = orderModel.CustomId, CustomName = orderModel.CustomName, Relation = orderModel.Relation, RelationPhone = orderModel.RelationPhone, Address = orderModel.Address, PayMentType = orderModel.PayMentType, OriginalPrice = orderModel.OriginalPrice, OrderDiscount = orderModel.OrderDiscount, OrderDiscountAmount = orderModel.OrderDiscountAmount, ReceivePrice = orderModel.ReceivePrice, PayStatus = orderModel.PayStatus, PayDate = orderModel.PayDate, OrderStatus = orderModel.OrderStatus, Remark = orderModel.Remark, SaleMan = orderModel.SaleMan
                    }, q => q.Id == orderModel.Id, false);
                }
                else
                {
                    orderModel.Id = db.AddReturnId(orderModel);
                }
                foreach (var item in orderDetails)
                {
                    var existsItem = db.Single <retail_order_item>(x => x.OrderNum == item.OrderNum && x.ItemGuid == item.ItemGuid);
                    if (existsItem != null && existsItem.Id > 0)
                    {
                        db.Update <retail_order_item>(x => new retail_order_item()
                        {
                            ProductId = item.ProductId, ProductName = item.ProductName, ProductUnitName = item.ProductUnitName, SizeId = item.SizeId, SizeName = item.SizeName, IsSingleSize = item.IsSingleSize, OriginalPrice = item.OriginalPrice, ItemDiscount = item.ItemDiscount, ItemDiscountPrice = item.ItemDiscountPrice, PromotionPrice = item.PromotionPrice, BuyPrice = item.BuyPrice, BuyCount = item.BuyCount, PackUnitName = item.PackUnitName, ConversionValue = item.ConversionValue, ProductDescription = item.ProductDescription, Remark = item.Remark
                        }, q => q.Id == existsItem.Id, false);
                    }
                    else
                    {
                        item.CreateDate = AppSetting.TimeNow;
                        item.Id         = db.AddReturnId(item);
                    }
                }
                return(Ok("订单上传成功"));
            }
            catch (SqlSugar.SqlSugarException ex)
            {
                return(Problem(ex.Message));
            }
        }