Exemple #1
0
        /// <summary>
        /// 更新拼团状态
        /// </summary>
        public void UpdateGroupState()
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    //支付超时
                    var groups = context.bsp_groups.Where(t => t.isfail == false && t.isfinish == false && t.endtime <= DateTime.Now).ToList();
                    groups.ForEach(g =>
                    {
                        g.isfail = true;
                    });
                    context.SaveChanges();

                    //确认收货超时
                    //var maxquerytime = DateTime.Now.AddMinutes(-119);
                    //orders = context.bsp_orders.Where(t => t.orderstate == (int)OrderState.Sending && t.shiptime.Value <= maxquerytime).ToList();
                    //orders.ForEach(o =>
                    //{
                    //    o.orderstate = (int)OrderState.WaitReview;
                    //});
                    context.SaveChanges();
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    Logger._.Error("更新拼团状态任务执行失败:", ex);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 新增优惠券(后台)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResultModel AddCouponType(ShowCouponTypeInfo model)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    //新增
                    if (model.ct_coupontypeid == 0)
                    {
                        bsp_coupontypes newcoupontype = new bsp_coupontypes();
                        newcoupontype.cutmoney         = model.ct_cutmoney;
                        newcoupontype.discount         = model.ct_discount;
                        newcoupontype.fullmoney        = model.ct_fullmoney;
                        newcoupontype.count            = 0;
                        newcoupontype.getmode          = 0;
                        newcoupontype.isstack          = model.ct_isstack;
                        newcoupontype.limitbrandid     = 0;
                        newcoupontype.limitcateid      = 0;
                        newcoupontype.limitproduct     = 0;
                        newcoupontype.money            = 0;
                        newcoupontype.name             = model.ct_name;
                        newcoupontype.orderamountlower = 0;
                        newcoupontype.sendendtime      = model.ct_sendendtime;
                        newcoupontype.sendmode         = 0;
                        newcoupontype.sendstarttime    = model.ct_sendstarttime;
                        newcoupontype.state            = 0;
                        newcoupontype.type             = model.ct_type;
                        newcoupontype.useendtime       = model.ct_useexpiretime == 1?model.ct_useendtime:DateTime.Now;
                        newcoupontype.useexpiretime    = model.ct_useexpiretime;
                        newcoupontype.usemode          = 0;
                        newcoupontype.userranklower    = 0;
                        newcoupontype.usestarttime     = model.ct_useexpiretime == 1 ? model.ct_usestarttime : DateTime.Now;
                        newcoupontype.isforgroup       = model.ct_isforgroup;
                        context.bsp_coupontypes.Add(newcoupontype);
                        context.SaveChanges();

                        if (model.ct_pid > 0)
                        {
                            bsp_couponproducts bsp_Couponproduct = new bsp_couponproducts();
                            bsp_Couponproduct.coupontypeid = newcoupontype.coupontypeid;
                            bsp_Couponproduct.pid          = model.ct_pid;
                            context.bsp_couponproducts.Add(bsp_Couponproduct);
                            context.SaveChanges();
                        }
                    }
                    tran.Commit();
                    return(ResultModel.Success("添加成功"));
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    Logger._.Error(ex);
                    return(ResultModel.Error());
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 用户开团(支付回调时调用)
        /// </summary>
        /// <returns></returns>
        public ResultModel StartGroup(int groupInfoId, int uid, string outtradeno, string transaction_id)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    bsp_groupinfos GroupInfo = context.bsp_groupinfos.SingleOrDefault(t => t.groupinfoid == groupInfoId);
                    bsp_groups     newGroup  = new bsp_groups();
                    newGroup.endtime     = DateTime.Now.AddSeconds(GroupInfo.maxtime);
                    newGroup.failtype    = 0;
                    newGroup.groupoid    = GroupInfo.groupoid;
                    newGroup.groupprice  = GroupInfo.groupprice;
                    newGroup.grouptype   = GroupInfo.grouptype;
                    newGroup.isfail      = false;
                    newGroup.isfinish    = false;
                    newGroup.maxtime     = GroupInfo.maxtime;
                    newGroup.needcount   = GroupInfo.needcount;
                    newGroup.nowcount    = 1;
                    newGroup.shopprice   = GroupInfo.shopprice;
                    newGroup.starttime   = DateTime.Now;
                    newGroup.startuid    = uid;
                    newGroup.groupinfoid = groupInfoId;
                    context.bsp_groups.Add(newGroup);
                    context.SaveChanges();

                    bsp_groupdetails newGroupetail = new bsp_groupdetails();
                    newGroupetail.groupid        = newGroup.groupid;
                    newGroupetail.paytime        = DateTime.Now;
                    newGroupetail.sno            = 1;
                    newGroupetail.uid            = uid;
                    newGroupetail.isgetcoupon    = false;
                    newGroupetail.paytime        = DateTime.Parse("1997-01-27");
                    newGroupetail.transaction_id = transaction_id;
                    newGroupetail.outtradeno     = outtradeno;
                    context.bsp_groupdetails.Add(newGroupetail);
                    context.SaveChanges();
                    ORDER.AddStatistics(true, newGroup, newGroupetail, context);
                    tran.Commit();
                    return(ResultModel.Success("开团成功"));
                }
                catch (Exception ex)
                {
                    Logger._.Error("StartGroup方法,", ex);
                    tran.Rollback();
                    return(ResultModel.Error(ex.ToString()));
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// 新增拼团活动
 /// </summary>
 public ResultModel CreateGroupInfo(GroupInfoModel model)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         try
         {
             bsp_groupinfos newGroupInfo = new bsp_groupinfos();
             newGroupInfo.endtime    = model.endtime;
             newGroupInfo.groupoid   = model.groupoid;
             newGroupInfo.groupprice = model.groupprice;
             newGroupInfo.grouptype  = model.grouptype;
             newGroupInfo.maxtime    = model.maxtime;
             newGroupInfo.needcount  = model.needcount;
             newGroupInfo.shopprice  = model.shopprice;
             newGroupInfo.starttime  = model.starttime;
             context.bsp_groupinfos.Add(newGroupInfo);
             context.SaveChanges();
             return(ResultModel.Success("新增成功"));
         }
         catch (Exception ex)
         {
             Logger._.Error("CreateGroupInfo方法,", ex);
             return(ResultModel.Error(ex.ToString()));
         }
     }
 }
