Beispiel #1
0
        /// <summary>
        /// 开团
        /// </summary>
        /// <param name="isgroup"></param>
        /// <param name="rid"></param>
        /// <param name="buyMode"></param>
        /// <param name="userid"></param>
        /// <param name="groupmodel"></param>
        /// <param name="dbOrder"></param>
        /// <returns></returns>
        public string OpenGroup(int isgroup, int rid, int buyMode, int userid, EntGroupsRelation groupmodel, int buyprice, int type, ref int groupid)
        {
            string msg = "";

            //是否开团
            if (isgroup > 0)
            {
                EntGroupSponsor groupSponsor = new EntGroupSponsor();
                groupSponsor.EntGoodRId    = groupmodel.Id;
                groupSponsor.SponsorUserId = userid;
                groupSponsor.GroupSize     = groupmodel.GroupSize;
                groupSponsor.RId           = rid;
                groupSponsor.Type          = type;
                groupSponsor.StartDate     = DateTime.Now;
                groupSponsor.EndDate       = DateTime.Now.AddHours(groupmodel.ValidDateLength);
                groupSponsor.State         = buyMode == (int)miniAppBuyMode.储值支付 || buyprice <= 0 ? (int)GroupState.开团成功 : (int)GroupState.待付款; //待付款
                groupid = Convert.ToInt32(base.Add(groupSponsor));
                if (groupid <= 0)
                {
                    msg = $"成团失败!";
                }
            }

            return(msg);
        }
Beispiel #2
0
        /// <summary>
        /// 检查购买团商品是否超出限制
        /// </summary>
        /// <param name="userid">用户Id</param>
        /// <param name="qty">购买数量</param>
        /// <param name="good">商品</param>
        /// <param name="attrSpacStr">规格参数</param>
        /// <param name="price">价格</param>
        /// <returns></returns>
        protected string CheckGoodCount(int userid, int qty, EntGoods good, string attrSpacStr, ref int price)
        {
            string            msg             = "";
            EntGroupsRelation entgroupremodel = EntGroupsRelationBLL.SingleModel.GetModelByGroupGoodType(good.id, good.aid, good.storeId);

            if (entgroupremodel == null)
            {
                msg = "团商品不存在";
            }
            price = entgroupremodel.GroupPrice;
            //用户已团数量
            int buycount = EntGoodsOrderBLL.SingleModel.GetGroupPersonCount(userid, entgroupremodel.EntGoodsId, good.storeId);

            if (entgroupremodel.LimitNum > 0 && qty > entgroupremodel.LimitNum - buycount)
            {
                msg = "超过购买限制";
            }

            //判断是否带有规格参数
            if (!string.IsNullOrWhiteSpace(attrSpacStr))
            {
                EntGoodsAttrDetail curEntGoodsAttrDtl = good.GASDetailList.First(x => x.id.Equals(attrSpacStr));
                if (curEntGoodsAttrDtl == null)
                {
                    msg = $"商品不存在:goodId={good.id}||spec={attrSpacStr}  ";
                }
                price = Convert.ToInt32(curEntGoodsAttrDtl.groupPrice * 100);
            }

            return(msg);
        }
