Exemple #1
0
        /// <summary>
        /// 获取分销员列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="strOrder"></param>
        /// <returns></returns>
        public List <SalesMan> GetListSalesMan(string strWhere, int pageIndex = 1, int pageSize = 10, string strOrder = "")
        {
            string sql = $"select m.*,u.NickName from SalesMan m  LEFT join C_UserInfo u on m.UserId=u.Id   where {strWhere} group by m.userId order by {strOrder} LIMIT {(pageIndex - 1) * pageSize},{pageSize}";

            using (var dr = SqlMySql.ExecuteDataReader(Utility.dbEnum.MINIAPP.ToString(), CommandType.Text, sql))
            {
                List <SalesMan> list = new List <SalesMan>();
                while (dr.Read())
                {
                    SalesMan salesMan = GetModel(dr);
                    if (salesMan != null && salesMan.Id > 0)
                    {
                        salesMan.nickName   = (dr["NickName"] == DBNull.Value ? string.Empty : dr["NickName"].ToString());
                        salesMan.orderCount = VipRelationBLL.SingleModel.GetEntGoodsOrderCount(salesMan.UserId);
                        VipRelation vip = VipRelationBLL.SingleModel.GetModel($"uid={salesMan.UserId}");
                        if (vip != null)
                        {
                            salesMan.orderPrice = vip.pricestr;
                        }
                        else
                        {
                            salesMan.orderPrice = "0.00";
                        }
                        salesMan = GetSalesMan(salesMan);
                        list.Add(salesMan);
                    }
                }
                return(list.Count > 0 ? list : null);
            }
        }
Exemple #2
0
        public PayContentPayment GetVipDiscountByUserId(PayContent content, int userId)
        {
            //会员等级信息
            VipRelation vipInfo   = VipRelationBLL.SingleModel.GetModel($"uid={userId} and state>=0");
            VipLevel    levelInfo = levelInfo = vipInfo != null?VipLevelBLL.SingleModel.GetModel($"id={vipInfo.levelid} and state>=0") : null;

            return(GetVipDiscount(content, levelInfo));
        }
