Example #1
0
        public async Task <BaseResult <bool> > Pay(string order_id, int payway, SendMailConfig sendMailConfig)
        {
            if (string.IsNullOrEmpty(order_id))
            {
                return(new BaseResult <bool>(808));
            }
            //第一步:查询订单信息,如果订单有问题,则不允许用户修改支付状态
            UserOrderInfo query = (from o in await orderRepository.GetAllAsync(c => c.order_id == order_id)
                                   join u in await userRepository.GetAllAsync() on o.user_id equals u.user_id
                                   select new UserOrderInfo()
            {
                order_id = o.order_id,
                order_number = o.order_number,
                order_goods = o.order_goods,
                order_delete = o.order_delete,
                disable = o.disable,
                user_email = u.user_email,
            }).FirstOrDefault();

            //已支付,已禁用,已删除 不允许操作
            if (query.order_paystatus == 2)
            {
                return(new BaseResult <bool>(5002));
            }
            if (query.disable == 1)
            {
                return(new BaseResult <bool>(5000));
            }
            if (query.order_delete != 1)
            {
                return(new BaseResult <bool>(5001));
            }

            var orderdetail = await orderDetailRepository.GetAllAsync(c => c.order_id == order_id);

            query.orderdetail = orderdetail;

            //首先查询信息并且发送邮件,如果邮件发送成功同步修改订单信息,否则不修改订单信息

            //根据订单详情查询对应的商品信息(商品名称,商品编码 商品code 商品下载地址 对应下载码),然后拼接发送的信息发送邮件
            IList <ShopDetailInfo> shopDetailList = (from s in await shopRepository.GetAllAsync(s => (from o in orderdetail select o.shop_id).Contains(s.shop_id))
                                                     join k in await shopSkuRepository.GetAllAsync(k => (from o in orderdetail select o.shopsku_id).Contains(k.shopsku_id)) on s.shop_id equals k.shop_id
                                                     select new ShopDetailInfo()
            {
                shopEntity = s,
                shopSkuEntity = k
            }).ToList();
            StringBuilder sbHtmlEmail = new StringBuilder();

            for (int i = 0; i < shopDetailList.Count; i++)
            {
                sbHtmlEmail.AppendFormat(@"<tr>
                    <td style='padding - left:10px; padding - right:10px; padding - top:5px; padding - bottom:5px; '>{0}</td>
                    <td style='padding - left:10px; padding - right:10px; padding - top:5px; padding - bottom:5px; '>{1}</td>
                    <td style='padding - left:10px; padding - right:10px; padding - top:5px; padding - bottom:5px; '>
                        <a href='{2}'>{2}</a></td><td style='padding - left:10px; padding - right:10px; padding - top:5px; padding - bottom:5px; '>{3}</td></tr>",
                                         shopDetailList[i].shopEntity.shop_name, shopDetailList[i].shopSkuEntity.shop_code, shopDetailList[i].shopSkuEntity.shopsku_url, shopDetailList[i].shopSkuEntity.shopsku_code);
            }
            var isEmailTrue = await EmailUtil.SendEmailAsync(query.user_email, string.Format(EmailKeyUtil.send_order_title, query.user_email),
                                                             string.Format(EmailKeyUtil.send_order_content, query.user_email, sbHtmlEmail.ToString()), sendMailConfig, "h");

            if (isEmailTrue)
            {
                OrderEntity order = new OrderEntity()
                {
                    order_id        = order_id,
                    order_paystatus = 2,
                    order_payway    = payway,
                    order_goods     = 2
                };
                var isTrue = await orderRepository.UpdateAsync(order, true, true, o => o.order_paystatus, o => o.order_payway, o => o.order_goods);

                if (isTrue)
                {
                    return(new BaseResult <bool>(200));
                }
            }
            return(new BaseResult <bool>(201));
        }