Beispiel #3
0
        /// <summary>
        /// 开团
        /// </summary>
        /// <param name="isgroup"></param>
        /// <param name="rid"></param>
        /// <param name="buyMode"></param>
        /// <param name="userid"></param>
        /// <param name="groupmodel"></param>
        /// <param name="dbOrder"></param>
        /// <returns></returns>
        protected string OpenGroup(int isgroup, int rid, int buyMode, int userid, EntGroupsRelation groupmodel, ref EntGoodsOrder dbOrder)
        {
            string msg = "";

            //是否开团
            if (isgroup > 0)
            {
                int             groupusersum = EntGroupSponsorBLL.SingleModel.GetGroupSponrUserSum(groupmodel.Id);
                EntGroupSponsor groupSponsor = new EntGroupSponsor();
                groupSponsor.EntGoodRId    = groupmodel.Id;
                groupSponsor.SponsorUserId = userid;
                groupSponsor.GroupSize     = groupmodel.GroupSize;
                groupSponsor.RId           = rid;
                groupSponsor.StartDate     = DateTime.Now;
                groupSponsor.EndDate       = DateTime.Now.AddHours(groupmodel.ValidDateLength);
                groupSponsor.State         = buyMode == (int)miniAppBuyMode.储值支付 || dbOrder.BuyPrice <= 0 ? (int)GroupState.开团成功 : (int)GroupState.待付款; //待付款
                int groupid = Convert.ToInt32(EntGroupSponsorBLL.SingleModel.Add(groupSponsor));
                if (groupid <= 0)
                {
                    msg = $"成团失败!";
                }
                dbOrder.GroupId = groupid;
                EntGoodsOrderBLL.SingleModel.Update(dbOrder, "groupid");
            }

            return(msg);
        }
Beispiel #4
0
        /// <summary>
        /// 编辑门店产品
        /// </summary>
        /// <returns></returns>
        public ActionResult subgoodedit()
        {
            int id    = Context.GetRequestInt("id", 0);
            int subid = Context.GetRequestInt("subid", 0);

            if (id <= 0 || subid <= 0)
            {
                return(View("PageError", new Return_Msg()
                {
                    Msg = "参数错误!", code = "500"
                }));
            }
            EntGoods entModelOld = EntGoodsBLL.SingleModel.GetModel(id);

            if (entModelOld == null || entModelOld.state == 0 || entModelOld.tag == 0)
            {
                return(View("PageError", new Return_Msg()
                {
                    Msg = "总店产品不可用!", code = "500"
                }));
            }
            SubStoreEntGoods subModel = SubStoreEntGoodsBLL.SingleModel.GetModel(subid);

            if (subModel == null || subModel.SubState == 0)
            {
                if (subModel.SubTag == 1)
                {
                    return(View("PageError", new Return_Msg()
                    {
                        Msg = "下架后才可以编辑!", code = "500"
                    }));
                }
                return(View("PageError", new Return_Msg()
                {
                    Msg = "产品不可用!", code = "500"
                }));
            }

            entModelOld.specificationdetail = subModel.SubSpecificationdetail;
            entModelOld.stock = subModel.SubStock;
            entModelOld.sort  = subModel.SubSort;

            //拼团
            if (entModelOld.goodtype == (int)EntGoodsType.拼团产品)
            {
                EntGroupsRelation group = EntGroupsRelationBLL.SingleModel.GetModelByGroupGoodType(entModelOld.id, entModelOld.aid);
                if (group == null)
                {
                    return(View("PageError", new Return_Msg()
                    {
                        Msg = "拼团不可编辑!", code = "500"
                    }));
                }
                entModelOld.EntGroups = group;
            }
            return(View(entModelOld));
        }
Beispiel #5
0
        /// <summary>
        /// 检查购买团商品是否超出限制
        /// </summary>
        /// <param name="userid">用户Id</param>
        /// <param name="qty">购买数量</param>
        /// <param name="good">商品</param>
        /// <param name="attrSpacStr">规格参数</param>
        /// <param name="price">价格</param>
        /// <returns></returns>
        protected string CheckGoodCount(int userid, int qty, int goodid, int rid, int storeId, string attrSpacStr, int groupprice, ref int price, int type = (int)TmpType.小程序专业模板)
        {
            string            msg             = "";
            EntGroupsRelation entgroupremodel = EntGroupsRelationBLL.SingleModel.GetModelByGroupGoodType(goodid, rid, storeId);

            if (entgroupremodel == null)
            {
                msg = "团商品不存在";
            }
            price = entgroupremodel.GroupPrice;
            //用户已团数量
            int buycount = EntGoodsOrderBLL.SingleModel.GetGroupPersonCount(userid, entgroupremodel.EntGoodsId, storeId);

            switch (type)
            {
            case (int)TmpType.小程序餐饮模板:
                buycount = FoodGoodsOrderBLL.SingleModel.GetGroupPersonCount(userid, entgroupremodel.EntGoodsId);
                break;

            case (int)TmpType.小程序专业模板:
                buycount = EntGoodsOrderBLL.SingleModel.GetGroupPersonCount(userid, entgroupremodel.EntGoodsId, storeId);
                break;
            }
            if (entgroupremodel.LimitNum > 0 && qty > entgroupremodel.LimitNum - buycount)
            {
                msg = "超过购买限制";
            }

            //判断是否带有规格参数
            if (!string.IsNullOrWhiteSpace(attrSpacStr))
            {
                price = groupprice;
            }

            return(msg);
        }
