Example #1
0
 public int AddShopCar(ShopCarEntity car, string loginName)
 {
     using (IDbConnection conn = DBContext.GetConnection(DataBaseName.AccountTrianDB, ReadOrWriteDB.Write))
     {
         string query = string.Format(@"INSERT INTO Train_ShopCar
                                        (ShopCarId
                                        ,Openid
                                        ,ClassId
                                        ,Status
                                        ,CreateTime
                                        ,CreateUser
                                        ,UpdateTime
                                        ,UpdateUser)
                                  VALUES
                                        ('{0}'
                                        ,'{1}'
                                        ,'{2}'
                                        ,'{3}'
                                        ,getdate()
                                        ,'{4}'
                                        ,getdate()
                                        ,'{5}')",
                                      Guid.NewGuid().ToString(), car.Openid, car.ClassId, 1, loginName, loginName);
         return(conn.Execute(query));
     }
 }
Example #2
0
        public ActionResult AddCar(string openid, string classId)
        {
            //判断是否注册
            //var userInfo = new WxUserBC().GetWxUserByOpenid(openid);
            //if (userInfo==null ||string.IsNullOrEmpty(userInfo.Phone))
            //{
            //    Response.Redirect(CommonHelper.GetRedirect("WxMy%2fRegistered"));
            //}

            ShopCarEntity entity = new ShopCarEntity()
            {
                Openid  = openid,
                ClassId = classId
            };

            var model = new ShopCarBC().GetMyShopByopenIdAndclassId(openid, classId);

            if (model != null)
            {
                return(Json("已加入购物车", JsonRequestBehavior.AllowGet));
            }

            var result = new ShopCarBC().AddShopCar(entity, openid);

            if (result > 0)
            {
                return(Json("更新成功", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(string.Empty, JsonRequestBehavior.AllowGet));
            }
        }
        /// <summary>
        /// 根据用户名查询购物车ID
        /// </summary>
        public async Task <GetShopCarResponse> GetShopCarAsync([FromBody] GetShopCarRequest request)
        {
            GetShopCarResponse response = new GetShopCarResponse();

            try
            {
                var customer = _context.CustomerEntitys.FirstOrDefault(a => a.CustomerPhone == request.UserName);
                if (customer != null)
                {
                    var shopCar = await _context.ShopCarEntitys.SingleOrDefaultAsync(a => a.UserId == customer.CustomerID);

                    if (shopCar == null)
                    {
                        shopCar = new ShopCarEntity
                        {
                            UserId = customer.CustomerID
                        };
                        _context.Add(shopCar);
                        await _context.SaveChangesAsync();
                    }
                    shopCar = await _context.ShopCarEntitys.SingleOrDefaultAsync(a => a.UserId == customer.CustomerID);

                    response.UserId = customer.CustomerID;
                    response.CarId  = shopCar.PKID;
                }
            }
            catch (Exception ex)
            {
                response.Successful = false;
                response.Message    = ex.Message;
                logger.LogError(ex, $"GetShopCarAsync 方法报错 Message:{JsonConvert.SerializeObject(request)}");
            }

            return(response);
        }
        public async Task <GetShopListResponse> GetShopListAsync([FromBody] GetShopListRequest request)
        {
            GetShopListResponse response = new GetShopListResponse();

            try
            {
                var customer = _context.CustomerEntitys.FirstOrDefault(a => a.CustomerPhone == request.UserName);
                if (customer != null)
                {
                    var shopCar = _context.ShopCarEntitys.SingleOrDefault(a => a.UserId == customer.CustomerID);
                    if (shopCar == null)
                    {
                        shopCar = new ShopCarEntity
                        {
                            UserId = customer.CustomerID
                        };
                        _context.Add(shopCar);
                        _context.SaveChanges();
                    }
                    shopCar = _context.ShopCarEntitys.SingleOrDefault(a => a.UserId == customer.CustomerID);
                    ResetCheck(shopCar.PKID);
                    var query = (from cl in _context.CarListEntitys
                                 join v in _context.VersionInfoEntitys
                                 on cl.VersionID equals v.ProductID
                                 join p in _context.ProductEntities
                                 on cl.ProductID equals p.ProductID
                                 where cl.CarID == shopCar.PKID
                                 select new ShopList
                    {
                        CarID = cl.CarID,
                        ProductID = p.ProductID,
                        ProductName = p.ProductName,
                        VersionID = cl.VersionID,
                        versionInfo = v.VersionInfo,
                        Price = cl.UnitPrice,
                        Count = cl.Count,
                        ProductImg = p.ProductImg,
                        Subtotal = cl.UnitPrice * cl.Count
                    }).ToList();

                    response.TotalPrice = query.Sum(a => a.Subtotal);
                    response.ShopCount  = query.Sum(a => a.Count);

                    response.ShopLists.AddRange(query);
                }
            }
            catch (Exception ex)
            {
                response.Successful = false;
                response.Message    = ex.Message;
                logger.LogError(ex, $"GetShopListAsync 方法报错 Message:{JsonConvert.SerializeObject(request)}");
            }
            return(response);
        }
Example #5
0
        public int AddShopCar(ShopCarEntity car, string loginName)
        {
            var da = new ShopCarDA();

            return(da.AddShopCar(car, loginName));
        }
Example #6
0
        public ActionResult GetPageListJson(Pagination pagination, string queryJson)
        {
            var           watch = CommonHelper.TimerStart();
            ShopCarEntity para  = new ShopCarEntity();

            if (!string.IsNullOrWhiteSpace(queryJson))
            {
                var queryParam = queryJson.ToJObject();
                //类型
                if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty())
                {
                    var condition = queryParam["condition"].ToString().ToLower();
                    switch (condition)
                    {
                    case "name":
                        para.Name = queryParam["keyword"].ToString();
                        break;

                    case "shopname":
                        para.ShopName = queryParam["keyword"].ToString();
                        break;

                    case "sortdesc":
                        para.SortDesc = queryParam["keyword"].ToString();
                        break;
                    }
                }
            }

            var pageList = ShopCarBLL.Instance.GetPageList(para, ref pagination);

            if (pageList != null)
            {
                pageList.ForEach((o) =>
                {
                    if (o.ShopCarId != null)
                    {
                        o.WeekSeeCarOrderCount = SeeCarOrderBLL.Instance.GetList(new SeeCarOrderEntity()
                        {
                            ShopCarId = o.ShopCarId,
                            StartTime = Util.Time.CalculateFirstDateOfWeek(DateTime.Now).ToString(),
                            EndTime   = Util.Time.CalculateLastDateOfWeek(DateTime.Now).ToString()
                        }).Count();
                        o.TotalSeeCarOrderCount = SeeCarOrderBLL.Instance.GetList(new SeeCarOrderEntity()
                        {
                            ShopCarId = o.ShopCarId
                        }).Count();
                    }
                });
            }
            var JsonData = new
            {
                rows     = pageList,
                total    = pagination.total,
                page     = pagination.page,
                records  = pagination.records,
                costtime = CommonHelper.TimerEnd(watch)
            };

            return(Content(JsonData.ToJson()));
        }