Exemple #5
0
        /// <summary>
        /// 更新包厢
        /// </summary>
        /// <param name="boxid"></param>
        /// <param name="state"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public ResultModel UpdateBox(int boxid, BoxState state, string name, decimal price, decimal bookprice)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    var box = context.bsp_boxes.SingleOrDefault(t => t.boxid == boxid);
                    if (box == null)
                    {
                        return(ResultModel.Fail("该包厢已删除,请刷新"));
                    }
                    box.state     = (int)state;
                    box.name      = name;
                    box.price     = price;
                    box.bookprice = bookprice;
                    if (state == BoxState.Empty)
                    {
                        box.username = "";
                        box.phone    = "";
                    }
                    context.SaveChanges();

                    tran.Commit();
                    new BoxCache().Init();
                    return(ResultModel.Success("修改成功"));
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    Logger._.Error(ex);
                    return(ResultModel.Error(ex.ToString()));
                }
            }
        }
Exemple #6
0
 /// <summary>
 /// 添加分类
 /// </summary>
 /// <returns></returns>
 public ResultModel AddCateGory(string name, int displayorder = 0)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         try
         {
             var catrgory = context.bsp_categories.SingleOrDefault(t => t.name == name);
             if (catrgory != null)
             {
                 return(ResultModel.Fail("已存在该分类"));
             }
             bsp_categories newcate = new bsp_categories();
             newcate.name         = name;
             newcate.displayorder = displayorder;
             newcate.pricerange   = "";
             newcate.path         = "";
             context.bsp_categories.Add(newcate);
             context.SaveChanges();
             return(ResultModel.Success("添加成功", newcate.cateid));
         }
         catch (Exception ex)
         {
             Logger._.Error(ex);
             return(ResultModel.Error(ex.ToString()));
         }
     }
 }
Exemple #7
0
 public ResultModel AddAttributeValue(short attrid, string value)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         try
         {
             var attrvalue = context.bsp_attributevalues.SingleOrDefault(t => t.attrid == attrid && t.attrvalue == value);
             if (attrvalue != null)
             {
                 return(ResultModel.Fail("该属性值已经存在"));
             }
             var attr = context.bsp_attributes.SingleOrDefault(t => t.attrid == attrid);
             bsp_attributevalues newattrvalue = new bsp_attributevalues();
             newattrvalue.attrid    = attrid;
             newattrvalue.attrname  = attr.name;
             newattrvalue.attrvalue = value;
             context.bsp_attributevalues.Add(newattrvalue);
             context.SaveChanges();
             return(ResultModel.Success("", newattrvalue.attrvalueid));
         }
         catch (Exception ex)
         {
             Logger._.Error(ex);
             return(ResultModel.Error(ex.ToString()));
         }
     }
 }
Exemple #8
0
 public ResultModel AddSKU(int pid, int valueid, int isdefaultprice, decimal price)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         try
         {
             var sku = context.bsp_productskus.SingleOrDefault(t => t.pid == pid && t.attrvalueid == valueid);
             if (sku != null)
             {
                 return(ResultModel.Fail("该规格SKU已经存在"));
             }
             var             attrvalue = context.bsp_attributevalues.SingleOrDefault(t => t.attrvalueid == valueid);
             bsp_productskus newsku    = new bsp_productskus();
             newsku.pid            = pid;
             newsku.attrid         = attrvalue.attrid;
             newsku.attrvalueid    = valueid;
             newsku.inputattr      = attrvalue.attrname;
             newsku.inputvalue     = attrvalue.attrvalue;
             newsku.isdefaultprice = isdefaultprice;
             newsku.price          = price;
             context.bsp_productskus.Add(newsku);
             context.SaveChanges();
             ProductCache.InitProductList();
             return(ResultModel.Success("", newsku.recordid));
         }
         catch (Exception ex)
         {
             Logger._.Error(ex);
             return(ResultModel.Error(ex.ToString()));
         }
     }
 }