Beispiel #6
0
        public EntGroupSponsor GetGroupDetail(int groupid, int type)
        {
            EntGroupSponsor model = GetModel(groupid);

            if (model == null)
            {
                return(model);
            }

            EntGroupsRelation entgroup = EntGroupsRelationBLL.SingleModel.GetModel(model.EntGoodRId);

            if (entgroup == null)
            {
                return(new EntGroupSponsor());
            }

            int groupnum = 0;

            model.GroupPrice    = entgroup.GroupPriceStr;
            model.OriginalPrice = entgroup.OriginalPriceStr;
            switch (type)
            {
            case (int)TmpType.小程序专业模板:
                EntGoods entgood = EntGoodsBLL.SingleModel.GetModel(entgroup.EntGoodsId);
                if (entgood == null)
                {
                    return(new EntGroupSponsor());
                }

                model.GroupName = entgood.name;
                model.GoodId    = entgood.id;
                EntGoodsOrder order = EntGoodsOrderBLL.SingleModel.GetModel($"ordertype = 3 and groupid = {groupid}");
                model.GroupImage = ImgHelper.ResizeImg(entgood.img, 220, 220);
                if (order != null)
                {
                    EntGoodsCart goodOrderDtl = EntGoodsCartBLL.SingleModel.GetModelByGoodsOrderId(order.Id);
                    if (goodOrderDtl != null && !string.IsNullOrEmpty(goodOrderDtl.SpecImg))
                    {
                        model.GroupImage = ImgHelper.ResizeImg(goodOrderDtl.SpecImg, 220, 220);
                    }
                }

                ;
                model.GroupUserList = EntGoodsOrderBLL.SingleModel.GetPersonByGroup(groupid.ToString(), ref groupnum);
                break;

            case (int)TmpType.小程序餐饮模板:
                groupnum            = FoodGoodsOrderBLL.SingleModel.GetGroupPersonCount(0, entgroup.EntGoodsId);
                model.GroupUserList = FoodGoodsOrderBLL.SingleModel.GetPersonByGroup(groupid.ToString());
                FoodGoods foodgood = FoodGoodsBLL.SingleModel.GetModel(entgroup.EntGoodsId);
                if (foodgood == null)
                {
                    return(new EntGroupSponsor());
                }

                model.GroupName  = foodgood.GoodsName;
                model.GoodId     = foodgood.Id;
                model.GroupImage = ImgHelper.ResizeImg(foodgood.ImgUrl, 220, 220);;
                break;
            }
            model.GroupNum = groupnum + entgroup.InitSaleCount;//加上初始化销售量

            return(model);
        }