Exemple #3
0
        public void GetVipDiscount <T>(ref List <T> list, VipRelation vipInfo, VipLevel levelinfo, int userid, string discountstr, string pricestr)
        {
            if (list == null || list.Count <= 0)
            {
                return;
            }

            //VipRelation vipInfo = VipRelationBLL.SingleModel.GetModelByUserid(userid);
            if (vipInfo == null)
            {
                return;
            }

            //VipLevel levelinfo = base.GetModel(vipInfo.levelid);
            if (levelinfo == null)
            {
                return;
            }

            if (levelinfo.type == 1)//全场打折
            {
                foreach (T orderitem in list)
                {
                    int price = Convert.ToInt32(orderitem.GetType().GetProperty(pricestr).GetValue(orderitem).ToString());
                    orderitem.GetType().GetProperty(discountstr).SetValue(orderitem, levelinfo.discount);
                    orderitem.GetType().GetProperty(pricestr).SetValue(orderitem, Convert.ToInt32(price * (levelinfo.discount * 0.01)) < 1 ? 1 : Convert.ToInt32(price * (levelinfo.discount * 0.01)));
                }
            }
            else if (levelinfo.type == 2)//部分打折
            {
                List <string> gids = levelinfo.gids.Split(',').ToList();
                foreach (T orderitem in list)
                {
                    string goodsId = orderitem.GetType().GetProperty("GoodsId").GetValue(orderitem).ToString();
                    if (gids.Contains(goodsId))
                    {
                        int price = Convert.ToInt32(orderitem.GetType().GetProperty(pricestr).GetValue(orderitem).ToString());
                        orderitem.GetType().GetProperty(discountstr).SetValue(orderitem, levelinfo.discount);
                        orderitem.GetType().GetProperty(pricestr).SetValue(orderitem, Convert.ToInt32(price * (levelinfo.discount * 0.01)) < 1 ? 1 : Convert.ToInt32(price * (levelinfo.discount * 0.01)));
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// 处理计算商品的会员价格(通用版:目前专业版在用)
        /// </summary>
        /// <param name="carts"></param>
        /// <param name="uid"></param>
        public void CalculateVipGoodsCartPrice(List <EntGoodsCart> carts, int uid)
        {
            if (!CheckList(carts))
            {
                return;
            }
            carts.ForEach(g => g.originalPrice = g.Price);
            //获取会员信息
            VipRelation vipInfo = VipRelationBLL.SingleModel.GetModel($"uid={uid} and state>=0");

            if (vipInfo == null)
            {
                return;
            }
            VipLevel levelinfo = new VipLevelBLL().GetModel($"id={vipInfo.levelid} and state>=0");

            if (levelinfo == null)
            {
                return;
            }
            switch (levelinfo.type)
            {
            case 1:    //全场打折
                carts.ForEach(g =>
                {
                    g.discount = levelinfo.discount;
                    g.Price    = Convert.ToInt32(g.Price * (levelinfo.discount * 0.01)) < 1 ? 1 : Convert.ToInt32(g.Price * (levelinfo.discount * 0.01));
                });
                break;

            case 2:    //部分打折
                List <string> gids = levelinfo.gids.Split(',').ToList();
                carts.ForEach(g =>
                {
                    if (gids.Contains(g.FoodGoodsId.ToString()))
                    {
                        g.discount = levelinfo.discount;
                        g.Price    = Convert.ToInt32(g.Price * (levelinfo.discount * 0.01)) < 1 ? 1 : Convert.ToInt32(g.Price * (levelinfo.discount * 0.01));
                    }
                });
                break;
            }
        }
Exemple #5
0
        /// <summary>
        /// 优惠金额处理
        /// </summary>
        /// <param name="couponLogId">用户领取优惠券id</param>
        /// <param name="cartList">购物车</param>
        /// <param name="userId">用户ID</param>
        /// <param name="beforeDiscountPrice">优惠前商品总价</param>
        /// <param name="afterDiscountPrice">优惠后商品总价</param>
        /// <param name="vipDiscountPrice">会员优惠价</param>
        /// <param name="couponPrice">优惠券优惠价格</param>
        public void DiscountPrice(int couponLogId, ref List <QiyeGoodsCart> cartList, int userId, ref int beforeDiscountPrice, ref int afterDiscountPrice, ref int vipDiscountPrice, ref int couponPrice, ref string msg)
        {
            beforeDiscountPrice = cartList.Sum(x => x.Price * x.Count);

            #region 会员打折
            cartList.ForEach(g => g.OriginalPrice = g.Price);
            //获取会员信息
            VipRelation vipInfo   = VipRelationBLL.SingleModel.GetModelByUserid(userId);
            VipLevel    levelInfo = vipInfo != null?VipLevelBLL.SingleModel.GetModel(vipInfo.levelid) : null;

            VipLevelBLL.SingleModel.GetVipDiscount(ref cartList, vipInfo, levelInfo, userId, "Discount", "Price");
            #endregion 会员打折

            //折后总价
            afterDiscountPrice = cartList.Sum(x => x.Price * x.Count);
            //会员优惠金额
            vipDiscountPrice = beforeDiscountPrice - afterDiscountPrice;

            //优惠金额
            couponPrice = CouponLogBLL.SingleModel.GetCouponPrice <QiyeGoodsCart>(couponLogId, cartList, "GoodsId", "Price", "Count", ref msg);

            afterDiscountPrice = afterDiscountPrice - couponPrice;
            afterDiscountPrice = afterDiscountPrice < 0 ? 0 : afterDiscountPrice;
        }
        public ActionResult GetGoodInfo()
        {
            int pid    = Context.GetRequestInt("pid", 0);
            int userId = Context.GetRequestInt("userId", 0);

            returnObj      = new Return_Msg_APP();
            returnObj.code = "200";

            if (pid == 0)
            {
                returnObj.Msg = "请选择产品";
                return(Json(returnObj, JsonRequestBehavior.AllowGet));
            }

            PlatChildGoods goodModel = PlatChildGoodsBLL.SingleModel.GetModel(pid);

            if (goodModel == null || goodModel.State == 0)
            {
                returnObj.Msg = "产品不存在或已删除";
                return(Json(returnObj, JsonRequestBehavior.AllowGet));
            }

            PlatStore platStore = PlatStoreBLL.SingleModel.GetModelByAId(goodModel.AId);

            if (platStore == null)
            {
                returnObj.Msg = "店铺不存在";
                return(Json(returnObj, JsonRequestBehavior.AllowGet));
            }

            if (!string.IsNullOrEmpty(goodModel.Plabels))
            {
                //goodModel.plabelstr = DAL.Base.SqlMySql.ExecuteScalar(Utility.dbEnum.MINIAPP.ToString(), CommandType.Text, $"SELECT group_concat(name order by sort desc) from entgoodlabel where id in ({goodModel.plabels})").ToString();
                goodModel.PlabelStr      = PlatChildGoodsLabelBLL.SingleModel.GetEntGoodsLabelStr(goodModel.Plabels);
                goodModel.PlabelStr_Arry = goodModel.PlabelStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            }

            #region 会员折扣显示
            //获取会员信息
            VipRelation vipInfo   = VipRelationBLL.SingleModel.GetModelByUserid(userId);
            VipLevel    levelinfo = vipInfo != null?VipLevelBLL.SingleModel.GetModel(vipInfo.levelid) : null;

            List <PlatChildGoods> list = new List <PlatChildGoods>();
            list.Add(goodModel);
            //  _miniappVipLevelBll.GetVipDiscount(ref list, vipInfo, levelinfo, userId, "Discount", "Price");
            goodModel = list.FirstOrDefault();

            #endregion 会员折扣显示

            //#region 会员打折
            List <PlatChildGoodsCart> carlist = new List <PlatChildGoodsCart>()
            {
                new PlatChildGoodsCart()
                {
                    GoodsId = goodModel.Id
                }
            };
            carlist.ForEach(g => g.OriginalPrice = g.Price);
            VipLevelBLL.SingleModel.GetVipDiscount(ref carlist, vipInfo, levelinfo, userId, "Discount", "Price");
            goodModel.Discount = carlist[0].Discount;
            //#endregion 会员打折

            if (!string.IsNullOrEmpty(goodModel.Img))
            {
                goodModel.Img = goodModel.Img.Replace("http://vzan-img.oss-cn-hangzhou.aliyuncs.com", "https://i.vzan.cc/");
            }

            List <GoodsSpecDetail> listGoodsSpecDetail = Newtonsoft.Json.JsonConvert.DeserializeObject <List <GoodsSpecDetail> >(goodModel.SpecDetail);
            listGoodsSpecDetail.ForEach(x =>
            {
                if (x.Discount == 100)
                {
                    x.DiscountPrice = x.Price;
                }
            });

            goodModel.SpecDetail = JsonConvert.SerializeObject(listGoodsSpecDetail);
            goodModel.storeModel = new StoreModel()
            {
                StoreId = platStore.Id,
                Name    = platStore.Name,
                Img     = platStore.StoreHeaderImg,
                Loction = platStore.Location,
                Lng     = platStore.Lng,
                Lat     = platStore.Lat
            };

            PlatMyCard platMyCard = PlatMyCardBLL.SingleModel.GetModel(platStore.MyCardId);
            if (platMyCard != null)
            {
                goodModel.storeOwner = new StoreOwner()
                {
                    UserId = platMyCard.UserId,
                    Name   = platMyCard.Name,
                    Avatar = platMyCard.ImgUrl
                };

                PlatUserCash userCash = PlatUserCashBLL.SingleModel.GetModelByUserId(platMyCard.AId, platMyCard.UserId);
                if (userCash != null)
                {
                    goodModel.storeOwner.IsOpenDistribution = userCash.IsOpenDistribution;
                }
            }

            returnObj.isok    = true;
            returnObj.dataObj = goodModel;
            returnObj.Msg     = "获取成功";
            return(Json(returnObj, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 产品列表
        /// </summary>
        /// <param name="appid"></param>
        /// <param name="typeid"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public ActionResult GetGoodsList(int aid, string typeid = "", int pageindex = 1, int pagesize = 10, int userId = 0, int isFirstType = -1)
        {
            returnObj      = new Return_Msg_APP();
            returnObj.code = "200";
            string goodsName      = Context.GetRequest("goodsName", "");
            string priceSort      = Context.GetRequest("pricesort", "");
            string entGoodTypeIds = string.Empty;

            if (!string.IsNullOrEmpty(typeid))
            {
                typeid = EncodeHelper.ReplaceSqlKey(typeid);
                typeid = Server.UrlDecode(typeid);
            }
            List <PlatChildGoods> goodslist = PlatChildGoodsBLL.SingleModel.GetListGoods(aid, goodsName, typeid, priceSort, pagesize, pageindex, isFirstType);

            //log4net.LogHelper.WriteInfo(this.GetType(), JsonConvert.SerializeObject(goodslist));
            if (goodslist != null)
            {
                goodslist.ForEach((Action <PlatChildGoods>)(goodModel =>
                {
                    if (!string.IsNullOrEmpty(goodModel.Categorys))
                    {
                        goodModel.CategorysStr = PlatChildGoodsCategoryBLL.SingleModel.GetPlatChildGoodsCategoryName(goodModel.Categorys);
                    }

                    if (!string.IsNullOrEmpty(goodModel.Plabels))
                    {
                        goodModel.PlabelStr      = PlatChildGoodsLabelBLL.SingleModel.GetGoodsLabel(goodModel.Plabels);
                        goodModel.PlabelStr_Arry = goodModel.PlabelStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    }

                    List <GoodsSpecDetail> listGoodsSpecDetail = Newtonsoft.Json.JsonConvert.DeserializeObject <List <GoodsSpecDetail> >(goodModel.SpecDetail);
                    if (listGoodsSpecDetail != null)
                    {
                        listGoodsSpecDetail.ForEach(x =>
                        {
                            if (x.Discount == 100)
                            {
                                x.DiscountPrice = x.Price;
                            }
                        });


                        goodModel.SpecDetail = JsonConvert.SerializeObject(listGoodsSpecDetail);
                    }
                }));

                //获取会员信息
                VipRelation vipInfo   = VipRelationBLL.SingleModel.GetModelByUserid(userId);
                VipLevel    levelinfo = vipInfo != null?VipLevelBLL.SingleModel.GetModel(vipInfo.levelid) : null;

                //#region 会员打折

                VipLevelBLL.SingleModel.GetVipDiscount(ref goodslist, vipInfo, levelinfo, userId, "Discount", "Price");
            }
            var postdata = new
            {
                goodslist = goodslist.Select(g => new
                {
                    Id                = g.Id,
                    Img               = g.Img,
                    Name              = g.Name,
                    Plabelstr_array   = g.PlabelStr_Arry,
                    PriceFen          = g.PriceFen,
                    DiscountPricestr  = g.DiscountPricestr,
                    Discount          = g.Discount,
                    Unit              = g.Unit,
                    VirtualSalesCount = g.VirtualSalesCount,
                    SalesCount        = g.SalesCount,
                    Price             = g.Price
                }),
            };

            returnObj.isok    = true;
            returnObj.dataObj = postdata;
            return(Json(returnObj, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 查询购物车
        /// </summary>
        /// <param name="appid"></param>
        /// <param name="openid"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public ActionResult GetGoodsCarList()
        {
            returnObj = new Return_Msg_APP();
            int pageSize  = Context.GetRequestInt("pageSize", 6);
            int pageIndex = Context.GetRequestInt("pageIndex", 1);
            int userId    = Context.GetRequestInt("userid", 0);

            try
            {
                C_UserInfo userInfo = C_UserInfoBLL.SingleModel.GetModel(userId);
                if (userInfo == null)
                {
                    returnObj.Msg = "用户不存在";
                    return(Json(returnObj));
                }

                XcxAppAccountRelation xcxrelation = _xcxAppAccountRelationBLL.GetModelByAppid(userInfo.appId);
                if (xcxrelation == null)
                {
                    returnObj.Msg = "未绑定小程序或模板已过期";
                    return(Json(returnObj));
                }

                List <PlatChildGoodsCart> carList = PlatChildGoodsCartBLL.SingleModel.GetListByUserId(xcxrelation.Id, userInfo.Id, pageSize, pageIndex);

                if (carList == null || carList.Count <= 0)
                {
                    returnObj.Msg = "购物车为空";
                    return(Json(returnObj));
                }

                //获取会员信息
                VipRelation vipInfo   = VipRelationBLL.SingleModel.GetModelByUserid(userInfo.Id);
                VipLevel    levelInfo = vipInfo != null?VipLevelBLL.SingleModel.GetModel(vipInfo.levelid) : null;

                //#region 会员打折
                carList.ForEach(g => g.OriginalPrice = g.Price);
                VipLevelBLL.SingleModel.GetVipDiscount(ref carList, vipInfo, levelInfo, userInfo.Id, "Discount", "Price");
                //#endregion 会员打折

                //获取商品详细资料
                List <PlatChildGoods> goods = new List <PlatChildGoods>();
                goods = PlatChildGoodsBLL.SingleModel.GetList($" Id in ({string.Join(",", carList.Select(x => x.GoodsId))}) ");

                if (goods == null || goods.Count <= 0)
                {
                    returnObj.Msg     = "商品已过期";
                    returnObj.dataObj = carList;
                    return(Json(returnObj));
                }

                PlatChildGoods curGood = new PlatChildGoods();
                carList.ForEach(c =>
                {
                    curGood = goods.FirstOrDefault(g => g.Id == c.GoodsId);
                    if (curGood != null && curGood.Id > 0)
                    {
                        //多规格处理
                        if (curGood.GASDetailList != null && curGood.GASDetailList.Count > 0)
                        {
                            List <GoodsSpecDetail> detaillist = curGood.GASDetailList.ToList();
                            detaillist?.ForEach(g =>
                            {
                                g.OriginalPrice     = g.Price;
                                g.Discount          = c.Discount;
                                float discountPrice = g.Price * (c.Discount * 0.01F);
                                g.DiscountPrice     = discountPrice < 0.01 ? 0.01F : discountPrice;
                            });
                            curGood.SpecDetail = JsonConvert.SerializeObject(detaillist);
                        }
                        curGood.Description = string.Empty;
                        c.GoodsInfo         = curGood;
                    }
                });

                returnObj.dataObj = new { carlist = carList, count = carList.Sum(s => s.Count) };
                returnObj.isok    = true;
                return(Json(returnObj));
            }
            catch (Exception ex)
            {
                returnObj.dataObj = ex;
                return(Json(returnObj));
            }
        }
Exemple #9
0
        public ActionResult GetCoupon()
        {
            string appId    = Context.GetRequest("appId", string.Empty);
            int    couponId = Context.GetRequestInt("couponId", 0);
            int    userId   = Context.GetRequestInt("userId", 0);

            if (couponId <= 0)
            {
                return(Json(new { isok = false, msg = "优惠券ID不能小于0" }, JsonRequestBehavior.AllowGet));
            }
            if (userId <= 0)
            {
                return(Json(new { isok = false, msg = "用户ID不能小于0" }, JsonRequestBehavior.AllowGet));
            }
            C_UserInfo usermodel = C_UserInfoBLL.SingleModel.GetModel(userId);

            if (usermodel == null)
            {
                return(Json(new { isok = false, msg = "找不到用户" }, JsonRequestBehavior.AllowGet));
            }

            XcxAppAccountRelation xcxrelation = _xcxAppAccountRelationBLL.GetModelByAppid(appId);

            if (xcxrelation == null)
            {
                return(Json(new { isok = false, msg = "未找到小程序授权资料" }, JsonRequestBehavior.AllowGet));
            }

            string userids = "";
            string aids    = "";
            string errMsg  = string.Empty;
            //店铺ID
            int storeId = _xcxAppAccountRelationBLL.ReturnStoreIdByAId(xcxrelation.Id, ref errMsg, ref aids, ref userids);

            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                return(Json(new { isok = false, errMsg }, JsonRequestBehavior.AllowGet));
            }

            lock (lockgetcoupon)
            {
                string  nowtime     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                Coupons couponmodel = CouponsBLL.SingleModel.GetValidModel(couponId, nowtime);
                if (couponmodel == null)
                {
                    return(Json(new { isok = false, msg = "找不到优惠券!" }, JsonRequestBehavior.AllowGet));
                }

                int couponlogcount = CouponLogBLL.SingleModel.GetCountByCouponId(couponId);
                if (couponlogcount >= couponmodel.CreateNum)
                {
                    return(Json(new { isok = false, msg = "您下手太慢了,优惠券被抢光了!" }, JsonRequestBehavior.AllowGet));
                }

                //判断用户领取是否超过限制
                if (couponmodel.LimitReceive > 0)
                {
                    int usercouponlogcount = CouponLogBLL.SingleModel.GetCountByCouponIdAndUserId(couponId, userId);
                    if (usercouponlogcount >= couponmodel.LimitReceive)
                    {
                        return(Json(new { isok = false, msg = "您已领取过了,快去使用!" }, JsonRequestBehavior.AllowGet));
                    }
                }

                //判断有会员等级限制
                if (couponmodel.VipLevel > 0)
                {
                    VipRelation viprelationmodel = VipRelationBLL.SingleModel.GetModelByRidAndUid(xcxrelation.AppId, userId);
                    if (viprelationmodel != null)
                    {
                        VipLevel viplevel = VipLevelBLL.SingleModel.GetModel(viprelationmodel.levelid);
                        if (viplevel == null || viplevel.level < couponmodel.VipLevel)
                        {
                            return(Json(new { isok = false, msg = "您的会员等级不够,无法领取优惠券!" }, JsonRequestBehavior.AllowGet));
                        }
                    }
                }

                CouponLog couponlog = new CouponLog();
                couponlog.AddTime  = DateTime.Now;
                couponlog.CouponId = couponmodel.Id;

                if (couponmodel.ValType == 0)
                {
                    //指定优惠券固定时间
                    couponlog.StartUseTime = couponmodel.StartUseTime;
                    couponlog.EndUseTime   = couponmodel.EndUseTime;
                }
                else
                {
                    //领券时间
                    string getcouptime = DateTime.Now.ToShortDateString();
                    //1:领到券次日开始N天内有效,2:领到券当日开始N天内有效
                    couponlog.StartUseTime = DateTime.Parse(getcouptime + " 00:00:00").AddDays(couponmodel.ValType == 1 ? 1 : 0);
                    couponlog.EndUseTime   = DateTime.Parse(getcouptime + " 23:59:59").AddDays(couponmodel.ValDay + (couponmodel.ValType == 1 ? 0 : -1));
                }

                couponlog.CouponName = couponmodel.CouponName;
                couponlog.UserId     = userId;

                couponlog.Id = Convert.ToInt32(CouponLogBLL.SingleModel.Add(couponlog));

                return(Json(new { isok = couponlog.Id > 0, msg = couponlog.Id > 0 ? "领取成功" : "领取失败" }, JsonRequestBehavior.AllowGet));
            }
        }