Beispiel #1
0
        /// <summary>
        /// 更新用户收货地址
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool updateUserAddress(useraddress user)
        {
            bool res = false;

            using (IDbConnection conn = DapperHelper.MySqlConnection())
            {
                IDbTransaction transaction = conn.BeginTransaction();
                try
                {
                    if (user.SetAsDefault == "1")
                    {
                        //将该用户原先默认地址设为非默认
                        string updateSQL = "update useraddress set SetAsDefault=0 where status=1 and SetAsDefault=1 and userOpenId=@userOpenId ";
                        conn.Execute(updateSQL, user, transaction);
                    }
                    string sqlCommandText = @"update useraddress set receiver=@receiver,province=@province,city=@city,county=@county,detailAddress=@detailAddress,Phone=@Phone,SetAsDefault=@SetAsDefault,updateDate=@updateDate where status=1 and userOpenId=@userOpenId and id=@Id";
                    conn.Execute(sqlCommandText, user, transaction);
                    //提交事务
                    transaction.Commit();
                    res = true;
                }
                catch (Exception e)
                {
                    //出现异常,事务Rollback
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }
            return(res);
        }
Beispiel #2
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));
        }
Beispiel #3
0
        public JsonResult PayOrder(string receiver, string rPhone, string province, string city, string county, string detailAddress, string orderId, string toStatus)
        {
            string userOpenId = base.getUserOpenIdFromCookie();
            string res        = "fail";

            try
            {
                if (!string.IsNullOrEmpty(userOpenId) && !string.IsNullOrEmpty(orderId))
                {
                    _Orderlog.WriteLog(orderId + " | " + "用户: " + userOpenId + " 开始付款 | " + (int)EnumOrderLogType.normal);
                    salesslip   userSalesSlip = new salesslip();
                    useraddress userRes       = new useraddress();
                    List <UserShopcartsInfo> userUnpaidOrderInfo = new List <UserShopcartsInfo>();
                    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"]); //顺丰非江浙沪快递费
                    userSalesSlip = OrderBiz.CreateNew().getCheckOutInfo(orderId, userOpenId);
                    if (userSalesSlip == null)                                                                                      //查不到销售单
                    {
                        res = "订单不存在";                                                                                              //查不到销售单,跳转至订单列表页面
                    }
                    else if (userSalesSlip.status == 0)                                                                             //0未付款 1已付款待发货 2 已发货,待收货 3 已完成 4 已删除 5 预付款 6 已过期
                    {
                        if (DateTime.Now.AddMinutes(-orderExpiredMins) > userSalesSlip.createDate)                                  //订单已失效,为了减少数据库操作,这边做跳转;
                        {
                            res = "订单已过期";                                                                                          //前端页面会做跳转,数据更新部分统一放到了订单列表
                        }
                        else
                        {
                            #region 邮费计算
                            if (!string.IsNullOrEmpty(province))
                            {
                                if (province.IndexOf("上海") >= 0 ||
                                    province.IndexOf("江苏") >= 0 ||
                                    province.IndexOf("浙江") >= 0)
                                {
                                    postage = SFJZF;
                                }
                                else
                                {
                                    postage = SFNonJZF;
                                }
                            }
                            #endregion
                            #region 订单产品部分
                            userUnpaidOrderInfo = OrderBiz.CreateNew().getUnpaidOrderInfo(userSalesSlip.salesId);

                            foreach (var i in userUnpaidOrderInfo)
                            {
                                productsPrice += i.productTotalPrice ?? 0;
                            }
                            #endregion

                            #region 更新记录
                            salesslip newOrder = new salesslip();
                            newOrder.salesId       = userSalesSlip.salesId;
                            newOrder.salesNo       = orderId;
                            newOrder.userOpenId    = userOpenId;
                            newOrder.receiver      = receiver;
                            newOrder.province      = province;
                            newOrder.city          = city;
                            newOrder.county        = county;
                            newOrder.detailAddress = detailAddress;
                            newOrder.Phone         = rPhone;
                            newOrder.amount        = productsPrice;
                            newOrder.postage       = postage;
                            newOrder.payDate       = System.DateTime.Now;
                            newOrder.status        = 5;//预付款  实际付款后会再更新成1

                            string remark = Newtonsoft.Json.JsonConvert.SerializeObject(userUnpaidOrderInfo);
                            newOrder.column1 = remark;

                            if (OrderBiz.CreateNew().userPaidOrder(newOrder))
                            {
                                _Orderlog.WriteLog(orderId + " | " + "用户预支付成功,订单: " + Newtonsoft.Json.JsonConvert.SerializeObject(newOrder) + "详情: " + remark + "| " + (int)EnumOrderLogType.normal);
                                res = "success";
                            }
                            else
                            {
                                _Orderlog.WriteLog(orderId + " | " + "用户预支付失败!,订单: " + Newtonsoft.Json.JsonConvert.SerializeObject(newOrder) + "详情: " + remark + "| " + (int)EnumOrderLogType.fail);
                                res = "付款失败";
                            }
                            #endregion
                        }
                    }
                    else if (userSalesSlip.status == 5)
                    {
                        userSalesSlip.status = Convert.ToInt32(toStatus);
                        if (Convert.ToInt32(toStatus) == 0)
                        {
                            userSalesSlip.payDate = null;
                        }

                        string remark = Newtonsoft.Json.JsonConvert.SerializeObject(userSalesSlip);
                        if (OrderBiz.CreateNew().userPaidOrder(userSalesSlip))
                        {
                            _Orderlog.WriteLog(orderId + " | " + "用户订单状态更新成功,订单: " + Newtonsoft.Json.JsonConvert.SerializeObject(userSalesSlip) + "详情: " + remark + "| " + (int)EnumOrderLogType.normal);
                            res = "success";// "用户订单状态更新成功";
                        }
                        else
                        {
                            _Orderlog.WriteLog(orderId + " | " + "用户订单状态更新失败!,订单: " + Newtonsoft.Json.JsonConvert.SerializeObject(userSalesSlip) + "详情: " + remark + "| " + (int)EnumOrderLogType.fail);
                            res = "用户订单状态更新失败";
                        }
                    }
                    else//订单状态不为 未付款,需要跳转到对应页面
                    {
                        res = "订单已支付";
                    }
                }
                else
                {
                    _Apilog.WriteLog("ProductsController/PayOrder 用户userOpenId 或 orderId 为空, 用户userOpenId: " + userOpenId + " orderId: " + orderId);
                    _Orderlog.WriteLog(orderId + " | " + "用户userOpenId 或 orderId 为空, 用户userOpenId: " + userOpenId + " orderId: " + orderId + "| " + (int)EnumOrderLogType.fail);
                }
            }
            catch (Exception e)
            {
                _Apilog.WriteLog("ProductsController/PayOrder 异常: " + userOpenId + " orderId: " + orderId + e.Message);
                _Orderlog.WriteLog(orderId + " | " + "支付异常: " + e.Message + e.Source + "| " + (int)EnumOrderLogType.error);
            }
            return(Json(res));
        }
Beispiel #4
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));
        }