Beispiel #7
0
        /// <summary>
        /// 下单时判断是否是拼团
        /// </summary>
        /// <param name="isgroup"></param>
        /// <param name="groupid"></param>
        /// <param name="specificationId"></param>
        /// <param name="goodscar"></param>
        /// <param name="grouperprice"></param>
        /// <param name="groupmodel"></param>
        /// <returns></returns>
        protected string CommandEntGroup(int isgroup, int groupid, int userid, int storeid, int goodid, ref int grouperprice, ref EntGroupsRelation groupmodel, int buyCount)
        {
            if (isgroup <= 0 && groupid <= 0)
            {
                return("");
            }

            if (isgroup > 0 && groupid > 0)
            {
                return("拼团参数错误");
            }

            groupmodel = EntGroupsRelationBLL.SingleModel.GetModelByGroupGoodType(goodid, groupmodel.RId, storeid);
            if (groupmodel == null)
            {
                return("产品匹配不到拼团信息");
            }

            #region 判断开团时,库存是否满足成团
            EntGoods entgood = EntGoodsBLL.SingleModel.GetModel(groupmodel.EntGoodsId);
            if (entgood == null)
            {
                return("拼团产品已下架");
            }
            //已团件数
            if (isgroup > 0 && entgood.stockLimit)
            {
                //判定是否当前用户下单后,剩余的数量是否足够成一个团,如果不足够,那么不允许用户再开团
                if (entgood.stock - buyCount < groupmodel.GroupSize - 1)
                {
                    return("商品库存不足,无法成团");
                }
            }
            #endregion
            grouperprice = groupmodel.HeadDeduct;

            //判断是否是团长,团员不减团长优惠价
            if (groupid > 0)
            {
                grouperprice = 0;
            }

            //判断是否已参加该团
            if (groupid > 0)
            {
                EntGoodsOrder entgoodorder = EntGoodsOrderBLL.SingleModel.GetModelGroupByGrouId(groupid, userid);
                if (entgoodorder != null)
                {
                    return("您已经参加过该拼团了");
                }
            }

            return("");
        }
Beispiel #8
0
        public ActionResult GetJoinGroupList()
        {
            string appId     = Context.GetRequest("appId", string.Empty);
            int    entgoodid = Context.GetRequestInt("entgoodid", 0);
            int    pageIndex = Context.GetRequestInt("pageIndex", 1);
            int    storeId   = Context.GetRequestInt("storeId", 0);//多门店分店ID,其他都为0
            int    pageSize  = 10;

            if (string.IsNullOrEmpty(appId))
            {
                return(Json(new { isok = -1, msg = "appid不能为空" }, JsonRequestBehavior.AllowGet));
            }

            XcxAppAccountRelation umodel = _xcxAppAccountRelationBLL.GetModelByAppid(appId);

            if (umodel == null)
            {
                return(Json(new { isok = -1, msg = "请先授权" }, JsonRequestBehavior.AllowGet));
            }

            int xtype = _xcxAppAccountRelationBLL.GetXcxTemplateType(umodel.Id);

            if (xtype == 0)
            {
                return(Json(new { isok = -1, msg = "小程序没授权" }, JsonRequestBehavior.AllowGet));
            }

            EntGroupsRelation grouprmodel = EntGroupsRelationBLL.SingleModel.GetModelByGroupGoodType(entgoodid, umodel.Id, storeId); //_entgrouprelationBll.GetModel($"entgoodsid={entgoodid}");

            if (grouprmodel == null)
            {
                return(Json(new { isok = -1, msg = "匹配不到拼团" }, JsonRequestBehavior.AllowGet));
            }
            List <EntGroupSponsor> grouplist = EntGroupSponsorBLL.SingleModel.GetPageList(grouprmodel.Id, pageIndex, pageSize);

            if (grouplist?.Count > 0)
            {
                string            userids    = string.Join(",", grouplist.Select(s => s.SponsorUserId).Distinct());
                List <C_UserInfo> groupusers = C_UserInfoBLL.SingleModel.GetListByIds(userids);

                //拼团订单记录
                string groupids = string.Join(",", grouplist.Select(s => s.Id));
                switch (xtype)
                {
                case (int)TmpType.小程序专业模板:
                    List <EntGoodsOrder> entgoodsorderlist = EntGoodsOrderBLL.SingleModel.GetListByGoodsState(umodel.Id, groupids, MiniAppEntOrderState.待发货);

                    grouplist.ForEach(p =>
                    {
                        C_UserInfo user = groupusers.Where(w => w.Id == p.SponsorUserId).FirstOrDefault();
                        if (user != null && !string.IsNullOrEmpty(user.HeadImgUrl))
                        {
                            p.UserImg = Utility.ImgHelper.ResizeImg(user.HeadImgUrl, 640, 360);;
                        }

                        int?tempgrouplist = entgoodsorderlist?.Where(w => w.GroupId == p.Id)?.Sum(s => s.QtyCount);
                        //已团数量
                        p.GroupNum = Convert.ToInt32(tempgrouplist);
                    });
                    break;

                case (int)TmpType.小程序餐饮模板:
                    Food food = FoodBLL.SingleModel.GetModelByAppId(umodel.Id);
                    if (food == null)
                    {
                        return(Json(new { isok = -1, msg = "餐厅还未营业,请稍后再试" }, JsonRequestBehavior.AllowGet));
                    }
                    List <FoodGoodsOrder> foodgoodsorderlist = FoodGoodsOrderBLL.SingleModel.GetListByGoodsState(food.Id, groupids, miniAppFoodOrderState.待就餐);

                    grouplist.ForEach(p =>
                    {
                        C_UserInfo user = groupusers.Where(w => w.Id == p.SponsorUserId).FirstOrDefault();
                        if (user != null && !string.IsNullOrEmpty(user.HeadImgUrl))
                        {
                            p.UserImg = Utility.ImgHelper.ResizeImg(user.HeadImgUrl, 640, 360);;
                        }

                        int?tempgrouplist = foodgoodsorderlist?.Where(w => w.GroupId == p.Id).Sum(s => s.QtyCount);
                        //已团数量
                        p.GroupNum = Convert.ToInt32(tempgrouplist);
                    });
                    break;
                }
            }

            return(Json(new { isok = 1, msg = "成功", postdata = grouplist }, JsonRequestBehavior.AllowGet));
        }