Example #7
0
        /// <summary>
        /// 导出EXCEL
        /// </summary>
        public void ExportExcel(string queryJson)
        {
            string cacheKey = Request["cacheid"] as string;

            HttpRuntime.Cache[cacheKey + "-state"] = "processing";
            HttpRuntime.Cache[cacheKey + "-row"]   = "0";
            try
            {
                //这里要url解码
                var           queryParam = Server.UrlDecode(queryJson).ToJObject();
                ShopCarEntity para       = new ShopCarEntity();
                //类型
                if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty())
                {
                    var condition = queryParam["condition"].ToString().ToLower();
                    switch (condition)
                    {
                    case "name":
                        para.Name = queryParam["keyword"].ToString();
                        break;

                    case "shopname":
                        para.ShopName = queryParam["keyword"].ToString();
                        break;

                    case "sortdesc":
                        para.SortDesc = queryParam["keyword"].ToString();
                        break;
                    }
                }
                var list = ShopCarBLL.Instance.GetList(para);
                if (list != null)
                {
                    list.ForEach((o) =>
                    {
                        if (o.ShopCarId != null)
                        {
                            o.WeekSeeCarOrderCount = SeeCarOrderBLL.Instance.GetList(new SeeCarOrderEntity()
                            {
                                ShopCarId = o.ShopCarId,
                                StartTime = Util.Time.CalculateFirstDateOfWeek(DateTime.Now).ToString(),
                                EndTime   = Util.Time.CalculateLastDateOfWeek(DateTime.Now).ToString()
                            }).Count();
                            o.TotalSeeCarOrderCount = SeeCarOrderBLL.Instance.GetList(new SeeCarOrderEntity()
                            {
                                ShopCarId = o.ShopCarId
                            }).Count();
                        }
                        if (o.LimitPrice != null && o.MaxPrice != null)
                        {
                            o.ConsultPrice = o.LimitPrice + "~" + o.MaxPrice;
                        }
                        if (o.Status != null)
                        {
                            o.StatusName = ((RCHL.Model.Enums.UseStatus)o.Status).ToString();
                        }
                    });

                    //设置导出格式
                    ExcelConfig excelconfig = new ExcelConfig();
                    excelconfig.Title           = "车辆信息";
                    excelconfig.TitleFont       = "微软雅黑";
                    excelconfig.TitlePoint      = 10;
                    excelconfig.FileName        = "车辆信息.xls";
                    excelconfig.IsAllSizeColumn = true;
                    //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
                    List <ColumnEntity> listColumnEntity = new List <ColumnEntity>();
                    excelconfig.ColumnEntity = listColumnEntity;
                    ColumnEntity columnentity = new ColumnEntity();
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "Name", ExcelColumn = "车辆名称", Width = 20
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "BrandName", ExcelColumn = "品牌名称", Width = 20
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "ShopName", ExcelColumn = "所属车店", Width = 15
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "ConsultPrice", ExcelColumn = "参考价", Width = 15
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "SortDesc", ExcelColumn = "车辆简介", Width = 15
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "WeekSeeCarOrderCount", ExcelColumn = "本周被预约次数", Width = 15
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "TotalSeeCarOrderCount", ExcelColumn = "总被预约次数", Width = 15
                    });
                    excelconfig.ColumnEntity.Add(new ColumnEntity()
                    {
                        Column = "StatusName", ExcelColumn = "状态", Width = 15
                    });
                    //需合并索引
                    //excelconfig.MergeRangeIndexArr = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };

                    //调用导出方法
                    ExcelHelper <ShopCarEntity> .ExcelDownload(list, excelconfig);

                    HttpRuntime.Cache[cacheKey + "-state"] = "done";
                }
            }
            catch (Exception)
            {
                HttpRuntime.Cache[cacheKey + "-state"] = "error";
            }
        }