Example #2
0
        public async Task <BaseResult <bool> > UpgradeOrder(string order_id, string check_shopsku_id, string shopsku_id, SendMailConfig sendMailConfig)
        {
            if (string.IsNullOrEmpty(order_id) || string.IsNullOrEmpty(shopsku_id) || string.IsNullOrEmpty(check_shopsku_id))
            {
                return(new BaseResult <bool>(808, false));
            }
            var check_data = await shopSkuRepository.GetAsync(c => c.shopsku_id == check_shopsku_id);   //新选择的价钱

            var data = await shopSkuRepository.GetAsync(c => c.shopsku_id == shopsku_id);               //原始的商品价钱

            double money = Convert.ToDouble(check_data.shopsku_currentprice) - Convert.ToDouble(data.shopsku_currentprice);

            if (money < 0)
            {
                return(new BaseResult <bool>(5004, false));
            }

            var userOrderInfo = (from o in await orderRepository.GetAllAsync(c => c.order_id == order_id)
                                 join od in await orderDetailRepository.GetAllAsync(c => c.shopsku_id == shopsku_id) on o.order_id equals od.order_id
                                 join u in await userRepository.GetAllAsync() on o.user_id equals u.user_id
                                 select new
            {
                u.user_email,
                o.order_total,
                o.order_actualpay,
                od.orderdetail_id
            }).FirstOrDefault();
            //首先发送邮件,邮件发送成功之后发修改数据库结构
            var emailSend = (from shop in await shopRepository.GetAllAsync()
                             join shopsku in await shopSkuRepository.GetAllAsync(c => c.shopsku_id == check_shopsku_id) on shop.shop_id equals shopsku.shop_id
                             select new
            {
                shop.shop_name,
                shopsku.shop_code,
                shopsku.shopsku_url,
                shopsku.shopsku_code,
                shopsku.shopsku_currentprice
            }).FirstOrDefault();
            string sbHtmlEmail = string.Format(@"<tr>
                    <td style='padding - left:10px; padding - right:10px; padding - top:5px; padding - bottom:5px; '>{0}</td>
                    <td style='padding - left:10px; padding - right:10px; padding - top:5px; padding - bottom:5px; '>{1}</td>
                    <td style='padding - left:10px; padding - right:10px; padding - top:5px; padding - bottom:5px; '>
                        <a href='{2}'>{2}</a></td><td style='padding - left:10px; padding - right:10px; padding - top:5px; padding - bottom:5px; '>{3}</td></tr>",
                                               emailSend.shop_name, emailSend.shop_code, emailSend.shopsku_url, emailSend.shopsku_code);

            var isEmailTrue = await EmailUtil.SendEmailAsync(userOrderInfo.user_email, string.Format(EmailKeyUtil.send_order_title, userOrderInfo.user_email),
                                                             string.Format(EmailKeyUtil.send_order_content, userOrderInfo.user_email, sbHtmlEmail.ToString()), sendMailConfig, "h");

            if (isEmailTrue)
            {
                var orderEntity = new OrderEntity()
                {
                    order_id        = order_id,
                    order_total     = Convert.ToDouble(userOrderInfo.order_total) + money,
                    order_actualpay = Convert.ToDouble(userOrderInfo.order_actualpay) + money,
                };
                var orderDetailEntity = new OrderDetailEntity
                {
                    orderdetail_id    = userOrderInfo.orderdetail_id,
                    shopsku_id        = check_shopsku_id,
                    shop_currentprice = Convert.ToDouble(emailSend.shopsku_currentprice),
                };

                var isOrder = await orderRepository.UpdateAsync(orderEntity, false, true, c => c.order_total, c => c.order_actualpay);

                var isOrderDetail = await orderDetailRepository.UpdateAsync(orderDetailEntity, false, true, c => c.shopsku_id, c => c.shop_currentprice);

                if (unitOfWork.SaveCommit())
                {
                    return(new BaseResult <bool>(200, true));
                }
            }
            return(new BaseResult <bool>(201, false));
        }
Example #3
0
        public async Task <BaseResult <bool> > UpdateUserName(string user_id, string user_name, string user_email, SendMailConfig sendMailConfig, string host_url)
        {
            if (string.IsNullOrEmpty(user_id) || string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_email))
            {
                return(new BaseResult <bool>(808, false));
            }
            string md5      = CommonUtil.Md5(user_id + user_email);
            string http_url = "http://" + host_url + "/Login/Activation?key=" + md5 + "&user_id=" + user_id;

            var isEmailTrue = await EmailUtil.SendEmailAsync(user_email, string.Format(EmailKeyUtil.send_user_activation_title, user_email),
                                                             string.Format(EmailKeyUtil.send_user_activation_content, user_email, http_url, http_url, http_url),
                                                             sendMailConfig, "h");

            if (isEmailTrue)
            {
                var isTrue = await userRepository.UpdateAsync(new UserEntity()
                {
                    user_id = user_id, user_name = user_name
                }, true, true, c => c.user_name);

                return(new BaseResult <bool>(200, true));
            }
            return(new BaseResult <bool>(201, false));
        }