Beispiel #9
0
        public ActionResult GetGoodInfo()
        {
            returnObj      = new Return_Msg_APP();
            returnObj.isok = false;

            int goodid  = Context.GetRequestInt("goodid", 0);
            int storeId = Context.GetRequestInt("storeId", 0);
            int aid     = Context.GetRequestInt("aid", 0);

            if (goodid == 0 || storeId < 0 || (storeId > 0 && aid == 0))
            {
                returnObj.Msg = "非法请求";
                return(Json(returnObj, JsonRequestBehavior.AllowGet));
            }

            int xtype = _xcxAppAccountRelationBLL.GetXcxTemplateType(aid);

            if (xtype == 0)
            {
                returnObj.Msg = "小程序没授权";
                return(Json(returnObj, JsonRequestBehavior.AllowGet));
            }

            EntGroupsRelation relationmodel = EntGroupsRelationBLL.SingleModel.GetModelByGroupGoodType(goodid, aid, storeId);

            if (relationmodel == null)
            {
                returnObj.Msg = "该拼团已不存在";
                return(Json(returnObj, JsonRequestBehavior.AllowGet));
            }

            //已团数量
            int                    groupnum         = 0;
            List <object>          userlist         = EntGroupSponsorBLL.SingleModel.GetGoupsUserImgs(relationmodel.Id, ref groupnum, xtype, relationmodel.EntGoodsId);
            List <EntGroupSponsor> groupSponsorList = EntGroupSponsorBLL.SingleModel.GetHaveSuccessGroup(relationmodel.Id, 10, goodid);

            switch (xtype)
            {
            case (int)TmpType.小程序专业模板: break;

            case (int)TmpType.小程序多门店模板:
                EntGoods goodModel = EntGoodsBLL.SingleModel.GetModel(goodid);
                if (goodModel == null || goodModel.state == 0)
                {
                    returnObj.Msg = "产品不存在或已删除";
                    return(Json(returnObj, JsonRequestBehavior.AllowGet));
                }

                if (storeId > 0)
                {
                    SubStoreEntGoods subGood = SubStoreEntGoodsBLL.SingleModel.GetModelByAppIdStoreIdGoodsId(aid, storeId, goodid);
                    if (subGood == null)
                    {
                        returnObj.Msg = "产品不存在或已下架";
                        return(Json(returnObj, JsonRequestBehavior.AllowGet));
                    }
                    goodModel.specificationdetail = subGood.SubSpecificationdetail;
                    goodModel.stock = subGood.SubStock;
                }

                if (!string.IsNullOrEmpty(goodModel.plabels))
                {
                    goodModel.plabelstr       = EntGoodsBLL.SingleModel.GetPlabelStr(goodModel.plabels);
                    goodModel.plabelstr_array = goodModel.plabelstr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                }

                goodModel.EntGroups.GroupUserList    = userlist;
                goodModel.EntGroups.GroupsNum        = groupnum;
                goodModel.EntGroups.GroupSponsorList = groupSponsorList;

                returnObj.dataObj = goodModel;
                break;
            }

            returnObj.isok = true;
            return(Json(returnObj, JsonRequestBehavior.AllowGet));
        }
