Esempio n. 1
0
        public ActionResult AddressSelect(string code, string fromURL)
        {
            #region 用户信息部分
            string userOpenId             = string.Empty;
            Tuple <string, string> result = base.getUserOpenId(code);
            if (!string.IsNullOrEmpty(result.Item1))
            {
                userOpenId = result.Item1;
            }
            else if (!string.IsNullOrEmpty(result.Item2))
            {
                return(Redirect(result.Item2));
            }
            ViewBag.userOpenId = userOpenId;
            #endregion

            ViewBag.fromURL = fromURL;
            List <useraddress> userAddressList = new List <useraddress>();
            if (!string.IsNullOrEmpty(userOpenId))
            {
                userAddressList = UserBiz.CreateNew().getUserAddressList(userOpenId);
            }

            return(View(userAddressList));
        }
Esempio n. 2
0
        public JsonResult CheckSMS(string Phone, string SMS, string OpenId)
        {
            string userOpenId = base.getUserOpenIdFromCookie();

            if (string.IsNullOrEmpty(userOpenId))
            {
                userOpenId = OpenId;
            }
            string res = "fail";

            if (!string.IsNullOrEmpty(userOpenId))
            {
                try
                {
                    string strCache = CacheHelper.GetCache("smsInfo" + userOpenId + Phone).ToString();
                    if (string.IsNullOrEmpty(strCache))
                    {
                        res = "验证码已失效";
                    }
                    else
                    {
                        if (SMS != strCache)
                        {
                            res = "验证码不正确";
                        }
                        else
                        {
                            //注册成功
                            //更新数据库
                            //删除缓存
                            users user = new users();
                            user.phone  = Phone;
                            user.openid = OpenId;
                            UserBiz uBiz    = UserBiz.CreateNew();
                            var     resUser = uBiz.getUserInfoByOpenId(user.openid);
                            if (resUser != null)
                            {
                                uBiz.updateUserPhone(user);
                            }
                            else
                            {
                                uBiz.insertUserPhone(user);
                            }
                            CacheHelper.RemoveCacheByKey("userInfo" + userOpenId);
                            res = "success";
                        }
                    }
                }
                catch (Exception e)
                {
                    res = "fail";
                    _Apilog.WriteLog("UserController/SendSMS 异常: " + e.Message);
                }
            }
            else
            {
                _Apilog.WriteLog("UserController/SendSMS 用户userOpenId 为空: ");
            }
            return(Json(res));
        }
Esempio n. 3
0
        /// <summary>
        /// 用户管理收货地址
        /// </summary>
        /// <returns></returns>
        public ActionResult Addressedit(string code, string fromURL, string addressId)
        {
            #region 用户信息部分
            string userOpenId             = string.Empty;
            Tuple <string, string> result = base.getUserOpenId(code);
            if (!string.IsNullOrEmpty(result.Item1))
            {
                userOpenId = result.Item1;
            }
            else if (!string.IsNullOrEmpty(result.Item2))
            {
                return(Redirect(result.Item2));
            }
            ViewBag.userOpenId = userOpenId;
            #endregion

            #region 收货地址部分
            if (string.IsNullOrEmpty(addressId))
            {
                return(RedirectToAction("Addresslist", "User", new { fromURL = fromURL }));
            }
            else
            {
                useraddress_extension userAddress = UserBiz.CreateNew().getUserAddressById(userOpenId, addressId);
                ViewBag.fromBaseURL = fromURL;
                ViewBag.FooterType  = "custom";
                ViewBag.PageName    = "管理收货地址";
                return(View(userAddress));
            }
            #endregion
        }
Esempio n. 4
0
        public JsonResult AddressUpdate(string id, string receiver, string rPhone, string district, string detailAddress, string setAsDefault)
        {
            string userOpenId = base.getUserOpenIdFromCookie();
            string res        = "fail";

            if (!string.IsNullOrEmpty(userOpenId))
            {
                try
                {
                    useraddress user = new useraddress();
                    user.Id            = Convert.ToInt32(id);
                    user.userOpenId    = userOpenId;
                    user.receiver      = receiver;
                    user.Phone         = rPhone;
                    user.detailAddress = detailAddress;
                    user.SetAsDefault  = setAsDefault.ToLower() == "true" ? "1" : "0";
                    user.status        = 1;
                    user.updateDate    = DateTime.Now;

                    string[] tempDistrict = district.Split(',');//10,183,1116
                    user.province = tempDistrict[0];
                    user.city     = "";
                    user.county   = "";
                    if (tempDistrict.Length >= 2)
                    {
                        user.city = tempDistrict[1];
                    }
                    if (tempDistrict.Length >= 3)
                    {
                        user.county = tempDistrict[2];
                    }

                    UserBiz.CreateNew().updateUserAddress(user);
                    res = "success";
                }
                catch (Exception e)
                {
                    res = "fail";
                    _Apilog.WriteLog("UserController/AddressAdd 异常: " + e.Message);
                }
            }
            else
            {
                _Apilog.WriteLog("UserController/AddressAdd 用户userOpenId 为空: ");
            }
            return(Json(res));
        }
