Example #1
0
 /// <summary>
 /// 创建用户现金券(盟主分享现金券时调用)
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>true if XXXX, false otherwise.</returns>
 public static int CreateUserCashCouponLog(CashCouponLogModel model)
 {
     using (var dal = FactoryDispatcher.CouponFactory())
     {
         return(dal.CreateUserCashCouponLog(model));
     }
 }
Example #2
0
 /// <summary>
 /// 更新现金券的领取记录
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>true if XXXX, false otherwise.</returns>
 public static bool UpdateUserCashCouponGetLog(CashCouponLogModel model)
 {
     using (var dal = FactoryDispatcher.CouponFactory())
     {
         return(dal.UpdateUserCashCouponGetLog(model));
     }
 }
Example #3
0
        /// <summary>
        /// 获取优惠券信息
        /// </summary>
        private void GetCouponInfo()
        {
            int    uid         = GetFormValue("userid", 0);
            int    cpid        = GetFormValue("cpid", 0);
            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
            {
                // CashCouponModel model = CouponLogic.GetModel(cpid, true);
                CashCouponLogModel model = CouponLogic.GetCashCouponLogIDByUserID(uid, cpid);
                if (model != null)
                {
                    Dictionary <string, object> data = new Dictionary <string, object>();
                    data["time"]   = model.StartTime.ToString("yyyy.MM.dd") + "-" + model.EndTime.ToString("yyyy.MM.dd");
                    data["money"]  = model.Money;
                    data["remark"] = model.Remark;
                    data["url"]    = "http://" + ctx.Request.Url.Host + string.Format("/app/getcoupon.html?userid={0}&cpid={1}&sign={2}", uid, cpid, currentSign);
                    json           = JsonHelper.JsonSerializer(new ResultModel(ApiStatusCode.OK, data));
                }
                else
                {
                    json = JsonHelper.JsonSerializer(new ResultModel(ApiStatusCode.现金券已领完));
                }
            }
        }
Example #4
0
        /// <summary>
        /// 更新现金券的领取记录
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>true if XXXX, false otherwise.</returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public bool UpdateUserCashCouponGetLog(CashCouponLogModel model)
        {
            string strSql = "update BM_GetCashCouponLog set Mobile=@Mobile,Name=@Name,IsGet=1,GetTime=GETDATE() where ID=@ID and UserId=@UserId";
            var    parms  = new[] {
                new SqlParameter("@Mobile", model.Mobile),
                new SqlParameter("@Name", model.Name),
                new SqlParameter("@UserId", model.UserId),
                new SqlParameter("@ID", model.ID)
            };

            return(DbHelperSQLP.ExecuteNonQuery(WebConfig.getConnectionString(), CommandType.Text, strSql.ToString(), parms) > 0);
        }
Example #5
0
        /// <summary>
        /// 获取优惠卷信息
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="cashNo"></param>
        /// <returns></returns>
        public CashCouponLogModel getEnableCashCouponLogModel(string mobile, string cashNo)
        {
            CashCouponLogModel model  = new CashCouponLogModel();
            string             strSql = "select * from BM_GetCashCouponLog where CouponNo=@CouponNo and Mobile=@Mobile and IsGet=1 and IsDel=0 ";
            var parms = new[] {
                new SqlParameter("@CouponNo", cashNo),
                new SqlParameter("@Mobile", mobile)
            };

            using (IDataReader dr = DbHelperSQLP.ExecuteReader(WebConfig.getConnectionString(), CommandType.Text, strSql.ToString(), parms))
            {
                model = DbHelperSQLP.GetEntity <CashCouponLogModel>(dr);
            }
            return(model);
        }
Example #6
0
        /// <summary>
        /// 创建用户现金券(盟主分享现金券时调用)
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>true if XXXX, false otherwise.</returns>
        public int CreateUserCashCouponLog(CashCouponLogModel model)
        {
            string strSql = "insert into BM_GetCashCouponLog(UserId,CouponNo,CouponId,StartTime,EndTime,Money,IsShare,ShopId,BelongOneUserId,BelongOneShopId) values(@UserId,@CouponNo,@CouponId,@StartTime,@EndTime,@Money,@IsShare,@ShopId,@BelongOneUserId,@BelongOneShopId);select @@IDENTITY";
            var    parm   = new[] {
                new SqlParameter("@UserId", model.UserId),
                new SqlParameter("@CouponId", model.CouponId),
                new SqlParameter("@CouponNo", model.CouponNo),
                new SqlParameter("@StartTime", model.StartTime),
                new SqlParameter("@EndTime", model.EndTime),
                new SqlParameter("@Money", model.Money),
                new SqlParameter("@IsShare", model.IsShare),
                new SqlParameter("@ShopId", model.ShopId),
                new SqlParameter("@BelongOneUserId", model.BelongOneUserId),
                new SqlParameter("@BelongOneShopId", model.BelongOneShopId)
            };
            object obj = DbHelperSQLP.ExecuteScalar(WebConfig.getConnectionString(), CommandType.Text, strSql.ToString(), parm);

            if (obj != null)
            {
                return(Convert.ToInt32(obj));
            }
            return(0);
        }