Exemple #9
0
        /// <summary>
        /// 删除分类
        /// </summary>
        /// <param name="cateid"></param>
        /// <returns></returns>
        public ResultModel DeleteCateGory(int cateid)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                try
                {
                    var sql = $@"select COUNT(bsp_cateproducts.catepid)
						    from bsp_cateproducts
						    left join bsp_products on bsp_products.pid = bsp_cateproducts.pid
						    where bsp_products.isdelete = 0 and bsp_cateproducts.cateid = {cateid}"                        ;
                    var dt  = SqlManager.FillDataTable(AppConfig.ConnectionString, new SqlCommand(sql));
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        if (int.Parse(dt.Rows[0][0].ToString()) > 0)
                        {
                            return(ResultModel.Fail("该分类下存在商品,不允许删除"));
                        }
                    }
                    var cate = context.bsp_categories.SingleOrDefault(t => t.cateid == cateid);
                    if (cate == null)
                    {
                        return(ResultModel.Fail("该分类已经删除,请刷新"));
                    }
                    context.bsp_categories.Remove(cate);
                    context.SaveChanges();
                    return(ResultModel.Success("删除成功"));
                }
                catch (Exception ex)
                {
                    Logger._.Error(ex);
                    return(ResultModel.Error(ex.ToString()));
                }
            }
        }
Exemple #10
0
 /// <summary>
 /// 编辑商家信息
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public ResultModel EditSYSInfo(ShowSYSModel model)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         try
         {
             var sys = context.bsp_businesses.FirstOrDefault();
             sys.address         = model.address;
             sys.name            = model.name;
             sys.businessEnd     = sys.businessEnd;
             sys.businessStart   = sys.businessStart;
             sys.businessTimeStr = sys.businessTimeStr;
             sys.canSendRadius   = sys.canSendRadius;
             sys.description     = sys.description;
             sys.latitude        = sys.latitude;
             sys.longitude       = sys.longitude;
             sys.showimg         = sys.showimg;
             context.SaveChanges();
             return(ResultModel.Success("修改成功"));
         }
         catch (Exception ex)
         {
             Logger._.Error(ex);
             return(ResultModel.Error());
         }
     }
 }
Exemple #11
0
        /// <summary>
        /// 删除包厢
        /// </summary>
        /// <param name="boxid"></param>
        /// <returns></returns>
        public ResultModel DeleteBox(int boxid)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    var box = context.bsp_boxes.SingleOrDefault(t => t.boxid == boxid);
                    if (box == null)
                    {
                        return(ResultModel.Fail("该包厢已删除,请刷新"));
                    }
                    context.bsp_boxes.Remove(box);
                    context.SaveChanges();

                    tran.Commit();
                    new BoxCache().Init();
                    return(ResultModel.Success("删除成功"));
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    Logger._.Error(ex);
                    return(ResultModel.Error(ex.ToString()));
                }
            }
        }
Exemple #12
0
 /// <summary>
 /// 从缓存根据对象名获取文件地址
 /// </summary>
 /// <param name="objectname"></param>
 /// <returns></returns>
 public static string GetFile(string objectname)
 {
     lock (GetFileObject)
     {
         try
         {
             var filecache = files.OrderByDescending(t => t.expiretime).FirstOrDefault(t => t.objectname == objectname);
             if (filecache == null || filecache.expiretime < DateTime.Now.AddMinutes(3))
             {
                 OSSHelper oSSHelper  = new OSSHelper();
                 DateTime  expireTime = DateTime.Now.AddMinutes(30);
                 string    ossurl     = oSSHelper.GetFilePath(objectname, expireTime);
                 using (brnshopEntities context = new brnshopEntities())
                 {
                     var bsp_file = context.bsp_files.SingleOrDefault(t => t.objectname == objectname);
                     bsp_file.ossurl = ossurl;
                     if (filecache == null)
                     {
                         FileCacheModel newfilecache = new FileCacheModel();
                         newfilecache.expiretime   = expireTime;
                         newfilecache.objectname   = objectname;
                         newfilecache.ossurl       = ossurl;
                         newfilecache.requestcount = 1;
                         newfilecache.timestamp    = bsp_file.timestamp;
                         files.Add(newfilecache);
                         //if(files.Count() > 999)
                         //{
                         //    files.RemoveAt(0);
                         //}//控制filecache数量
                     }
                     else
                     {
                         filecache.ossurl     = ossurl;
                         filecache.expiretime = expireTime;
                         filecache.requestcount++;
                         bsp_file.requestcount += filecache.requestcount;
                         filecache.requestcount = 0;
                     }
                     context.SaveChanges();
                 }
                 Logger._.Info(files.Count.ToString());
                 return(ossurl);
             }//缓存中没有或三分钟内要过期就请求oss获取地址存入缓存和数据库
             else
             {
                 filecache.requestcount++;
                 return(filecache.ossurl);
             }
         }
         catch (Exception ex)
         {
             Logger._.Error(ex);
             return("");
         }
     }
 }
