Exemplo n.º 1
0
 /// <summary>
 /// 修改现金券
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>true if XXXX, false otherwise.</returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public static bool UpdateCashCoupon(CashCouponModel model)
 {
     using (var dal = FactoryDispatcher.CouponFactory())
     {
         return(dal.UpdateCashCoupon(model));
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 编辑优惠券
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>true if XXXX, false otherwise.</returns>
 public static bool EditCashCoupon(CashCouponModel model)
 {
     if (model.CouponId > 0)
     {
         return(UpdateCashCoupon(model));
     }
     else
     {
         return(AddCashCoupon(model) > 0);
     }
 }
Exemplo n.º 3
0
        public static MyCouponListModel ToMyCouponList(CashCouponModel item)
        {
            MyCouponListModel model = new MyCouponListModel();

            model.due   = item.StartTime.ToString("yyyy.MM.dd") + "-" + item.EndTime.ToString("yyyy.MM.dd");
            model.ID    = item.CouponId;
            model.money = item.Money;
            model.name  = item.Title;
            model.url   = WebConfig.articleDetailsDomain() + "/app/couponshare.html";
            return(model);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 修改现金券
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>true if XXXX, false otherwise.</returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public bool UpdateCashCoupon(CashCouponModel model)
        {
            string strSql = "update BM_CashCoupon set Title=@Title,Money=@Money,StartTime=@StartTime,EndTime=@EndTime,IsEnable=@IsEnable,Remark=@Remark where CouponId=@CouponId";
            var    parm   = new[] {
                new SqlParameter("@Title", model.Title),
                new SqlParameter("@Money", model.Money),
                new SqlParameter("@StartTime", model.StartTime),
                new SqlParameter("@EndTime", model.EndTime),
                new SqlParameter("@IsEnable", model.IsEnable),
                new SqlParameter("@CouponId", model.CouponId),
                new SqlParameter("@Remark", model.Remark)
            };

            return(DbHelperSQLP.ExecuteNonQuery(WebConfig.getConnectionString(), CommandType.Text, strSql.ToString(), parm) > 0);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 添加优惠券发送记录
        /// </summary>
        /// <param name="userId">发送人ID</param>
        /// <param name="Int32">The int32.</param>
        /// <param name="userIdentity">用户身份,0盟友  1盟主.</param>
        /// <param name="sendToUserId">接收用户ID,如果是自己转发,则为0</param>
        /// <param name="couponId">优惠券ID</param>
        /// <returns>true if XXXX, false otherwise.</returns>
        public static bool AddSendCoupon(int userId, int userIdentity, int sendToUserId, int couponId)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                using (var dal = FactoryDispatcher.CouponFactory())
                {
                    bool flag = dal.AddSendCoupon(userId, sendToUserId, couponId);

                    //如果盟主自己分享或发送给盟友,则创建现金券记录
                    if (flag && userIdentity == 1)
                    {
                        CashCouponModel couponModel = dal.GetModel(couponId);
                        if (couponModel != null)
                        {
                            int BelongOneUserId = userId;

                            int belongOneShopId = ShopLogic.GetBelongShopId(couponModel.ShopId);
                            if (belongOneShopId == 0)
                            {
                                belongOneShopId = couponModel.ShopId;
                            }

                            dal.CreateUserCashCouponLog(new CashCouponLogModel()
                            {
                                CouponId        = couponId,
                                CouponNo        = couponModel.ShopId.ToString() + StringHelper.CreateCheckCodeWithNum(10).ToLower(),
                                UserId          = sendToUserId > 0 ? sendToUserId : userId,
                                IsShare         = sendToUserId > 0 ? 0 : 1,
                                Money           = couponModel.Money,
                                StartTime       = couponModel.StartTime,
                                EndTime         = couponModel.EndTime,
                                ShopId          = couponModel.ShopId,
                                BelongOneUserId = BelongOneUserId,
                                BelongOneShopId = belongOneShopId
                            });
                        }
                    }
                    if (flag && userIdentity == 0)
                    {
                        dal.UpdateCouponShareStatus(userId, couponId);
                    }

                    scope.Complete();
                    return(flag);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///给盟友发送优惠券
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <param name="couponId">The coupon identifier.</param>
        /// <param name="TargetIds">The target ids.</param>
        /// <returns>true if XXXX, false otherwise.</returns>
        public static bool AddSendAllyCoupon(int userId, int couponId, string[] TargetIds)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                using (var dal = FactoryDispatcher.CouponFactory())
                {
                    bool flag = dal.AddSendCoupon(userId, 0, couponId);

                    //如果盟主自己分享或发送给盟友,则创建现金券记录
                    CashCouponModel couponModel = dal.GetModel(couponId);
                    if (couponModel != null)
                    {
                        int    BelongOneUserId = userId;
                        string cpNo            = couponModel.ShopId.ToString() + StringHelper.CreateCheckCodeWithNum(10).ToLower();
                        foreach (var item in TargetIds)
                        {
                            int sendToUserId = Convert.ToInt32(item);

                            int belongOneShopId = ShopLogic.GetBelongShopId(couponModel.ShopId);
                            if (belongOneShopId == 0)
                            {
                                belongOneShopId = couponModel.ShopId;
                            }

                            dal.CreateUserCashCouponLog(new CashCouponLogModel()
                            {
                                CouponId        = couponId,
                                CouponNo        = cpNo,
                                UserId          = sendToUserId,
                                IsShare         = 0,
                                Money           = couponModel.Money,
                                StartTime       = couponModel.StartTime,
                                EndTime         = couponModel.EndTime,
                                ShopId          = couponModel.ShopId,
                                BelongOneUserId = BelongOneUserId,
                                BelongOneShopId = belongOneShopId
                            });
                        }
                    }
                    scope.Complete();
                    return(flag);
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// 添加现金券
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>System.Int32.</returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public static int AddCashCoupon(CashCouponModel model)
 {
     using (var dal = FactoryDispatcher.CouponFactory())
     {
         int flag = dal.AddCashCoupon(model);
         if (flag > 0)
         {
             //添加优惠券领取操作日志
             LogLogic.AddCouponLog(new LogBaseModel()
             {
                 objId         = flag,
                 UserId        = flag,
                 ShopId        = model.ShopId,
                 OperationType = 0,//0创建 1领取 2使用
                 Money         = model.Money
             });
         }
         return(flag);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// 添加现金券
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>System.Int32.</returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public int AddCashCoupon(CashCouponModel model)
        {
            string strSql = "insert into BM_CashCoupon(ShopId,Title,Money,StartTime,EndTime,IsEnable,Remark) values(@ShopId,@Title,@Money,@StartTime,@EndTime,@IsEnable,@Remark);select @@IDENTITY;";
            var    parm   = new[] {
                new SqlParameter("@Title", model.Title),
                new SqlParameter("@Money", model.Money),
                new SqlParameter("@StartTime", model.StartTime),
                new SqlParameter("@EndTime", model.EndTime),
                new SqlParameter("@IsEnable", model.IsEnable),
                new SqlParameter("@ShopId", model.ShopId),
                new SqlParameter("@Remark", model.Remark)
            };
            object obj = DbHelperSQLP.ExecuteScalar(WebConfig.getConnectionString(), CommandType.Text, strSql.ToString(), parm);

            if (obj != null)
            {
                return(Convert.ToInt32(obj));
            }
            return(0);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 获取优惠券信息
        /// </summary>
        /// <param name="couponId">The coupon identifier.</param>
        /// <param name="isValid">是否只获取有效的优惠券</param>
        /// <returns>CashCouponModel.</returns>
        public CashCouponModel GetModel(int couponId, bool isValid = false)
        {
            CashCouponModel model  = new CashCouponModel();
            string          strSql = SELECT_SQL + " and CouponId=@CouponId";

            if (isValid)
            {
                strSql += " and EndTime>@Date and IsEnable=1 ";
            }
            var parms = new[] {
                new SqlParameter("@CouponId", couponId),
                new SqlParameter("@Date", DateTime.Now)
            };

            using (IDataReader dr = DbHelperSQLP.ExecuteReader(WebConfig.getConnectionString(), CommandType.Text, strSql.ToString(), parms))
            {
                model = DbHelperSQLP.GetEntity <CashCouponModel>(dr);
            }
            return(model);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 编辑优惠券
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>true if XXXX, false otherwise.</returns>
        public bool EditCashCoupon(CashCouponModel model)
        {
            string[] ids = model.ShopIds.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            string[] goodsids = model.GoodsIds.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            bool     result   = false;

            using (TransactionScope scope = new TransactionScope())
            {
                int couponId = 0, couponIdTwo = 0;

                if (model.CouponId > 0)
                {
                    var couponModel = dal.GetCouponModel(model.CouponId);
                    if (couponModel != null)
                    {
                        result = dal.UpdateCashCoupon(model);
                        if (result)
                        {
                            if (string.IsNullOrEmpty(couponModel.ShopIds))
                            {
                                couponId = couponModel.CouponId;
                            }

                            if (string.IsNullOrEmpty(couponModel.GoodsIds))
                            {
                                couponIdTwo = couponModel.CouponId;
                            }
                        }
                    }
                }
                else
                {
                    couponId    = dal.AddCashCoupon(model);
                    couponIdTwo = couponId;
                }
                if (couponId > 0)
                {
                    if (model.ShopIds != "-100")
                    {
                        foreach (var shopId in ids)
                        {
                            if (!string.IsNullOrEmpty(shopId))
                            {
                                dal.AddShopCouponInfo(Convert.ToInt32(shopId), couponId);
                            }
                        }
                    }
                    else
                    {
                        List <ShopModel> lst = dal.GetShopIds(model.BrandId);
                        foreach (var item in lst)
                        {
                            dal.AddShopCouponInfo(item.ShopID, couponId);
                        }
                    }
                    result = true;
                }

                if (couponIdTwo > 0)
                {
                    if (model.GoodsIds != "-100")
                    {
                        foreach (var goodsid in goodsids)
                        {
                            if (!string.IsNullOrEmpty(goodsid))
                            {
                                dal.AddGoodsCouponInfo(Convert.ToInt32(goodsid), couponId);
                            }
                        }
                    }
                    result = true;
                }
                scope.Complete();
            }
            return(result);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 领取优惠券
        /// </summary>
        private void CouponGet()
        {
            try
            {
                int    uid         = GetFormValue("userid", 0);
                int    cpid        = GetFormValue("cpid", 0);
                string username    = GetFormValue("username", "");
                string usermobile  = GetFormValue("usermobile", "");
                string requestSign = GetFormValue("sign", "");

                Dictionary <string, string> paramters = new Dictionary <string, string>();
                paramters.Add("userid", uid.ToString());
                paramters.Add("cpid", cpid.ToString());
                string currentSign = SignatureHelper.BuildSign(paramters, ConstConfig.SECRET_KEY);
                if (!requestSign.Equals(currentSign))
                {
                    json = JsonHelper.JsonSerializer(new ResultModel(ApiStatusCode.未授权));
                }
                else
                {
                    if (!RegexHelper.IsValidMobileNo(usermobile))
                    {
                        json = JsonHelper.JsonSerializer(new ResultModel(ApiStatusCode.无效手机号));
                        return;
                    }

                    //
                    lock (objCouponGetLocked)
                    {
                        CashCouponLogModel logModel = CouponLogic.GetCashCouponLogIDByUserID(uid, cpid);
                        if (logModel != null)
                        {
                            using (TransactionScope scope = new TransactionScope())
                            {
                                bool flag = CouponLogic.UpdateUserCashCouponGetLog(new CashCouponLogModel()
                                {
                                    UserId = uid,
                                    ID     = logModel.ID,
                                    Name   = username,
                                    Mobile = usermobile
                                });
                                if (flag)
                                {
                                    Dictionary <string, object> dict = new Dictionary <string, object>();
                                    dict["couponNo"] = logModel.CouponNo;
                                    json             = JsonHelper.JsonSerializer(new ResultModel(ApiStatusCode.OK, dict));

                                    CouponLogic.DeleteUserCashCoupon(logModel.CouponNo, logModel.CouponId, uid);
                                    var user = UserLogic.GetModel(uid);
                                    if (user != null)
                                    {
                                        CashCouponModel model = CouponLogic.GetModel(cpid, true);
                                        //添加优惠券领取操作日志
                                        LogLogic.AddCouponLog(new LogBaseModel()
                                        {
                                            objId         = model.CouponId,
                                            UserId        = user.UserId,
                                            ShopId        = logModel.ShopId,
                                            OperationType = 1,//0创建 1领取 2使用
                                            Money         = logModel.Money
                                        });
                                    }

                                    try
                                    {
                                        var shopData = ShopLogic.GetShopModel(logModel.ShopId);
                                        if (shopData != null)
                                        {
                                            string errmsg  = "";
                                            string content = string.Format("您收到一张新的{0}元现金券,现金券使用码:{1},您可在{2}前到门店消费使用。门店地址:{3}",
                                                                           logModel.Money,
                                                                           logModel.CouponNo,
                                                                           logModel.StartTime.ToString("yyyy.MM.dd") + "-" + logModel.EndTime.ToString("yyyy.MM.dd"),
                                                                           shopData.ShopProv + shopData.ShopCity + shopData.ShopAddress + shopData.ShopName
                                                                           );
                                            if (!string.IsNullOrEmpty(usermobile) && RegexHelper.IsValidMobileNo(usermobile))
                                            {
                                                SmsLogic.send(1, usermobile, content, out errmsg);
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        LogHelper.Log(string.Format("Message:{0},StackTrace:{1}", ex.Message, ex.StackTrace), LogHelperTag.ERROR);
                                    }
                                }
                                else
                                {
                                    json = JsonHelper.JsonSerializer(new ResultModel(ApiStatusCode.SERVICEERROR));
                                }

                                scope.Complete();
                            }
                        }
                        else
                        {
                            json = JsonHelper.JsonSerializer(new ResultModel(ApiStatusCode.现金券已领完));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(string.Format("Message:{0},StackTrace:{1}", ex.Message, ex.StackTrace), LogHelperTag.ERROR);
                json = JsonHelper.JsonSerializer(new ResultModel(ApiStatusCode.SERVICEERROR));
            }
        }