Example #1
0
        /// <summary>
        /// 保存优惠券
        /// </summary>
        /// <param name="coupon">促销规则实体</param>
        /// <param name="user">操作者</param>
        /// <param name="originalCoupon">原优惠卷(复制优惠卷时使用)</param>
        /// <param name="couponCardNo">优惠卡号(复制优惠卡时使用)</param>
        /// <returns></returns>
        /// <remarks>
        /// 2013-08-22 黄志勇 创建
        /// 日期 朱家宏 添加参数:originalCoupon/couponCardNo
        /// </remarks>
        public int SaveCoupon(SpCoupon coupon, SyUser user, SpCoupon originalCoupon = null, string couponCardNo = null)
        {
            coupon.LastUpdateBy   = user.SysNo;
            coupon.LastUpdateDate = DateTime.Now;
            if (coupon.SysNo > 0)
            {
                return(ISpCouponDao.Instance.Update(coupon));
            }

            coupon.CreatedBy   = user.SysNo;
            coupon.CreatedDate = DateTime.Now;

            var couponSysNo = ISpCouponDao.Instance.Insert(coupon);

            //2013-12-30 朱家宏 私有优惠卷时写日志
            if (couponSysNo > 0 && coupon.Type == (int)PromotionStatus.优惠券类型.私有)
            {
                //需求为仅在新建(包括复制)私有优惠卷时写日志,其他情况下不管
                var originalCouponSysNo = (originalCoupon == null) ? 0 : originalCoupon.SysNo;
                var log = new SpCouponReceiveLog
                {
                    CouponSysNo         = couponSysNo,
                    OriginatorSysNo     = user.SysNo,
                    RecipientSysNo      = coupon.CustomerSysNo,
                    ReceiveTime         = coupon.CreatedDate,
                    CouponCardNo        = couponCardNo,
                    OriginalCouponSysNo = originalCouponSysNo
                };
                SpCouponReceiveLogBo.Instance.Insert(log);
            }
            return(couponSysNo);
        }
Example #2
0
        /// <summary>
        /// 保存优惠券
        /// </summary>
        /// <param name="coupon">促销规则实体</param>
        /// <param name="userSysNo">操作者</param>
        /// <param name="originalCoupon">原优惠卷(复制优惠卷时使用)</param>
        /// <param name="couponCardNo">优惠卡号(复制优惠卡时使用)</param>
        /// <returns></returns>
        /// <remarks>2013-12-31 黄波 创建</remarks>
        public int SaveCoupon(SpCoupon coupon, int userSysNo, SpCoupon originalCoupon = null, string couponCardNo = null)
        {
            var syUser = new SyUser {
                SysNo = userSysNo
            };

            return(SaveCoupon(coupon, syUser));
        }
Example #3
0
        /// <summary>
        /// 根据优惠券代码获取优惠券
        /// </summary>
        /// <param name="couponCode">优惠券代码</param>
        /// <returns>优惠券信息</returns>
        /// <remarks>2014-03-28 唐永勤 创建</remarks>
        public override SpCoupon GetSpCouponByCouponCode(string couponCode)
        {
            SpCoupon entity = Context.Select <SpCoupon>("*")
                              .From("SpCoupon")
                              .Where("CouponCode = @CouponCode")
                              .Parameter("CouponCode", couponCode)
                              .QuerySingle();

            return(entity);
        }