Exemple #13
0
        /// <summary>
        /// 用户参团(支付回调时调用)
        /// </summary>
        /// <returns></returns>
        public ResultModel JoinGroup(int GroupId, int uid, string outtradeno, string transaction_id)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    bsp_groups Group = context.bsp_groups.SingleOrDefault(t => t.groupid == GroupId);
                    Group.nowcount += 1;
                    //拼团成功,发放优惠券
                    if (Group.needcount <= Group.nowcount)
                    {
                        Group.isfinish = true;
                        Group.endtime  = DateTime.Now;
                        var groupdetails = context.bsp_groupdetails.Where(t => t.groupid == GroupId).ToList();
                        foreach (var groupdetail in groupdetails)
                        {
                            if (!groupdetail.isgetcoupon.Value)
                            {
                                coupon.RecpientCoupon(groupdetail.uid, Group.groupoid);
                                groupdetail.isgetcoupon = true;
                            }
                        }
                    }

                    bsp_groupdetails newGroupetail = new bsp_groupdetails();
                    newGroupetail.groupid        = Group.groupid;
                    newGroupetail.paytime        = DateTime.Now;
                    newGroupetail.sno            = Group.nowcount;
                    newGroupetail.uid            = uid;
                    newGroupetail.isgetcoupon    = false;
                    newGroupetail.paytime        = DateTime.Parse("1997-01-27");
                    newGroupetail.transaction_id = transaction_id;
                    newGroupetail.outtradeno     = outtradeno;
                    if (Group.needcount <= Group.nowcount)
                    {
                        coupon.RecpientCoupon(newGroupetail.uid, Group.groupoid);
                        newGroupetail.isgetcoupon = true;
                    }
                    context.bsp_groupdetails.Add(newGroupetail);
                    context.SaveChanges();

                    ORDER.AddStatistics(true, Group, newGroupetail, context);
                    tran.Commit();
                    return(ResultModel.Success("参团成功"));
                }
                catch (Exception ex)
                {
                    Logger._.Error("JoinGroup方法,", ex);
                    tran.Rollback();
                    return(ResultModel.Error(ex.ToString()));
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// 添加编辑轮播图
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResultModel AddBanner(AddBannerModel model)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    if (model.bannerid == 0)
                    {
                        var newbanner = new bsp_banners();
                        newbanner.displayorder = model.displayorder;
                        newbanner.endtime      = model.endtime;
                        newbanner.img          = model.img;
                        newbanner.isshow       = 1;
                        newbanner.starttime    = model.starttime;
                        newbanner.title        = model.title;
                        newbanner.type         = (byte)model.bannerType;
                        newbanner.url          = model.url;
                        context.bsp_banners.Add(newbanner);
                    }
                    else
                    {
                        var banner = context.bsp_banners.SingleOrDefault(t => t.id == model.bannerid);
                        if (banner == null)
                        {
                            return(ResultModel.Fail("请刷新列表"));
                        }
                        banner.displayorder = model.displayorder;
                        banner.endtime      = model.endtime;
                        banner.img          = model.img;
                        banner.starttime    = model.starttime;
                        banner.type         = (byte)model.bannerType;
                        banner.title        = model.title;
                        banner.url          = model.url;
                    }
                    context.SaveChanges();

                    tran.Commit();
                    InitBanners();
                    return(ResultModel.Success("添加成功"));
                }
                catch (Exception ex)
                {
                    Logger._.Error(ex);
                    tran.Rollback();
                    return(ResultModel.Error());
                }
            }
        }
Exemple #15
0
        /// <summary>
        /// 用户领用优惠券接口
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="couponTypeid"></param>
        public ResultModel RecpientCoupon(int uid, int couponTypeid, bool isFromGroup = false)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                try
                {
                    var coupontype = context.bsp_coupontypes.SingleOrDefault(t => t.coupontypeid == couponTypeid);
                    var coupon     = context.bsp_coupons.SingleOrDefault(t => t.uid == uid && t.coupontypeid == couponTypeid & t.createtime >= coupontype.sendstarttime & t.createtime <= coupontype.sendendtime);

                    if (coupon != null && !isFromGroup)
                    {
                        return(ResultModel.Fail("您已经领取了该优惠券"));
                    }
                    var newcoupon = new bsp_coupons();
                    newcoupon.uid          = uid;
                    newcoupon.activateip   = WXPayHelper.GetPublicIp();
                    newcoupon.activatetime = DateTime.Now;
                    newcoupon.couponsn     = WXPayHelper.GetTimeStamp();
                    newcoupon.coupontypeid = couponTypeid;
                    newcoupon.createip     = "";
                    newcoupon.createoid    = 0;
                    newcoupon.createtime   = DateTime.Now;
                    newcoupon.createuid    = uid;
                    newcoupon.useip        = "";
                    newcoupon.usetime      = DateTime.Parse("1997-01-01");
                    newcoupon.isuse        = 0;
                    if (coupontype.useexpiretime == 0)
                    {
                        newcoupon.expiretime = coupontype.useendtime;
                    }
                    else
                    {
                        newcoupon.expiretime = DateTime.Now.AddSeconds(coupontype.useexpiretime);
                    }
                    context.bsp_coupons.Add(newcoupon);
                    context.SaveChanges();

                    return(ResultModel.Success());
                }
                catch (Exception ex)
                {
                    Logger._.Error(ex);
                    return(ResultModel.Error());
                }
            }
        }
Exemple #16
0
 /// <summary>
 /// 删除拼团活动
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public ResultModel DeleteGroupInfo(int groupInfoId)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         try
         {
             bsp_groupinfos GroupInfo = context.bsp_groupinfos.SingleOrDefault(t => t.groupinfoid == groupInfoId);
             context.bsp_groupinfos.Remove(GroupInfo);
             context.SaveChanges();
             return(ResultModel.Success("删除成功"));
         }
         catch (Exception ex)
         {
             Logger._.Error("DeleteGroupInfo方法,", ex);
             return(ResultModel.Error(ex.ToString()));
         }
     }
 }
