12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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;
- }
- /// <summary>
- /// 创建微信订单
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public async Task<bool> 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;
- }
- /// <summary>
- /// 支付宝
- /// </summary>
- /// <param name="sArray"></param>
- /// <returns></returns>
- public async Task<bool> InsertAliPayOrderAsync(Dictionary<string, string> 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;
- }
- }
- }
|