Esempio n. 5
0
        /// <summary>
        /// 将地址设为默认地址
        /// </summary>
        /// <param name="addressId">地址id</param>
        /// <param name="fromURL"></param>
        /// <returns></returns>
        public ActionResult SetDefaultAddress(string addressId, string fromURL)
        {
            string userOpenId = base.getUserOpenIdFromCookie();

            try
            {
                if (!string.IsNullOrEmpty(userOpenId))
                {
                    UserBiz.CreateNew().setDefaultAddress(userOpenId, addressId);
                }
                else
                {
                    _Apilog.WriteLog("UserController SetDefaultAddress 异常,userOpenId为空,addressId:" + addressId);
                }
            }
            catch (Exception e)
            {
                _Apilog.WriteLog("UserController 下的SetDefaultAddress 异常,addressId:" + addressId + "异常: " + e.Message);
            }
            return(RedirectToAction("Addresslist", "User", new { fromURL = fromURL }));
        }
Esempio n. 6
0
        public async Task <ActionResult> login(AdminLoginViewModels model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            if (UserBiz.CreateNew().isAdminUser(model.Account, model.Password))
            {
                HttpContext.Session["LoginedUser"]     = "******";
                HttpContext.Session["LoginedUserName"] = model.Account;
                return(RedirectToLocal(returnUrl));
            }
            else
            {
                ModelState.AddModelError("", "账号或密码错误");
            }

            return(View(model));
        }
Esempio n. 7
0
        public ActionResult userList()
        {
            List <users> lusers = UserBiz.CreateNew().getUserList();

            return(View(lusers));
        }