Exemple #17
0
 /// <summary>
 /// 修改商品分类信息
 /// </summary>
 /// <param name="cateid"></param>
 /// <param name="name"></param>
 /// <param name="displayorder"></param>
 /// <returns></returns>
 public ResultModel UpdateCateGory(int cateid, string name, int displayorder)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         try
         {
             var cate = context.bsp_categories.SingleOrDefault(t => t.cateid == cateid);
             cate.name         = name;
             cate.displayorder = displayorder;
             context.SaveChanges();
             return(ResultModel.Success("修改成功"));
         }
         catch (Exception ex)
         {
             Logger._.Error(ex);
             return(ResultModel.Error(ex.ToString()));
         }
     }
 }
Exemple #18
0
 /// <summary>
 /// 删除轮播图
 /// </summary>
 /// <returns></returns>
 public ResultModel DeleteBanner(int[] ids)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         try
         {
             var banners = context.bsp_banners.Where(t => ids.Contains(t.id)).ToList();
             context.bsp_banners.RemoveRange(banners);
             context.SaveChanges();
             InitBanners();
             return(ResultModel.Success("删除成功"));
         }
         catch (Exception ex)
         {
             Logger._.Error(ex);
             return(ResultModel.Error());
         }
     }
 }
Exemple #19
0
        public ResultModel Upload(byte[] content, string filename, string client)
        {
            OSSHelper osshelper  = new OSSHelper();
            var       suffixname = filename.Split('.')[filename.Split('.').Length - 1];
            var       timestamp  = EncryptHelp.GetTimeStamp();
            var       objectName = EncryptHelp.GetRandomStr(4) + timestamp + "." + suffixname;

            if (!osshelper.Upload(content, filename, objectName, OSSHelper.GetContentTypeBySuffix(suffixname)))
            {
                return(ResultModel.Error("oss文件上传失败,请联系管理员"));
            }
            using (brnshopEntities context = new brnshopEntities())
            {
                try
                {
                    bsp_files newfile = new bsp_files();
                    newfile.client       = client;
                    newfile.name         = filename;
                    newfile.ossurl       = "";
                    newfile.requesturl   = "";
                    newfile.suffixname   = suffixname;
                    newfile.timestamp    = timestamp;
                    newfile.uploadtime   = DateTime.Now;
                    newfile.objectname   = objectName;
                    newfile.requestcount = 0;
                    newfile.domain       = ConfigurationManager.AppSettings["filedomain"];
                    context.bsp_files.Add(newfile);
                    context.SaveChanges();

                    //DateTime expirationTime = DateTime.Now.AddMinutes(30);
                    //GetFilePath(objectName);
                    return(ResultModel.Success(newfile.domain + newfile.objectname));
                }
                catch (Exception ex)
                {
                    Logger._.Error(ex);
                    return(ResultModel.Error(ex.ToString()));
                }
            }
        }
Exemple #20
0
 /// <summary>
 /// 删除商品
 /// </summary>
 /// <param name="pid"></param>
 /// <returns></returns>
 public ResultModel Deleteproduct(int pid)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         var tran = context.Database.BeginTransaction();
         try
         {
             var pro = context.bsp_products.SingleOrDefault(t => t.pid == pid);
             pro.isdelete = 1;
             context.SaveChanges();
             tran.Commit();
             new ProductCache().Init();
             return(ResultModel.Success("删除成功"));
         }
         catch (Exception ex)
         {
             Logger._.Error(ex);
             tran.Rollback();
             return(ResultModel.Error(ex.ToString()));
         }
     }
 }
Exemple #21
0
 public ResultModel DeleteSKU(int pid, int valueid)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         try
         {
             var sku = context.bsp_productskus.SingleOrDefault(t => t.pid == pid && t.attrvalueid == valueid);
             if (sku == null)
             {
                 return(ResultModel.Fail("该规格SKU已经删除"));
             }
             context.bsp_productskus.Remove(sku);
             context.SaveChanges();
             ProductCache.InitProductList();
             return(ResultModel.Success());
         }
         catch (Exception ex)
         {
             Logger._.Error(ex);
             return(ResultModel.Error(ex.ToString()));
         }
     }
 }
Exemple #22
0
 /// <summary>
 /// 调用login判断无用户信息后,小程序端通过GetUserInfo之后获取用户信息之后发送给服务端存储,返回用户信息
 /// </summary>
 public ResultModel SetUserInfo(ShowUserInfo showUserInfo)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         try
         {
             var newuser = new bsp_users()
             {
                 admingid     = 0,
                 avatar       = showUserInfo.avater,
                 email        = "",
                 gender       = showUserInfo.gender,
                 liftbantime  = DateTime.Now,
                 mobile       = "",
                 nickname     = showUserInfo.nickname,
                 openid       = showUserInfo.openid,
                 password     = "",
                 paycredits   = 0,
                 rankcredits  = 0,
                 salt         = "",
                 username     = showUserInfo.username,
                 userrid      = 0,
                 verifyemail  = 0,
                 verifymobile = 0
             };
             context.bsp_users.Add(newuser);
             context.SaveChanges();
             showUserInfo.uid = newuser.uid;
             return(ResultModel.Success("", showUserInfo));
         }
         catch (Exception ex)
         {
             Logger._.Error(ex);
             return(ResultModel.Error());
         }
     }
 }