Beispiel #10
0
        /// <summary>
        /// 添加门店产品
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="storeId"></param>
        /// <returns></returns>
        public ActionResult AddStoreProduct(int appId = 0, int storeId = 0)
        {
            string ids = Context.GetRequest("ids", string.Empty);

            if (appId == 0 || storeId == 0 || ids == "")
            {
                return(Json(new { isok = false, msg = "非法请求" }));
            }
            string[] idsArray = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (idsArray.Length <= 0)
            {
                return(Json(new { isok = false, msg = "请选择要添加的产品" }));
            }

            SubStoreEntGoods subGoodsModel;
            List <string>    addSqlList = new List <string>();

            foreach (string id in idsArray)
            {
                int pid = 0;
                if (int.TryParse(id, out pid))
                {
                    EntGoods goodModel = EntGoodsBLL.SingleModel.GetModel(pid);
                    if (goodModel != null && !SubStoreEntGoodsBLL.SingleModel.Exists($"pid={pid} and aid={appId} and storeid={storeId} and SubState=1"))
                    {
                        subGoodsModel = new SubStoreEntGoods()
                        {
                            Aid     = goodModel.aid,
                            Pid     = goodModel.id,
                            StoreId = storeId,
                            SubSpecificationdetail = goodModel.specificationdetail,
                            SubState      = 1,
                            SubTag        = 1,
                            SubsalesCount = 0,
                            SubStock      = goodModel.stock,
                        };
                        addSqlList.Add(SubStoreEntGoodsBLL.SingleModel.BuildAddSql(subGoodsModel));

                        #region 拼团
                        if (goodModel.goodtype == (int)EntGoodsType.拼团产品)
                        {
                            EntGroupsRelation entgroups = EntGroupsRelationBLL.SingleModel.GetModelByGroupGoodType(goodModel.id, goodModel.aid);
                            if (entgroups == null)
                            {
                                return(Json(new { isok = false, msg = "团商品已失效!" }));
                            }
                            entgroups.AddTime    = DateTime.Now;
                            entgroups.RId        = goodModel.aid;
                            entgroups.EntGoodsId = goodModel.id;//占位
                            entgroups.StoreId    = storeId;
                            string addsql = EntGroupsRelationBLL.SingleModel.BuildAddSql(entgroups);
                            //获取最新插入的多门店产品ID
                            //addsql = addsql.Replace("-9999", "(select last_insert_id())");
                            //log4net.LogHelper.WriteInfo(this.GetType(),addsql);
                            addSqlList.Add(addsql);
                        }

                        #endregion
                    }
                }
            }
            if (SubStoreEntGoodsBLL.SingleModel.ExecuteTransaction(addSqlList.ToArray()))
            {
                return(Json(new { isok = true, msg = $"选择{idsArray.Length}个产品,添加成功{addSqlList.Count}个" }));
            }
            else
            {
                return(Json(new { isok = false, msg = "添加失败!" }));
            }
        }