Esempio n. 1
0
        public IHttpActionResult GetUserTaskList(string userCode)
        {
            LogHelper.WriteLog("GetUserTaskList userCode" + userCode);
            var sharePictures     = ConfigurationManager.AppSettings["sharePictures"].ToString();
            var shareDescriptions = ConfigurationManager.AppSettings["shareDescriptions"].ToString();
            var shareTitle        = ConfigurationManager.AppSettings["shareTitle"].ToString();

            SimpleResult     result   = new SimpleResult();
            IUserTaskService _service = new UserTaskService();

            try
            {
                if (UserAuthorization)
                {
                    var list = _service.GetUserTaskList(userCode);
                    foreach (var t in list)
                    {
                        if (t.TaskCode == "2")
                        {
                            t.ShareDescriptions = shareDescriptions;
                            t.SharePictures     = sharePictures;
                            t.ShareTitle        = shareTitle;
                        }
                    }
                    result.Resource = list;
                    result.Status   = Result.SUCCEED;
                }
                else
                {
                    result.Status   = ResultType;
                    result.Resource = ReAccessToken;
                    result.Msg      = TokenMessage;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("GetUserTaskList userCode" + userCode, ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;
            }
            LogHelper.WriteLog("GetUserTaskList result" + Json(result));
            return(Json(result));
        }
Esempio n. 2
0
        public IHttpActionResult Getaccess_token(string authorizationCode, string membershipCardStore)
        {
            SimpleResult result = new SimpleResult();

            try
            {
                var store = storeService.GetStore(membershipCardStore);
                if (store != null)
                {
                    LogHelper.WriteLog("微信authorizationCode:" + authorizationCode + "membershipCardStore:" + membershipCardStore);
                    var wxAccessToken = Common.wxCertification(authorizationCode, store);
                    if (wxAccessToken != null && wxAccessToken.access_token != null)
                    {
                        Certification certification = new Certification();
                        //①请求判断是否用户已经存在认证②存在了更新
                        LogHelper.WriteLog("微信openid:" + wxAccessToken.openid + "membershipCardStore:" + membershipCardStore);
                        if (certificationService.CheckCertification(wxAccessToken.openid))
                        {
                            certification.CertificationCode = Guid.NewGuid().ToString();
                            certification.OpenID            = wxAccessToken.openid;
                            certification.AccessToken       = Guid.NewGuid().ToString();
                            certification.CreateTime        = DateTime.Now;
                            certification.ReAccessToken     = Guid.NewGuid().ToString();
                            certificationService.UpdateUserCertification(certification);
                        }
                        else
                        {
                            //③不存在 微信authorizationCode转化自己的authorizationCode
                            certification.CertificationCode = Guid.NewGuid().ToString();
                            certification.OpenID            = wxAccessToken.openid;
                            certification.CreateTime        = DateTime.Now;
                            certification.AccessToken       = Guid.NewGuid().ToString();
                            certification.ReAccessToken     = Guid.NewGuid().ToString();
                            //3.1 创建认证信息
                            certificationService.CreateUserCertification(certification);
                        }
                        IUserTaskService _userTaskService = new UserTaskService();
                        //3.2用OpenID检查用户 没有的话创建用户信息待写
                        //using (var scope = new TransactionScope())//创建事务
                        //{
                        User user      = new User();
                        var  userStore = userStoreService.GetUserStoreby(wxAccessToken.openid);
                        if (userStore != null)
                        {
                            user = userInfo.GetUserByCode(userStore.UserCode);
                            if (_userTaskService.GetUserTaskList(user.Code).Count() != 2)
                            {
                                _userTaskService.InsertUserTask(user.Code, "1");
                                _userTaskService.InsertUserTask(user.Code, "2");
                            }
                        }
                        // 用OpenID获取用户信息然后创建用户信息
                        else
                        {
                            var wxuserinfo = Common.wxuserInfo(wxAccessToken.access_token, wxAccessToken.openid);
                            if (wxuserinfo != null)
                            {
                                user.Code = Guid.NewGuid().ToString();
                                if (wxuserinfo.sex == 2)
                                {
                                    user.Sex = true;
                                }
                                else
                                {
                                    user.Sex = false;
                                }

                                user.UserIamgeUrl = wxuserinfo.headimgurl;
                                user.UserName     = wxuserinfo.nickname;
                                user.CreateTime   = DateTime.Now;
                                userInfo.CreateUser(user);
                                UserStore userStorew = new UserStore();
                                userStorew.OpenID              = wxAccessToken.openid;
                                userStorew.UserStoreCode       = Guid.NewGuid().ToString();
                                userStorew.UserCode            = user.Code;
                                userStorew.MembershipCardStore = membershipCardStore;
                                userStoreService.CreateUserStore(userStorew);

                                _userTaskService.InsertUserTask(user.Code, "1");
                                _userTaskService.InsertUserTask(user.Code, "2");
                            }
                            else
                            {
                                result.Msg = "请使用微信获取用户信息失败";
                            }
                        }

                        result.Status = Result.SUCCEED;
                        FristModel fristModel = new FristModel();
                        fristModel.certification = certification;
                        fristModel.userInfo      = user;
                        result.Resource          = fristModel;
                        result.Msg = "请使用AccessToken请求认证";
                        //    scope.Complete();//这是最后提交事务
                        //}
                    }
                    else
                    {
                        result.Msg = "认证失败";
                        result.Msg = "请求微信认证失败重新获取Code";
                    }
                }
                else
                {
                    result.Msg = "店铺没有配置";
                }
            }
            catch (Exception e)
            {
                result.Msg = e.Message + e.StackTrace;
                LogHelper.WriteLog("Getaccess_token ", e);
            }
            LogHelper.WriteLog("Getaccess_token result" + Json(result));
            return(Json(result));
        }
Esempio n. 3
0
        //http://localhost:10010//api/Message/BangMessageOk?userCode=18235139350
        public IHttpActionResult BangMessageOk(string userCode)
        {
            LogHelper.WriteLog("BangMessageOk :" + userCode);

            ICouponService     _service           = new CouponService();
            IUserInfo          _userservice       = new UserInfo();
            ICouponTypeService _couponTypeservice = new CouponTypeService();
            IUserTaskService   _userTaskservice   = new UserTaskService();
            IStoreService      storeService       = new StoreService();
            IUserStoreService  userStoreService   = new UserStoreService();
            SimpleResult       result             = new SimpleResult();

            try
            {
                if (UserAuthorization)
                {
                    var user = userInfo.GetUserByCode(userCode);
                    if (user != null)
                    {
                        var userStore = userStoreService.GetUserStorebyUserCode(userCode);
                        if (userStore != null)
                        {
                            var store = storeService.GetStore(userStore.MembershipCardStore);
                            if (store != null)
                            {
                                var cardId = ConfigurationManager.AppSettings["cardId"].ToString();
                                var card   = getcardlist(store.accessToken, userStore.OpenID, cardId);
                                if (card != null && card.FirstOrDefault()?.code != null)
                                {
                                    var code       = card.FirstOrDefault()?.code;
                                    var cardstatus = getcardstatus(store.accessToken, code, cardId);
                                    if (cardstatus.user_card_status.Equals("NORMAL"))
                                    {
                                        //写入到手机号和和数据库
                                        var count = userInfo.UpdateIsMemberByuserCode(userCode, code);
                                        if (count > 0)
                                        {
                                            if (!string.IsNullOrEmpty(user.RecommendedPhone))
                                            {
                                                IUserStoreService _userStoreservice = new UserStoreService();

                                                if (store != null)
                                                {
                                                    var recouser = _userservice.GetUserByphone(user.RecommendedPhone, store.StoreCode);
                                                    //判断是不是已经领够了2次
                                                    if (recouser != null && recouser.IsMember)
                                                    {
                                                        if (_service.checkCoupon(recouser.Code, "2"))
                                                        {
                                                            var couponType = _couponTypeservice.GetCouponTypeByIsGivedType("2");
                                                            if (couponType != null)
                                                            {
                                                                Coupon coupon = new Coupon();
                                                                coupon.CouponCode     = Guid.NewGuid().ToString();
                                                                coupon.UserCode       = recouser.Code;
                                                                coupon.CouponTypeCode = couponType.CouponTypeCode;
                                                                coupon.StratTime      = DateTime.Now;
                                                                coupon.VersionEndTime = DateTime.MaxValue;
                                                                coupon.IsGiveed       = true;
                                                                coupon.CouponUseCode  = Str(10, true);
                                                                //没有添加任务优惠券
                                                                var re = _service.Insert(coupon);
                                                                //更改任务状态
                                                                var userTask = _userTaskservice.GetUserTaskList(recouser.Code);
                                                                var ut       = userTask.Where(u => u.TaskCode == "2").FirstOrDefault();
                                                                ut.IsComplete = true;
                                                                _userTaskservice.UpdateUserTask(ut.UserTaskCode, 1);
                                                                result.Resource = re;
                                                                result.Status   = Result.SUCCEED;
                                                            }
                                                            else
                                                            {
                                                                result.Resource = "好友赠送任务已经结束";
                                                                result.Status   = Result.SYSTEM_ERROR;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            result.Resource = "好友已经达到任务奖励上限";

                                                            result.Status = Result.SYSTEM_ERROR;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        result.Resource = "您还没有注册会员";
                                                        result.Status   = Result.SYSTEM_ERROR;
                                                    }
                                                }
                                                else
                                                {
                                                    result.Resource = "店铺不存在";
                                                    result.Status   = Result.SYSTEM_ERROR;
                                                }
                                            }
                                            if (!user.IsMember)
                                            {
                                                //
                                                //添加赠送本人
                                                if (_service.checkCoupon(userCode, "1"))
                                                {
                                                    var couponType = _couponTypeservice.GetCouponTypeByIsGivedType("1");
                                                    if (couponType != null)
                                                    {
                                                        Coupon coupon = new Coupon();
                                                        coupon.CouponCode     = Guid.NewGuid().ToString();
                                                        coupon.UserCode       = userCode;
                                                        coupon.CouponTypeCode = couponType.CouponTypeCode;
                                                        coupon.StratTime      = DateTime.Now;
                                                        coupon.VersionEndTime = DateTime.MaxValue;
                                                        coupon.IsGiveed       = true;
                                                        coupon.CouponUseCode  = Str(10, true);
                                                        //没有添加任务优惠券
                                                        var re = _service.Insert(coupon);
                                                        //更改任务状态
                                                        //更改任务状态
                                                        var userTask = _userTaskservice.GetUserTaskList(userCode);
                                                        var ut       = userTask.Where(u => u.TaskCode == "1").FirstOrDefault();
                                                        ut.IsComplete = true;
                                                        _userTaskservice.UpdateUserTask(ut.UserTaskCode, 1);
                                                        result.Resource = re;
                                                        result.Status   = Result.SUCCEED;
                                                    }
                                                }
                                            }

                                            result.Resource = count;
                                            result.Status   = Result.SUCCEED;
                                        }
                                        else
                                        {
                                            result.Status   = Result.SYSTEM_ERROR;
                                            result.Resource = "添加没有成功,请重试。";
                                        }
                                    }
                                    else
                                    {
                                        result.Status   = Result.SYSTEM_ERROR;
                                        result.Resource = "添加没有成功,请重试。";
                                    }
                                }
                                else
                                {
                                    result.Status   = Result.SYSTEM_ERROR;
                                    result.Resource = "添加没有成功,请重试。";
                                }
                            }
                        }
                        else
                        {
                            result.Status   = Result.SYSTEM_ERROR;
                            result.Resource = "添加没有成功,请重试。";
                        }
                    }
                    else
                    {
                        result.Status   = Result.SYSTEM_ERROR;
                        result.Resource = "当前用户不存在";
                    }
                }
                else
                {
                    result.Status   = ResultType;
                    result.Resource = ReAccessToken;
                    result.Msg      = TokenMessage;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("BangMessageOk:" + ex.Message, ex);
                LogHelper.WriteLog("BangMessageOk:" + ex.StackTrace, ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;
            }
            LogHelper.WriteLog("BangMessageOk result" + Json(result));
            return(Json(result));
        }
Esempio n. 4
0
        //http://localhost:10010//api/Message/BangMessageCode?phone=18235139350&verificationCode=232232&userCode=121ewe&birthday='yyyy-mm-dd'
        public IHttpActionResult BangMessageCode(string phone, string verificationCode, string userCode, string storeCode, string birthday, string recommendedPhone = null)
        {
            LogHelper.WriteLog("BangMessageCode phone" + phone);
            LogHelper.WriteLog("BangMessageCode verificationCode" + verificationCode);
            LogHelper.WriteLog("BangMessageCode userCode" + userCode);
            LogHelper.WriteLog("BangMessageCode storeCode" + storeCode);
            LogHelper.WriteLog("BangMessageCode birthday" + birthday);
            LogHelper.WriteLog("BangMessageCode recommendedPhone" + recommendedPhone);
            IStoreService      storeService       = new StoreService();
            ICouponService     _service           = new CouponService();
            IUserInfo          _userservice       = new UserInfo();
            ICouponTypeService _couponTypeservice = new CouponTypeService();
            IUserTaskService   _userTaskservice   = new UserTaskService();
            IUserStoreService  userStoreService   = new UserStoreService();
            SimpleResult       result             = new SimpleResult();

            try
            {
                if (UserAuthorization)
                {
                    if (verificationService.CheckVerification(phone, verificationCode))
                    {
                        DateTime birthdaydate = new DateTime();
                        if (DateTime.TryParse(birthday, out birthdaydate))
                        {
                            var store = storeService.GetStore(storeCode);
                            if (store != null)
                            {
                                var use = userInfo.GetUserByCode(userCode);
                                if (use != null)
                                {
                                    var userStore = userStoreService.GetUserStorebyUserCode(userCode);
                                    if (userStore != null)
                                    {
                                        var recouser = _userservice.GetUserByphone(recommendedPhone, store.StoreCode);
                                        //判断是不是已经领够了2次
                                        if (recouser != null && recouser.IsMember)
                                        {
                                            if (_service.checkCoupon(recouser.Code, "2"))
                                            {
                                                var couponType = _couponTypeservice.GetCouponTypeByIsGivedType("2");
                                                if (couponType != null)
                                                {
                                                    Coupon coupon = new Coupon();
                                                    coupon.CouponCode     = Guid.NewGuid().ToString();
                                                    coupon.UserCode       = recouser.Code;
                                                    coupon.CouponTypeCode = couponType.CouponTypeCode;
                                                    coupon.StratTime      = DateTime.Now;
                                                    coupon.VersionEndTime = DateTime.MaxValue;
                                                    coupon.IsGiveed       = true;
                                                    coupon.CouponUseCode  = Str(10, true);
                                                    //没有添加任务优惠券
                                                    var re = _service.Insert(coupon);
                                                    //更改任务状态
                                                    var userTask = _userTaskservice.GetUserTaskList(recouser.Code);
                                                    var ut       = userTask.Where(u => u.TaskCode == "2").FirstOrDefault();
                                                    ut.IsComplete = true;
                                                    _userTaskservice.UpdateUserTask(ut.UserTaskCode, 1);
                                                    result.Resource = re;
                                                    result.Status   = Result.SUCCEED;
                                                }
                                                else
                                                {
                                                    result.Resource = "好友赠送任务已经结束";
                                                    result.Status   = Result.SYSTEM_ERROR;
                                                }
                                            }
                                        }
                                        //添加赠送本人
                                        if (_service.checkCoupon(userCode, "1"))
                                        {
                                            var couponType = _couponTypeservice.GetCouponTypeByIsGivedType("1");
                                            if (couponType != null)
                                            {
                                                Coupon coupon = new Coupon();
                                                coupon.CouponCode     = Guid.NewGuid().ToString();
                                                coupon.UserCode       = userCode;
                                                coupon.CouponTypeCode = couponType.CouponTypeCode;
                                                coupon.StratTime      = DateTime.Now;
                                                coupon.VersionEndTime = DateTime.MaxValue;
                                                coupon.IsGiveed       = true;
                                                coupon.CouponUseCode  = Str(10, true);
                                                //没有添加任务优惠券
                                                var re = _service.Insert(coupon);
                                                //更改任务状态
                                                //更改任务状态
                                                var userTask = _userTaskservice.GetUserTaskList(userCode);
                                                var ut       = userTask.Where(u => u.TaskCode == "1").FirstOrDefault();
                                                ut.IsComplete = true;
                                                _userTaskservice.UpdateUserTask(ut.UserTaskCode, 1);
                                                result.Resource = re;
                                                result.Status   = Result.SUCCEED;
                                            }
                                        }
                                        var cardId = ConfigurationManager.AppSettings["cardId"].ToString();
                                        var card   = getcardlist(store.accessToken, userStore.OpenID, cardId);
                                        if (card != null && card.FirstOrDefault()?.code != null)
                                        {
                                            var code       = card.FirstOrDefault()?.code;
                                            var cardstatus = getcardstatus(store.accessToken, code, cardId);
                                            if (cardstatus.user_card_status.Equals("NORMAL"))
                                            {
                                                var count = userInfo.UpdateByuserCodePhone(userCode, phone, birthdaydate, code);

                                                if (count > 0)
                                                {
                                                    result.Status = Result.SUCCEED;
                                                }
                                                else
                                                {
                                                    result.Status = Result.SYSTEM_ERROR;
                                                    result.Msg    = "当前用户绑定手机号失败";
                                                }
                                            }
                                            else
                                            {
                                                var wxc = Common.GetCardExt(store, userCode);
                                                if (wxc != null)
                                                {
                                                    //写入到手机号和和数据库
                                                    var count = userInfo.UpdateByPhone(userCode, phone, birthdaydate, wxc.cardExt.code, recommendedPhone);
                                                    if (count > 0)
                                                    {
                                                        result.Status = Result.SUCCEED;
                                                        LogHelper.WriteLog("BangMessageCode :" + result.Status);
                                                        LogHelper.WriteLog("wxc :" + wxc);
                                                        LogHelper.WriteLog("code :" + wxc.cardExt.code);
                                                        result.Resource = wxc;
                                                    }
                                                    else
                                                    {
                                                        result.Status = Result.SYSTEM_ERROR;
                                                        result.Msg    = "获取配置失败重新获取";
                                                    }
                                                }
                                                else
                                                {
                                                    result.Status = Result.USER_AUTH_ERROR;
                                                    result.Msg    = "获取配置失败重新获取";
                                                }
                                            }
                                        }
                                        else
                                        {
                                            var wxc = Common.GetCardExt(store, userCode);
                                            if (wxc != null)
                                            {
                                                //写入到手机号和和数据库
                                                var count = userInfo.UpdateByPhone(userCode, phone, birthdaydate, wxc.cardExt.code, recommendedPhone);
                                                if (count > 0)
                                                {
                                                    result.Status = Result.SUCCEED;
                                                    LogHelper.WriteLog("BangMessageCode :" + result.Status);
                                                    LogHelper.WriteLog("wxc :" + wxc);
                                                    LogHelper.WriteLog("code :" + wxc.cardExt.code);
                                                    result.Resource = wxc;
                                                }
                                                else
                                                {
                                                    result.Status = Result.SYSTEM_ERROR;
                                                    result.Msg    = "获取配置失败重新获取";
                                                }
                                            }
                                            else
                                            {
                                                result.Status = Result.USER_AUTH_ERROR;
                                                result.Msg    = "获取配置失败重新获取";
                                            }
                                        }
                                    }
                                    else
                                    {
                                        result.Status = Result.SYSTEM_ERROR;
                                        result.Msg    = "当前用户不存在";
                                    }
                                }
                                else
                                {
                                    result.Status = Result.SYSTEM_ERROR;
                                    result.Msg    = "当前用户不存在";
                                }
                            }
                            else
                            {
                                result.Status = Result.SYSTEM_ERROR;
                                result.Msg    = "店铺不存在";
                            }
                        }
                        else
                        {
                            result.Status = Result.SYSTEM_ERROR;
                            result.Msg    = "选择生日有误";
                        }
                    }
                    else
                    {
                        result.Status = Result.SYSTEM_ERROR;
                        result.Msg    = "验证码错误或者已经过期,请重新获取验证码。";
                    }
                }
                else
                {
                    result.Status   = ResultType;
                    result.Resource = ReAccessToken;
                    result.Msg      = TokenMessage;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("BangMessageCode:", ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;
            }
            LogHelper.WriteLog("BangMessageCode result" + Json(result));

            return(Json(result));
        }
Esempio n. 5
0
        public IHttpActionResult GetUserInfoByCode(string usercode, string store)
        {
            LogHelper.WriteLog("GetUserInfoByCode usercode" + usercode);
            LogHelper.WriteLog("GetUserInfoByCode store" + store);
            SimpleResult      result            = new SimpleResult();
            IUserInfo         _service          = new UserInfo();
            ICustomerServiceS _customerServiceS = new CustomerServiceS();
            IOrderService     _OrderService     = new OrderService();
            ICouponService    _CouponService    = new CouponService();
            UserInfoModel     userInfo          = new UserInfoModel();
            IUseWalletService _useWalletService = new UseWalletService();
            IUserTaskService  _userTaskService  = new UserTaskService();

            try
            {
                if (UserAuthorization)
                {
                    var user = _service.GetUserByCode(usercode);
                    userInfo.user = user;
                    var customerService = _customerServiceS.GetCustomerService(store);
                    userInfo.customerService = customerService;
                    var orders = _OrderService.GetOrderList(usercode);
                    userInfo.useWalletInfo = _useWalletService.GetUseWalletInfoByUserCode(usercode);
                    var conponList = _CouponService.GetUserCoupon(usercode);
                    userInfo.useCouponCount = conponList.Any()?conponList.Count:0;
                    if (orders != null)
                    {
                        userInfo.orders = orders.Where(p => p.PayTime != null && p.IsWriteOff == false).Count();
                    }
                    var coupons = _CouponService.GetCouponList(usercode);
                    if (coupons != null)
                    {
                        userInfo.coupons = coupons.Where(c => c.IsUsed == false).Count();
                    }
                    var userTask = _userTaskService.GetUserTaskList(user.Code);
                    if (userTask != null)
                    {
                        userInfo.userTask = userTask.Where(t => t.IsComplete == false).Count();
                    }
                    userInfo.openCard = new OpenCard();
                    var cardId = ConfigurationManager.AppSettings["cardId"].ToString();
                    userInfo.openCard.cardId = cardId;
                    userInfo.openCard.code   = userInfo.user?.ReferenceNumber;
                    result.Resource          = userInfo;
                    result.Status            = Result.SUCCEED;
                }
                else
                {
                    result.Status   = ResultType;
                    result.Resource = ReAccessToken;
                    result.Msg      = TokenMessage;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("GetUserInfoByCode usercode" + usercode + "store" + store, ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;
            }
            LogHelper.WriteLog("GetUserInfoByCode result" + Json(result));
            return(Json(result));
        }