Exemple #23
0
 /// <summary>
 /// 结束发放优惠券
 /// </summary>
 /// <param name="coupontypeids"></param>
 /// <returns></returns>
 public ResultModel StopCoupon(int[] coupontypeids)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         var tran = context.Database.BeginTransaction();
         try
         {
             foreach (var coupontypeid in coupontypeids)
             {
                 var coupontype = context.bsp_coupontypes.SingleOrDefault(t => t.coupontypeid == coupontypeid);
                 coupontype.sendendtime = DateTime.Now;
                 context.SaveChanges();
             }
             tran.Commit();
             return(ResultModel.Success("结束发放成功"));
         }
         catch (Exception ex)
         {
             tran.Rollback();
             Logger._.Error(ex);
             return(ResultModel.Error());
         }
     }
 }
Exemple #24
0
 public ResultModel AddAttribute(string name)
 {
     using (brnshopEntities context = new brnshopEntities())
     {
         try
         {
             var attr = context.bsp_attributes.SingleOrDefault(t => t.name == name);
             if (attr != null)
             {
                 return(ResultModel.Fail("该属性已经存在"));
             }
             bsp_attributes newattr = new bsp_attributes();
             newattr.name = name;
             context.bsp_attributes.Add(newattr);
             context.SaveChanges();
             return(ResultModel.Success("", newattr.attrid));
         }
         catch (Exception ex)
         {
             Logger._.Error(ex);
             return(ResultModel.Error(ex.ToString()));
         }
     }
 }
Exemple #25
0
        /// <summary>
        /// 新增包厢
        /// </summary>
        /// <param name="code"></param>
        /// <param name="name"></param>
        /// <param name="type">1.包厢 2.餐桌</param>
        /// <returns></returns>
        public ResultModel AddBox(string code, string name, decimal price, decimal bookprice, int type)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    var box = context.bsp_boxes.SingleOrDefault(t => t.code == code);
                    if (box != null)
                    {
                        return(ResultModel.Fail("该包厢编号已经存在"));
                    }
                    bsp_boxes newbox = new bsp_boxes();
                    newbox.booktime  = null;
                    newbox.code      = code;
                    newbox.name      = name;
                    newbox.oid       = 0;
                    newbox.state     = (int)BoxState.Empty;
                    newbox.uid       = 0;
                    newbox.price     = price;
                    newbox.bookprice = bookprice;
                    newbox.type      = type;
                    context.bsp_boxes.Add(newbox);
                    context.SaveChanges();

                    tran.Commit();
                    new BoxCache().Init();
                    return(ResultModel.Success("添加成功"));
                }catch (Exception ex)
                {
                    tran.Rollback();
                    Logger._.Error(ex);
                    return(ResultModel.Error(ex.ToString()));
                }
            }
        }