Esempio n. 8
0
        /// <summary>
        /// 用户提供授权
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public Tuple <string, users> getUserInfoByAuthorize(string code)
        {
            try
            {
                users user = new users();
                if (isWechatTest == "false")
                {
                    Userinfo  wechatInfo    = new Userinfo();
                    Authorize authorizeInfo = new Authorize();
                    string    userOpenId    = CookieHelper.GetCookieValue("userOpenId");
                    //缓存不为空,说明可能先点过购物车或者产品
                    if (!string.IsNullOrEmpty(userOpenId))
                    {
                        //_Apilog.WriteLog("1.userOpenId 不为空:" + userOpenId);
                        var resCache = CacheHelper.GetCache(userOpenId);
                        if (resCache != null)
                        {
                            user = (users)resCache;
                            //_Apilog.WriteLog("2.userOpenId 不为空,缓存不为空:" + userOpenId);
                            return(new Tuple <string, users>(string.Empty, user));
                        }


                        UserBiz userBiz = UserBiz.CreateNew();
                        //判断openid是否已存在或者需要更新
                        user = userBiz.getUserInfoByOpenId(userOpenId);
                        if (user != null)
                        {
                            //_Apilog.WriteLog("3.userOpenId 不为空,表不为空:" + userOpenId);
                            DateTime dtCreate = user.updateDate ?? user.createDate;
                            DateTime dtNow    = DateTime.Now;
                            if (dtCreate.AddDays(7) < dtNow || string.IsNullOrEmpty(user.nickname))
                            {
                                //第一步
                                if (string.IsNullOrEmpty(code))
                                {
                                    //_Apilog.WriteLog("4.userOpenId 不为空,表不为空,第一步:" + userOpenId);
                                    return(new Tuple <string, users>(getSnsapi_userinfo_Link(), user));
                                }
                                else
                                {
                                    //_Apilog.WriteLog("5.userOpenId 不为空,表不为空,第二步:" + userOpenId);
                                    //授权第二步,获取openid
                                    authorizeInfo = getAuthorizeInfo(code);
                                    //授权3
                                    wechatInfo = getWechatUserInfo(authorizeInfo);
                                    //update
                                    user            = setUserinfoFromWechat(wechatInfo);
                                    user.updateDate = DateTime.Now;
                                    userBiz.updateUserWeChatInfo(user);
                                }
                            }
                        }
                        else//需要插入
                        {
                            //第一步
                            if (string.IsNullOrEmpty(code))
                            {
                                //_Apilog.WriteLog("6.userOpenId 不为空,表为空,第一步:" + userOpenId);
                                return(new Tuple <string, users>(getSnsapi_userinfo_Link(), user));
                            }
                            else
                            {
                                //_Apilog.WriteLog("7.userOpenId 不为空,表为空,第二步:" + userOpenId);
                                //_Apilog.WriteLog("7.1.userOpenId 不为空,表为空,第二步:code" + code);
                                //授权第二步,获取openid
                                authorizeInfo = getAuthorizeInfo(code);
                                //_Apilog.WriteLog("7.2.userOpenId 不为空,表为空,第二步:access_token" + authorizeInfo.access_token + " openid: " + authorizeInfo.openid);

                                //授权3
                                wechatInfo = getWechatUserInfo(authorizeInfo);
                                //_Apilog.WriteLog("7.3.userOpenId 不为空,表为空,第二步:wechatInfo" + wechatInfo.nickname);
                                //insert
                                user = setUserinfoFromWechat(wechatInfo);
                                //_Apilog.WriteLog("7.4.userOpenId 不为空,表为空,第二步:user" + user.nickname);
                                user.createDate = DateTime.Now;
                                user.updateDate = user.createDate;
                                userBiz.insertUserWeChatInfo(user);
                                //_Apilog.WriteLog("7.5.userOpenId 不为空,表为空,第二步:code" + code);
                            }
                        }
                    }
                    //缓存为空
                    else
                    {
                        //授权第一步,返回地址
                        if (string.IsNullOrEmpty(code))
                        {
                            //_Apilog.WriteLog("8.userOpenId 为空,第一步:");
                            return(new Tuple <string, users>(getSnsapi_userinfo_Link(), user));
                        }
                        else
                        {
                            //授权第二步,获取openid
                            //_Apilog.WriteLog("9.userOpenId 为空,第二步:" + code);
                            authorizeInfo = getAuthorizeInfo(code);
                            //_Apilog.WriteLog("10.userOpenId 为空,第二.2步:");
                            var resCache = CacheHelper.GetCache(authorizeInfo.openid);
                            if (resCache != null)
                            {
                                //_Apilog.WriteLog("11.userOpenId 为空,缓存不为空,第二步:" + code);
                                user = (users)resCache;
                                return(new Tuple <string, users>(string.Empty, user));
                            }
                            UserBiz userBiz = UserBiz.CreateNew();
                            //判断openid是否已存在或者需要更新
                            user = userBiz.getUserInfoByOpenId(authorizeInfo.openid);
                            //_Apilog.WriteLog("12.userOpenId 为空,第二.3步:");
                            if (user != null)
                            {
                                DateTime dtCreate = user.updateDate ?? user.createDate;
                                DateTime dtNow    = DateTime.Now;
                                if (dtCreate.AddDays(7) < dtNow || string.IsNullOrEmpty(user.nickname))
                                {
                                    //授权3
                                    //_Apilog.WriteLog("13.userOpenId 为空,缓存为空,表不为空,第三步:");
                                    wechatInfo = getWechatUserInfo(authorizeInfo);
                                    //update
                                    user            = setUserinfoFromWechat(wechatInfo);
                                    user.updateDate = DateTime.Now;
                                    userBiz.updateUserWeChatInfo(user);
                                }
                            }
                            else
                            {
                                //_Apilog.WriteLog("14.userOpenId 为空,缓存为空,表为空,第三步:");
                                wechatInfo = getWechatUserInfo(authorizeInfo);
                                //insert
                                user            = setUserinfoFromWechat(wechatInfo);
                                user.createDate = DateTime.Now;
                                user.updateDate = user.createDate;
                                userBiz.insertUserWeChatInfo(user);
                            }
                        }
                    }
                    if (user != null)
                    {
                        var      start       = DateTime.Now;
                        var      expiredDate = start.AddDays(1);
                        TimeSpan ts          = expiredDate - start;
                        CacheHelper.SetCache("userInfo" + user.openid.ToString(), user, ts);
                        if (!string.IsNullOrEmpty(user.openid))
                        {
                            CookieHelper.SetCookie("userOpenId", user.openid);
                        }
                    }
                }
                else
                {
                    user.nickname   = "test";
                    ViewBag.headImg = "../images/noavatar.png";//缺省图片
                }
                return(new Tuple <string, users>(string.Empty, user));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 结算页面
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public ActionResult Checkout(string orderId, string code)
        {
            #region 用户信息部分
            string userOpenId             = string.Empty;
            Tuple <string, string> result = base.getUserOpenId(code);
            if (!string.IsNullOrEmpty(result.Item1))
            {
                userOpenId = result.Item1;
            }
            else if (!string.IsNullOrEmpty(result.Item2))
            {
                return(Redirect(result.Item2));
            }
            ViewBag.userOpenId = userOpenId;
            #endregion

            if (string.IsNullOrEmpty(orderId) || string.IsNullOrEmpty(userOpenId))
            {
                return(RedirectToAction("OrderList", "Order"));
            }

            #region 绑定手机部分
            //用户未点击跳过注册 并且电话为空
            users res      = new users();
            var   resCache = CacheHelper.GetCache("userInfo" + userOpenId);
            if (resCache != null)
            {
                res = (users)resCache;
            }
            else
            {
                res = UserBiz.CreateNew().getUserInfoByOpenId(userOpenId);
                if (res == null)
                {
                    return(RedirectToAction("Register", "User", new { needRegister = "1", fromUrl = Request.RawUrl }));//跳转到注册页面,且必须注册
                }
                else
                {
                    var      start       = DateTime.Now;
                    var      expiredDate = start.AddDays(1);
                    TimeSpan ts          = expiredDate - start;
                    CacheHelper.SetCache("userInfo" + res.openid.ToString(), res, ts);
                    if (!string.IsNullOrEmpty(res.openid))
                    {
                        CookieHelper.SetCookie("userOpenId", res.openid);
                    }
                }
            }

            if (string.IsNullOrEmpty(res.phone))
            {
                return(RedirectToAction("Register", "User", new { needRegister = "1", fromUrl = Request.RawUrl }));//跳转到注册页面,且必须注册
            }
            #endregion

            CheckOutModels           checkOutModels      = new CheckOutModels();
            useraddress              userRes             = new useraddress();
            List <UserShopcartsInfo> userUnpaidOrderInfo = new List <UserShopcartsInfo>();
            salesslip userSalesSlip = new salesslip();

            decimal productsPrice = 0;
            decimal postage       = 0;
            decimal SFJZF         = Convert.ToDecimal(System.Configuration.ConfigurationSettings.AppSettings["sf:JZH"]);    //顺丰江浙沪快递费
            decimal SFNonJZF      = Convert.ToDecimal(System.Configuration.ConfigurationSettings.AppSettings["sf:NonJZH"]); //顺丰非江浙沪快递费

            string wechatBody = string.Empty;
            userSalesSlip = OrderBiz.CreateNew().getCheckOutInfo(orderId, userOpenId);
            if (userSalesSlip == null)                          //查不到销售单
            {
                return(RedirectToAction("OrderList", "Order")); //查不到销售单,跳转至订单列表页面
            }
            else if (userSalesSlip.status == 5)
            {
                userSalesSlip.status = OrderBiz.CreateNew().dealExpectionOrder(userSalesSlip.salesNo, userSalesSlip.wechatOrderNo);
            }
            if (userSalesSlip.status == 0)                                                 //0未付款 1已付款待发货 2 已发货,待收货 3 已完成 4 已删除 5 预付款 6 已过期
            {
                if (DateTime.Now.AddMinutes(-orderExpiredMins) > userSalesSlip.createDate) //订单已失效,为了减少数据库操作,这边做跳转;
                {
                    return(RedirectToAction("OrderList", "Order", new { status = "all" }));
                }

                #region 用户收货地址部分
                if (!string.IsNullOrEmpty(userSalesSlip.province) && !string.IsNullOrEmpty(userSalesSlip.receiver)) //先看该订单用户是否已经设置收货地址,没有设置过则读取默认地址,还没有则为空
                {
                    userRes.receiver      = userSalesSlip.receiver;
                    userRes.Phone         = userSalesSlip.Phone;
                    userRes.province      = userSalesSlip.province;
                    userRes.city          = userSalesSlip.city;
                    userRes.county        = userSalesSlip.county;
                    userRes.detailAddress = userSalesSlip.detailAddress;
                }
                else
                {
                    var userAddressList = UserBiz.CreateNew().getUserAddressList(userOpenId);
                    if (userAddressList.Any())
                    {
                        userRes = userAddressList.Find(x => x.SetAsDefault == "1");
                    }
                    if (userRes == null)
                    {
                        userRes          = new useraddress();
                        userRes.receiver = userRes.Phone = userRes.province = userRes.city = userRes.county = userRes.detailAddress = "";
                    }
                }
                if (!string.IsNullOrEmpty(userRes.province))
                {
                    if (userRes.province.IndexOf("上海") >= 0 ||
                        userRes.province.IndexOf("江苏") >= 0 ||
                        userRes.province.IndexOf("浙江") >= 0 ||
                        userRes.province.IndexOf("安徽") >= 0)
                    {
                        postage = SFJZF;
                    }
                    else
                    {
                        postage = SFNonJZF;
                    }
                }

                #endregion

                #region 订单产品部分
                OrderBiz orderBiz = OrderBiz.CreateNew();
                userUnpaidOrderInfo          = orderBiz.getUnpaidOrderInfo(userSalesSlip.salesId);
                checkOutModels.UserOrderInfo = userUnpaidOrderInfo;

                foreach (var i in userUnpaidOrderInfo)
                {
                    try
                    {
                        orderBiz.updateOrder2ProductLogField(i.productId, i.id);
                    }
                    catch (Exception ex)
                    {
                        _Apilog.WriteLog("ProductsController/Checkout更新订单logid异常" + ex.Message);
                    }
                    wechatBody    += i.productName + "*" + i.num.ToString() + ";";
                    productsPrice += i.productTotalPrice ?? 0;
                }
                #endregion
            }
            else//订单状态不为 未付款,需要跳转到对应页面
            {
                return(RedirectToAction("OrderList", "Order", new { status = userSalesSlip.status }));
            }

            decimal factPrice   = 0;
            decimal factPostage = 0;
            if (Convert.IsDBNull(userSalesSlip.adminChangeAmount) || userSalesSlip.adminChangeAmount == null)
            {
                factPrice = productsPrice;
            }
            else
            {
                factPrice = userSalesSlip.adminChangeAmount ?? 1;
            }

            if (Convert.IsDBNull(userSalesSlip.adminChangePostage) || userSalesSlip.adminChangePostage == null)
            {
                factPostage = postage;
            }
            else
            {
                factPostage = userSalesSlip.adminChangePostage ?? 1;
            }

            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            JsApiPay jsApiPay = new JsApiPay();
            jsApiPay.openid    = userOpenId;
            jsApiPay.total_fee = base.isPayTest == "false" ? decimal.ToInt32(factPrice * 100 + factPostage * 100) : 1;//测试环境默认支付1分

            //JSAPI支付预处理
            try
            {
                string wechatOrderId = Guid.NewGuid().ToString("N").ToLower();
                OrderBiz.CreateNew().updateWechatOrderId(orderId, userOpenId, wechatOrderId);

                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(wechatBody, wechatOrderId); //orderId
                ViewBag.wxJsApiParam = jsApiPay.GetJsApiParameters();                                     //获取H5调起JS API参数
                _Apilog.WriteLog("ProductsController/Checkout 用户userOpenId: " + userOpenId + " wxJsApiParam : " + ViewBag.wxJsApiParam);
                //Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                //在页面上显示订单信息
            }
            catch (Exception ex)
            {
                _Apilog.WriteLog("ProductsController/Checkout下单失败" + ex.Message);
            }



            //_Apilog.WriteLog(orderId);
            ViewBag.productsPrice      = productsPrice;
            ViewBag.postage            = postage;
            ViewBag.totalCost          = factPrice + factPostage;//productsPrice + postage;
            ViewBag.FooterType         = "custom";
            ViewBag.PageName           = "结算";
            ViewBag.ProjectUrl         = base.projectURL;
            ViewBag.adminChangeAmount  = userSalesSlip.adminChangeAmount;
            ViewBag.adminChangePostage = userSalesSlip.adminChangePostage;
            checkOutModels.UserAddress = userRes;
            return(View(checkOutModels));
        }