using System.Threading.Tasks; using GxPress.Common.WechatPay; using GxPress.Repository.Interface.Order; using GxPress.Service.Interface.Order; using GxPress.Repository.Interface.Media; using GxPress.Repository.Interface; using System; using System.Collections.Generic; namespace GxPress.Service.Implement.Order { public class OrderService : IOrderService { private readonly IOrderRepository orderRepository; private readonly IMediaRepository mediaRepository; private readonly IUserRepository userRepository; public OrderService(IOrderRepository orderRepository, IMediaRepository mediaRepository, IUserRepository userRepository) { this.orderRepository = orderRepository; this.mediaRepository = mediaRepository; this.userRepository = userRepository; } /// /// 创建微信订单 /// /// /// public async Task InsertWxOrderAsync(WxPayData data) { var order = new Entity.Order.Order(); var attach = data.GetValue("attach").ToString(); if (attach.Split('_').Length > 0) { //获取medio属性 var media = await mediaRepository.GetAsync(attach.Split('_')[0]); //获取用户数据 var user = await userRepository.GetAsync(int.Parse(attach.Split('_')[1])); order.OutTradeNo = data.GetValue("out_trade_no").ToString(); order.OrderType = 1; order.IsRefund = false; order.IsSuccess = true; order.IsVip = user.IsVip; order.MediaId = media.Id; order.Explain = media.Title; order.Name = user.Name; order.OrderNumber = DateTime.Now.Ticks.ToString(); order.Price = Decimal.Parse(data.GetValue("total_fee").ToString()) / 100; order.TransactionId = data.GetValue("transaction_id").ToString(); order.UserId = user.Id; order.PayWay = 1; return await orderRepository.InsertAsync(order) > 0; } return false; } /// /// 支付宝 /// /// /// public async Task InsertAliPayOrderAsync(Dictionary sArray) { var order = new Entity.Order.Order(); var attach = sArray["out_trade_no"].ToString(); if (attach.Split('_').Length > 0) { //获取medio属性 var media = await mediaRepository.GetAsync(attach.Split('_')[0]); //获取用户数据 var user = await userRepository.GetAsync(int.Parse(attach.Split('_')[1])); order.OutTradeNo = sArray["out_trade_no"].ToString(); order.OrderType = 1; order.IsRefund = false; order.IsSuccess = true; order.IsVip = user.IsVip; order.MediaId = media.Id; order.Explain = media.Title; order.Name = user.Name; order.OrderNumber = DateTime.Now.Ticks.ToString(); order.Price = decimal.Parse(sArray["total_amount"].ToString()); order.TransactionId = sArray["trade_no"].ToString(); order.UserId = user.Id; order.PayWay = 2; return await orderRepository.InsertAsync(order) > 0; } return false; } } }