Exemple #26
0
        public ResultModel AddOrUpdateBusiness(BusinessModel businessModel)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    if (businessModel.businessid == 0)
                    {
                        bsp_businesses bsp_Businesses = new bsp_businesses();
                        bsp_Businesses.address         = businessModel.address;
                        bsp_Businesses.addtime         = DateTime.Now;
                        bsp_Businesses.businessEnd     = businessModel.businessEnd;
                        bsp_Businesses.businessStart   = businessModel.businessStart;
                        bsp_Businesses.businessTimeStr = businessModel.businessStart / 60 + ":" + businessModel.businessStart % 60 + "-" + businessModel.businessEnd / 60 + ":" + businessModel.businessEnd % 60;
                        bsp_Businesses.description     = businessModel.description;
                        bsp_Businesses.name            = businessModel.name;
                        bsp_Businesses.telphone        = businessModel.telphone;
                        bsp_Businesses.avgconsume      = businessModel.avgconsume;
                        bsp_Businesses.specialserver   = businessModel.specialserver;
                        bsp_Businesses.latitude        = businessModel.latitude;
                        bsp_Businesses.longitude       = businessModel.longitude;
                        context.bsp_businesses.Add(bsp_Businesses);
                        context.SaveChanges();
                        foreach (var img in businessModel.imgs)
                        {
                            bsp_businessimgs bsp_Businessimgs = new bsp_businessimgs();
                            bsp_Businessimgs.businessid = bsp_Businesses.businessid;
                            bsp_Businessimgs.img        = img.bi_img;
                            context.bsp_businessimgs.Add(bsp_Businessimgs);
                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        bsp_businesses bsp_Businesses = context.bsp_businesses.SingleOrDefault(t => t.businessid == businessModel.businessid);
                        bsp_Businesses.address         = businessModel.address;
                        bsp_Businesses.businessEnd     = businessModel.businessEnd;
                        bsp_Businesses.businessStart   = businessModel.businessStart;
                        bsp_Businesses.businessTimeStr = DateTime.Now.Date.AddMinutes(businessModel.businessStart).ToString("HH:mm") + "-" + DateTime.Now.Date.AddMinutes(businessModel.businessEnd).ToString("HH:mm");
                        bsp_Businesses.description     = businessModel.description;
                        bsp_Businesses.name            = businessModel.name;
                        bsp_Businesses.telphone        = businessModel.telphone;
                        bsp_Businesses.avgconsume      = businessModel.avgconsume;
                        bsp_Businesses.specialserver   = businessModel.specialserver;
                        bsp_Businesses.latitude        = businessModel.latitude;
                        bsp_Businesses.longitude       = businessModel.longitude;
                        context.SaveChanges();

                        var imgs = context.bsp_businessimgs.Where(t => t.businessid == bsp_Businesses.businessid);
                        foreach (var img in imgs)
                        {
                            context.bsp_businessimgs.Remove(img);
                            context.SaveChanges();
                        }

                        foreach (var img in businessModel.imgs)
                        {
                            bsp_businessimgs bsp_Businessimgs = new bsp_businessimgs();
                            bsp_Businessimgs.businessid = bsp_Businesses.businessid;
                            bsp_Businessimgs.img        = img.bi_img;
                            context.bsp_businessimgs.Add(bsp_Businessimgs);
                            context.SaveChanges();
                        }
                    }
                    tran.Commit();
                    InitBusinessCache();
                    return(ResultModel.Success("保存"));
                }
                catch (Exception ex)
                {
                    Logger._.Error("AddOrUpdateBusiness", ex);
                    tran.Rollback();
                    return(ResultModel.Error(ex.ToString()));
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// 编辑商品信息
        /// </summary>
        /// <returns></returns>
        public ResultModel UpdatePorduct(AddProductModel model)
        {
            if (model.skuInfos.Count() != model.skuInfos.Select(t => t.name).Distinct().Count())
            {
                return(ResultModel.Fail("不允许出现重复名称的属性"));
            }
            foreach (var skuinfo in model.skuInfos)
            {
                if (skuinfo.attributevalues.Count() != skuinfo.attributevalues.Select(t => t.attrvalue).Distinct().Count())
                {
                    return(ResultModel.Fail("同一属性下不允许出现重复名称的值"));
                }
            }
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    var pro = context.bsp_products.SingleOrDefault(t => t.pid == model.pid);
                    //pro.addtime = DateTime.Now;
                    pro.cateid           = 0;
                    pro.costprice        = model.costprice;
                    pro.description      = model.description;
                    pro.displayorder     = model.displayorder;
                    pro.isbest           = model.isbest;
                    pro.ishot            = model.ishot;
                    pro.rmddisplayorder  = model.rmddisplayorder;
                    pro.isnew            = model.isnew;
                    pro.isfullcut        = model.isfullcut;
                    pro.marketprice      = model.marketprice;
                    pro.name             = model.name;
                    pro.packprice        = model.packprice;
                    pro.showimg          = model.showimg;
                    pro.shopprice        = model.shopprice;
                    pro.weight           = model.weight;
                    pro.startseckilltime = model.startseckilltime;
                    pro.endseckilltime   = model.endseckilltime;
                    pro.seckillprice     = model.seckillprice;
                    context.SaveChanges();

                    //编辑商品分类信息
                    foreach (var cateid in model.cateids)
                    {
                        bsp_categories   cate        = context.bsp_categories.SingleOrDefault(t => t.cateid == cateid);
                        bsp_cateproducts cateproduct = context.bsp_cateproducts.SingleOrDefault(t => t.pid == pro.pid & t.cateid == cateid);
                        if (cateproduct == null)
                        {
                            cateproduct          = new bsp_cateproducts();
                            cateproduct.cateid   = cateid;
                            cateproduct.catename = cate.name.Trim();
                            cateproduct.pid      = pro.pid;
                            cateproduct.pname    = pro.name;
                            context.bsp_cateproducts.Add(cateproduct);
                        }
                        else
                        {
                            cateproduct.catename = cate.name.Trim();
                            cateproduct.pname    = pro.name;
                        }
                        context.SaveChanges();
                    }
                    //删除不存在的分类信息
                    var deletecateproducts = context.bsp_cateproducts.Where(t => t.pid == pro.pid & !model.cateids.Contains(t.cateid));
                    context.bsp_cateproducts.RemoveRange(deletecateproducts);
                    context.SaveChanges();

                    var attrindex = 0;

                    //添加属性和值
                    foreach (var attribute in model.skuInfos)
                    {
                        bsp_attributes newattribute = new bsp_attributes();
                        if (attribute.attrid == 0)
                        {
                            context.bsp_attributes.Add(newattribute);
                        }//新增的属性
                        else
                        {
                            newattribute = context.bsp_attributes.SingleOrDefault(t => t.attrid == attribute.attrid);
                        }//原有的属性
                        newattribute.name         = attribute.name;
                        newattribute.remark       = attribute.remark;
                        newattribute.displayorder = attrindex++;
                        context.SaveChanges();
                        attribute.attrid = newattribute.attrid;

                        var valueindex = 0;
                        foreach (var value in attribute.attributevalues)
                        {
                            bsp_attributevalues newvalue = new bsp_attributevalues();
                            bsp_productskus     newsku   = new bsp_productskus();
                            if (value.attrvalueid == 0)
                            {
                                newvalue.attrid = newattribute.attrid;
                                context.bsp_attributevalues.Add(newvalue);
                            }//新增值和sku
                            else
                            {
                                newvalue = context.bsp_attributevalues.SingleOrDefault(t => t.attrvalueid == value.attrvalueid);
                            }//原有值
                            newvalue.attrname              = newattribute.name;
                            newvalue.attrvalue             = value.attrvalue;
                            newvalue.attrgroupname         = "";
                            newvalue.isinput               = 0;
                            newvalue.attrdisplayorder      = 0;
                            newvalue.attrshowtype          = 0;
                            newvalue.attrvaluedisplayorder = 0;
                            newvalue.attrgroupid           = 0;
                            newvalue.attrgroupdisplayorder = 0;
                            newvalue.attrdisplayorder      = valueindex++;
                            context.SaveChanges();
                            value.attrvalueid = newvalue.attrvalueid;
                        }
                    }

                    //添加商品的sku信息
                    var skus = GetAllSkuByAttrAndValue(model.skuInfos);

                    //得到商品已有的sku中的valuid,valueid从大到小按逗号分隔组成字符串比较
                    var                       allpskus         = context.bsp_productskus.Where(t => t.pid == pro.pid).ToList();
                    var                       sku_guids        = allpskus.Select(t => t.skuguid).Distinct().ToArray();
                    List <string>             guid_valueidstr  = new List <string>();
                    Dictionary <string, Guid> valueids_skuguid = new Dictionary <string, Guid>();
                    foreach (var sku_guid in sku_guids)
                    {
                        var valueids = allpskus.Where(t => t.skuguid == sku_guid).OrderBy(t => t.attrvalueid).Select(t => t.attrvalueid.ToString()).ToArray();
                        guid_valueidstr.Add(string.Join(",", valueids));
                        if (!valueids_skuguid.ContainsKey(string.Join(",", valueids)))
                        {
                            valueids_skuguid.Add(string.Join(",", valueids), sku_guid);
                        }
                    }
                    guid_valueidstr = guid_valueidstr.Distinct().ToList();
                    List <string> newvalueids = new List <string>();
                    foreach (var sku in skus)
                    {
                        var valueids      = sku.OrderBy(t => t.valueid).Select(t => t.valueid.ToString()).ToArray();
                        var nowvalueidstr = string.Join(",", valueids);
                        newvalueids.Add(nowvalueidstr);
                        //该sku不存在,则新增
                        if (!guid_valueidstr.Contains(nowvalueidstr))
                        {
                            Guid newskuguid = Guid.NewGuid();
                            foreach (var s in sku)
                            {
                                bsp_productskus newsku = new bsp_productskus();
                                newsku.attrid         = (short)s.attrid;
                                newsku.attrvalueid    = s.valueid;
                                newsku.inputattr      = model.skuInfos.FirstOrDefault(t => t.attrid == newsku.attrid).name;
                                newsku.inputvalue     = model.skuInfos.FirstOrDefault(t => t.attrid == newsku.attrid).attributevalues.FirstOrDefault(t => t.attrvalueid == newsku.attrvalueid).attrvalue;
                                newsku.isdefaultprice = 1;
                                newsku.pid            = pro.pid;
                                newsku.price          = -1;
                                newsku.skugid         = 0;
                                newsku.skuguid        = newskuguid;
                                newsku.stock          = -1;
                                context.bsp_productskus.Add(newsku);
                                context.SaveChanges();
                            }
                        }
                        else
                        {
                            //sku存在更新sku相关的属性和值信息
                            var skuGuid  = sku_guids[guid_valueidstr.IndexOf(nowvalueidstr)];
                            var skuItems = context.bsp_productskus.Where(t => t.skuguid == skuGuid).ToList();
                            foreach (var skuItem in skuItems)
                            {
                                skuItem.inputattr  = model.skuInfos.SingleOrDefault(t => t.attrid == skuItem.attrid).name;
                                skuItem.inputvalue = model.skuInfos.SingleOrDefault(t => t.attrid == skuItem.attrid).attributevalues.SingleOrDefault(t => t.attrvalueid == skuItem.attrvalueid).attrvalue;
                            }
                        }
                    }
                    //将不需要的sku删除
                    foreach (var exist_valuestr in guid_valueidstr)
                    {
                        if (!newvalueids.Contains(exist_valuestr))
                        {
                            var guidstr  = valueids_skuguid[exist_valuestr].ToString();
                            var skuitems = context.bsp_productskus.Where(t => t.skuguid.ToString() == guidstr).ToList();
                            context.bsp_productskus.RemoveRange(skuitems);
                        }
                    }
                    context.SaveChanges();

                    var proimgs = context.bsp_productimages.Where(t => t.pid == model.pid).ToList();
                    context.bsp_productimages.RemoveRange(proimgs);
                    context.SaveChanges();

                    //修改商品图片
                    if (model.mainImgs != null)
                    {
                        foreach (var img in model.mainImgs)
                        {
                            bsp_productimages newimg = new bsp_productimages();
                            newimg.displayorder = img.displayorder;
                            newimg.ismain       = 1;
                            newimg.pid          = pro.pid;
                            newimg.showimg      = img.showimg;
                            context.bsp_productimages.Add(newimg);
                            context.SaveChanges();
                        }
                    }

                    if (model.detailImgs != null)
                    {
                        foreach (var img in model.detailImgs)
                        {
                            bsp_productimages newimg = new bsp_productimages();
                            newimg.displayorder = img.displayorder;
                            newimg.ismain       = 0;
                            newimg.pid          = pro.pid;
                            newimg.showimg      = img.showimg;
                            context.bsp_productimages.Add(newimg);
                            context.SaveChanges();
                        }
                    }


                    tran.Commit();
                    new ProductCache().Init();
                    return(ResultModel.Success("修改成功"));
                }
                catch (Exception ex)
                {
                    Logger._.Error(ex);
                    tran.Rollback();
                    return(ResultModel.Error(ex.ToString()));
                }
            }
        }