Example #7
0
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <param name="shopId">The shop identifier.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="mobile">The mobile.</param>
        /// <param name="address">The address.</param>
        /// <param name="cashNo">The cash no.</param>
        /// <param name="memo">The memo.</param>
        /// <param name="filename">The filename.</param>
        /// <param name="apiCode">The API code.</param>
        /// <returns>true if XXXX, false otherwise.</returns>
        public static bool saveOrder(int userId, int shopId, string userName, string mobile, string address, string cashNo, string memo, string filename, string fileName2, string fileName3, string fileName4, string fileName5, int cid, ref ApiStatusCode apiCode)
        {
            try
            {
                OrderModel model = new OrderModel();
                model.orderId     = createOrderNo(userId);
                model.UserId      = userId;
                model.Ct_BelongId = userId;
                model.orderTime   = DateTime.Now;
                model.Memo        = memo;
                model.OrderStatus = 0;
                model.OrderImg    = filename;
                model.OrderImg2   = fileName2;
                model.OrderImg3   = fileName3;
                model.OrderImg4   = fileName4;
                model.OrderImg5   = fileName5;
                model.SuccessImg  = model.SuccessImg2 = model.SuccessImg3 = model.SuccessImg4 = model.SuccessImg5 = "";
                model.Ct_Name     = userName;
                model.Ct_Mobile   = mobile;
                model.Ct_Address  = address;
                model.FianlAmount = 0;
                model.CreateTime  = DateTime.Now;

                //判断订单是否使用优惠券
                CashCouponLogModel coupon = null;
                int cashUserId            = 0;
                using (var dal = FactoryDispatcher.CouponFactory())
                {
                    if (!string.IsNullOrEmpty(cashNo))
                    {
                        coupon = dal.getEnableCashCouponLogModel(mobile, cashNo);
                        if (coupon != null && coupon.ID > 0)
                        {
                            if (coupon.ShopId != shopId)
                            {
                                apiCode = ApiStatusCode.非本店现金券;
                                return(false);
                            }
                            if (coupon.IsUse != 0)
                            {
                                apiCode = ApiStatusCode.现金券已使用;
                                return(false);
                            }
                            model.CashCouponAmount = coupon.Money;
                            model.CashCouponBn     = cashNo;
                            model.ShopId           = coupon.ShopId;
                            //设置订单归属用户
                            model.Ct_BelongId = coupon.UserId;
                            model.UserId      = coupon.BelongOneUserId;
                            cashUserId        = coupon.UserId;
                        }
                        else
                        {
                            apiCode = ApiStatusCode.优惠券不存在;
                            return(false);
                        }
                    }
                }
                //如果没有优惠
                if (cashUserId <= 0)
                {
                    //根据手机号或地址,查找客户
                    CustomerModel customer = cid > 0 ? CustomerLogic.getCustomerModel(cid) : CustomerLogic.getCustomerModel(mobile, address);
                    if (customer != null)
                    {
                        //设置订单归属用户
                        model.Ct_BelongId = customer.BelongOne;
                        model.UserId      = customer.BelongTwo;
                        model.ShopId      = customer.ShopId;
                        cashUserId        = customer.BelongOne;
                    }
                }
                TempBeansRecordsModel model1 = null;
                BeansRecordsModel     model2 = null;
                if (cashUserId > 0)
                {
                    using (var dal = FactoryDispatcher.UserFactory())
                    {
                        var user = dal.GetUserModel(cashUserId);
                        if (user.UserIdentity == 0)
                        {
                            model.UserId      = user.BelongOne;
                            model.Ct_BelongId = user.UserId;


                            var shopData = ShopLogic.GetShopModel(model.ShopId);
                            RewardsSettingModel rewardSettingModel = null;
                            //判断当前客户是否所属分店
                            if (shopData != null && shopData.ShopType == 2)
                            {
                                rewardSettingModel = UserLogic.GetRewardModel(model.ShopId);
                            }

                            if (rewardSettingModel != null && rewardSettingModel.OrderReward > 0)
                            {
                                //订单成交需付盟豆
                                model.MengBeans = rewardSettingModel.OrderReward;
                                //插入盟友订单成交临时奖励
                                model1            = new TempBeansRecordsModel();
                                model1.Amount     = rewardSettingModel.OrderReward;
                                model1.UserId     = cashUserId;
                                model1.LogType    = 0;
                                model1.Income     = 1;
                                model1.CreateTime = DateTime.Now;
                                model1.Status     = 0;
                                model1.Remark     = "下单";
                            }
                        }
                        else
                        {
                            model.UserId      = user.UserId;
                            model.Ct_BelongId = user.UserId;
                        }

                        //获取积分奖励配置
                        ScoreConfigModel scoreCfg = ConfigLogic.GetScoreConfig();
                        //添加盟主创建订单,奖励积分
                        if (scoreCfg.CreateOrderScore > 0 && dal.addUserIntegral(userId, scoreCfg.CreateOrderScore) > 0)
                        {
                            model2            = new BeansRecordsModel();
                            model2.Amount     = scoreCfg.CreateOrderScore;
                            model2.UserId     = userId;
                            model2.LogType    = 1;
                            model2.Income     = 1;
                            model2.Remark     = "创建订单奖励";
                            model2.OrderId    = "";
                            model2.CreateTime = DateTime.Now;
                        }
                    }
                }
                else
                {
                    using (var dal = FactoryDispatcher.UserFactory())
                    {
                        var user = dal.GetUserModel(userId);
                        model.UserId      = userId;
                        model.Ct_BelongId = userId;
                        model.ShopId      = user.ShopId;
                    }
                }
                bool flag = false;

                using (TransactionScope scope = new TransactionScope())
                {
                    using (var dal = FactoryDispatcher.OrderFactory())
                    {
                        model.BelongOneShopId = ShopLogic.GetBelongShopId(model.ShopId);
                        if (model.BelongOneShopId == 0)
                        {
                            model.BelongOneShopId = model.ShopId;
                        }
                        flag = dal.Add(model);
                    }
                    if (flag)
                    {
                        //

                        //根据手机号或地址,查找客户,修改客户状态为已生成订单
                        CustomerModel customer = cid > 0 ? CustomerLogic.getCustomerModel(cid) : CustomerLogic.getCustomerModel(mobile, address);
                        if (customer != null)
                        {
                            using (var dal = FactoryDispatcher.CustomerFactory())
                            {
                                dal.UpdateStatus(customer.ID, 4);
                            }
                        }
                        //添加
                        using (var dald = FactoryDispatcher.UserFactory())
                        {
                            if (model1 != null)
                            {
                                dald.AddTempBeansRecords(model1);
                            }

                            //添加日志
                            if (model2 != null)
                            {
                                dald.AddBeansRecords(model2);
                            }
                        }

                        //添加优惠券使用记录
                        using (var cpDal = FactoryDispatcher.CouponFactory())
                        {
                            if (coupon != null)
                            {
                                if (cpDal.UpdateUserCashCouponUseStatus(coupon.ID))
                                {
                                    //添加优惠券领取操作日志
                                    LogLogic.AddCouponLog(new LogBaseModel()
                                    {
                                        objId         = coupon.CouponId,
                                        UserId        = coupon.UserId,
                                        ShopId        = coupon.ShopId,
                                        OperationType = 2,//0创建 1领取 2使用
                                        Money         = coupon.Money
                                    });
                                }
                            }
                        }
                    }
                    scope.Complete();
                    return(flag);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(string.Format("saveOrder==>Message:{0},StackTrace:{1}", ex.Message, ex.StackTrace), LogHelperTag.ERROR);
                apiCode = ApiStatusCode.SERVICEERROR;
                return(false);
            }
        }
Example #8
0
        /// <summary>
        /// 领取优惠券
        /// </summary>
        /// <param name="couponid">The couponid.</param>
        /// <param name="userid">The userid.</param>
        /// <param name="currentuserid">The currentuserid.</param>
        /// <param name="name">The name.</param>
        /// <param name="mobile">The mobile.</param>
        /// <param name="from">From.</param>
        /// <returns>true if XXXX, false otherwise.</returns>
        public bool onCouponGet(int couponid, int userid, int currentuserid, string name, string mobile, string from, string shops, ref ApiStatusCode apiCode)
        {
            lock (couponGetObj)
            {
                string[] ids = shops.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                using (TransactionScope scope = new TransactionScope())
                {
                    if (couponid == 0 || currentuserid == 0)
                    {
                        apiCode = ApiStatusCode.操作失败;
                        return(false);
                    }
                    var couponInfo = dal.GetCouponDetailById(couponid);
                    if (couponInfo == null || couponInfo.Amounts <= 0)
                    {
                        apiCode = ApiStatusCode.优惠券已领完;
                        return(false);
                    }
                    if (ids.Count() > couponInfo.Amounts)
                    {
                        apiCode = ApiStatusCode.优惠券数量不够;
                        return(false);
                    }
                    if (ids.Count() <= 0)
                    {
                        apiCode = ApiStatusCode.请选择门店;
                        return(false);
                    }


                    if (from == "list" && userid > 0)
                    {
                        dal.AddCouponShareLog(couponid, userid);
                    }

                    Random rnd      = new Random(Guid.NewGuid().GetHashCode());
                    var    logModel = new CashCouponLogModel()
                    {
                        UserId      = currentuserid,
                        CouponId    = couponid,
                        CouponNo    = StringHelper.CreateCheckCode(10, 1, rnd),
                        IsGet       = 1,
                        GetTime     = DateTime.Now,
                        ShareUserId = userid,
                        Name        = name,
                        Mobile      = mobile
                    };

                    foreach (var shopid in ids)
                    {
                        logModel.ShopId   = Convert.ToInt32(shopid);
                        logModel.CouponNo = StringHelper.CreateCheckCode(10, 1, rnd);
                        if (dal.AddCouponGetLog(logModel) > 0)
                        {
                            dal.AddCouponGetAmount(couponid, userid);
                        }
                    }
                    dal.UpdateUserInfo(currentuserid, name, mobile);
                    scope.Complete();
                    return(true);
                }
            }
        }
Example #9
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));
            }
        }