Example #4
0
 /// <summary>
 /// 插入数据
 /// </summary>
 /// <param name="entity">数据实体</param>
 /// <returns>新增记录编号</returns>
 /// <remarks>2013-08-21  朱成果 创建</remarks>
 public override int Insert(SpCoupon entity)
 {
     if (entity.AuditDate == DateTime.MinValue)
     {
         entity.AuditDate = (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;
     }
     entity.SysNo = Context.Insert("SpCoupon", entity)
                    .AutoMap(o => o.SysNo)
                    .ExecuteReturnLastId <int>("SysNo");
     return(entity.SysNo);
 }
Example #5
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity">数据实体</param>
        /// <returns>影响的行</returns>
        /// <remarks>2013-08-21  朱成果 创建</remarks>
        public override int Update(SpCoupon entity)
        {
            int      SysNo  = entity.SysNo;
            SpCoupon Entity = GetEntity(SysNo);

            entity.AuditDate   = Entity.AuditDate;
            entity.CreatedDate = Entity.CreatedDate;

            return(Context.Update("SpCoupon", entity)
                   .AutoMap(o => o.SysNo)
                   .Where("SysNo", entity.SysNo)
                   .Execute());
        }
Example #6
0
 /// <summary>
 /// 更新数据
 /// </summary>
 /// <param name="entity">数据实体</param>
 /// <returns>影响的行</returns>
 /// <remarks>2013-08-21  朱成果 创建</remarks>
 public abstract int Update(SpCoupon entity);
Example #7
0
 /// <summary>
 /// 插入数据
 /// </summary>
 /// <param name="entity">数据实体</param>
 /// <returns>新增记录编号</returns>
 /// <remarks>2013-08-21  朱成果 创建</remarks>
 public abstract int Insert(SpCoupon entity);
Example #8
0
        /// <summary>
        /// 绑定优惠卡
        /// </summary>
        /// <param name="couponCardNo">优惠卡号</param>
        /// <param name="couponSysNo">优惠卷编号</param>
        /// <param name="customerSysNo">客户编号</param>
        /// <param name="recordNum">操作次数</param>
        /// <param name="syUser">当前用户</param>
        /// <param name="action">绑定优惠卡回调</param>
        /// <returns>分配成功后的优惠卷新编号</returns>
        /// <remarks>2014-01-08 朱家宏 创建</remarks>
        public int AssignToCustomer(string couponCardNo, int couponSysNo, int customerSysNo, int recordNum = 1, SyUser syUser = null, Action <int> action = null)
        {
            /*
             * 优惠卡、优惠卡类型条件:
             *
             * 1.优惠卡状态为启用
             *
             * 2.优惠卡类型状态为启用
             *
             * 3.优惠卡类型有效日期大于当前
             *
             * 4.未分配过给该客户的优惠卡
             *
             * 5.更新优惠卡激活、中止日期
             */

            /*
             * 优惠卷条件:
             *
             * 1.查询条件:所选优惠卷为系统、优惠卷状态为已审核、结束日期大于当前、允许使用数量>0
             *
             * 2.复制后初始数据:优惠卷类型为私有,允许使用数量为1,已使用数量为0,客户系统编号为指定客户,生成新的优惠卷随机代码,
             *   状态为待审核,审核人、创建人为当前用户,审核日期、创建日期为当前日期、是优惠卡
             *
             * 3.更新源优惠卷:已使用数量+1,更新人为当前用户,更新日期为当前日期
             *
             * 4.完成复制后,对该优惠卷仅提供审核和作废
             *
             * 5.操作权限,具备优惠卷操作权限的用户,或优惠卷的创建用户
             */

            #region 优惠卡、优惠卡类型数据校验

            if (string.IsNullOrWhiteSpace(couponCardNo))
            {
                throw new ArgumentNullException("couponCardNo");
            }

            var couponCard = ISpCouponCardDao.Instance.Get(couponCardNo);
            if (couponCard == null)
            {
                throw new HytException("未找到优惠卡");
            }

            if (couponCard.Status == (int)PromotionStatus.优惠券卡状态.禁用)
            {
                throw new HytException("不能使用未启用的优惠卡号");
            }

            var couponCardType = ISpCouponCardTypeDao.Instance.GetEntity(couponCard.CardTypeSysNo);
            if (couponCardType == null)
            {
                throw new HytException("未找到优惠卡类型");
            }

            if (couponCardType.Status == (int)PromotionStatus.优惠券卡类型状态.禁用)
            {
                throw new HytException("不能使用未启用的优惠卡类型");
            }

            if (couponCardType.EndTime < DateTime.Now)
            {
                throw new HytException("优惠卡类型已过期");
            }

            if (recordNum == 1)
            {
                var assigned = ISpCouponReceiveLogDao.Instance.HasGet(couponCardNo, customerSysNo);
                if (assigned)
                {
                    throw new HytException("不能重复绑定优惠卡");
                }

                if (couponCard.ActivationTime != DateTime.MinValue)
                {
                    throw new HytException("优惠卡已经被其他用户绑定过,不能重复绑定");
                }
            }

            var associations          = ISpCouponCardAssociateDao.Instance.GetAllByCardTypeSysNo(couponCardType.SysNo);
            var couponCardAssociation = associations.First(o => o.CouponSysNo == couponSysNo);
            if (couponCardAssociation == null)
            {
                throw new HytException("未能找到优惠卡、卷关联");
            }

            #endregion

            var newCouponSysNo = 0;
            var coupon         = PromotionBo.Instance.GetEntity(couponSysNo);

            #region 优惠卷数据校验

            if (coupon.WebPlatform == 0 && coupon.ShopPlatform == 0 && coupon.MallAppPlatform == 0 &&
                coupon.LogisticsAppPlatform == 0)
            {
                throw new HytException("优惠卷没有选择任何使用平台");
            }

            if (coupon.Status == (int)PromotionStatus.优惠券状态.作废)
            {
                throw new HytException("优惠卡已经作废,绑定失败");
            }

            if (coupon.Type != (int)PromotionStatus.优惠券类型.系统 ||
                coupon.Status != (int)PromotionStatus.优惠券状态.已审核 ||
                coupon.EndTime < DateTime.Now)
            {
                return(newCouponSysNo);
            }

            #endregion

            #region  制优惠卷,初始数据

            if (syUser == null)
            {
                syUser = AdminAuthenticationBo.Instance.Current.Base;
            }
            var bindNumber = couponCardAssociation.BindNumber;
            for (var i = 1; i <= bindNumber; i++)
            {
                var newCoupon = new SpCoupon
                {
                    SysNo         = 0,
                    Type          = (int)PromotionStatus.优惠券类型.私有,
                    UseQuantity   = 1,
                    UsedQuantity  = 0,
                    CustomerSysNo = customerSysNo,
                    CouponCode    = SpCouponBo.Instance.GenerateNewCouponCode(),
                    Status        = (int)PromotionStatus.优惠券状态.待审核,

                    CouponAmount         = coupon.CouponAmount,
                    Description          = coupon.Description,
                    StartTime            = coupon.StartTime,
                    EndTime              = coupon.EndTime,
                    ParentSysNo          = coupon.ParentSysNo,
                    PromotionSysNo       = coupon.PromotionSysNo,
                    RequirementAmount    = coupon.RequirementAmount,
                    SourceDescription    = Constant.COUPONDESCRIPTION_BINDUSERCOUPON,
                    IsCouponCard         = (int)PromotionStatus.是否优惠卡.是,
                    WebPlatform          = coupon.WebPlatform,
                    ShopPlatform         = coupon.ShopPlatform,
                    MallAppPlatform      = coupon.MallAppPlatform,
                    LogisticsAppPlatform = coupon.LogisticsAppPlatform
                };
                newCouponSysNo = PromotionBo.Instance.SaveCoupon(newCoupon, syUser, coupon, couponCardNo);
                if (action != null)
                {
                    action(newCouponSysNo);
                }
            }

            #endregion

            #region 更新原优惠卷

            //coupon.UsedQuantity++;
            //PromotionBo.Instance.SaveCoupon(coupon, AdminAuthenticationBo.Instance.Current.Base);

            #endregion

            #region 更新优惠卡激活、中止日期

            couponCard.ActivationTime  = DateTime.Now;
            couponCard.TerminationTime = DateTime.Now;
            ISpCouponCardDao.Instance.Update(couponCard);

            #endregion

            return(newCouponSysNo);
        }
Example #9
0
        /// <summary>
        /// 为客户分配优惠卷
        /// </summary>
        /// <param name="couponSysNo">优惠卷编号</param>
        /// <param name="customerSysNo">客户编号</param>
        /// <returns>分配成功后的优惠卷新编号</returns>
        /// <remarks>2013/12/05 朱家宏 创建</remarks>
        /// <remarks>2013/12/31 黄波 复制</remarks>
        public int AssignToCustomer(int couponSysNo, int customerSysNo)
        {
            /*
             * 1.查询条件:所选优惠卷为系统、优惠卷状态为已审核、结束日期大于当前、允许使用数量>0
             *
             * 2.复制后初始数据:优惠卷类型为私有,允许使用数量为1,已使用数量为0,客户系统编号为指定客户,生成新的优惠卷随机代码,
             *   状态为待审核,审核人、创建人为当前用户,审核日期、创建日期为当前日期
             *
             * 3.更新源优惠卷:已使用数量+1,更新人为当前用户,更新日期为当前日期
             *
             * 4.完成复制后,对该优惠卷仅提供审核和作废
             *
             * 5.操作权限,具备优惠卷操作权限的用户,或优惠卷的创建用户
             */
            var newCouponSysNo = 0;
            var coupon         = PromotionBo.Instance.GetEntity(couponSysNo);

            #region 数据校验

            if (coupon.Type != (int)PromotionStatus.优惠券类型.系统 ||
                coupon.Status != (int)PromotionStatus.优惠券状态.已审核 ||
                coupon.EndTime < DateTime.Now ||
                coupon.UseQuantity <= 0 ||
                coupon.UsedQuantity >= coupon.UseQuantity)
            {
                return(newCouponSysNo);
            }

            #endregion

            #region  制优惠卷,初始数据

            var newCoupon = new SpCoupon
            {
                SysNo         = 0,
                Type          = (int)PromotionStatus.优惠券类型.私有,
                UseQuantity   = 1,
                UsedQuantity  = 0,
                CustomerSysNo = customerSysNo,
                CouponCode    = Hyt.BLL.Promotion.SpCouponBo.Instance.GenerateNewCouponCode(),
                Status        = (int)PromotionStatus.优惠券状态.已审核,

                CouponAmount      = coupon.CouponAmount,
                Description       = coupon.Description,
                StartTime         = coupon.StartTime,
                EndTime           = coupon.EndTime,
                ParentSysNo       = coupon.ParentSysNo,
                PromotionSysNo    = coupon.PromotionSysNo,
                RequirementAmount = coupon.RequirementAmount,
                SourceDescription = Model.SystemPredefined.Constant.COUPONDESCRIPTION_BINDUSERCOUPON,
                IsCouponCard      = coupon.IsCouponCard,
                //2014-01-07 朱家宏 添加:优惠卷表新增字段
                WebPlatform          = coupon.WebPlatform,
                ShopPlatform         = coupon.ShopPlatform,
                MallAppPlatform      = coupon.MallAppPlatform,
                LogisticsAppPlatform = coupon.LogisticsAppPlatform
            };
            newCouponSysNo = PromotionBo.Instance.SaveCoupon(newCoupon, 0, coupon);

            #endregion

            #region 更新原优惠卷

            coupon.UsedQuantity++;
            PromotionBo.Instance.SaveCoupon(coupon, 0);

            #endregion

            return(newCouponSysNo);
        }