mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 18:43:26 +08:00
完成充值功能整体开发。
This commit is contained in:
@@ -58,6 +58,8 @@ namespace CoreCms.Net.Services
|
||||
private readonly ICoreCmsServicesServices _servicesServices;
|
||||
private readonly ICoreCmsUserServicesOrderServices _userServicesOrderServices;
|
||||
private readonly ICoreCmsUserWeChatInfoServices _userWeChatInfoServices;
|
||||
private readonly ICoreCmsTopUpTypeServices _topUpTypeServices;
|
||||
private readonly ICoreCmsUserPointLogServices _userPointLogServices;
|
||||
private readonly WeChatOptions _weChatOptions;
|
||||
|
||||
|
||||
@@ -75,8 +77,7 @@ namespace CoreCms.Net.Services
|
||||
, IServiceProvider serviceProvider, ICoreCmsServicesServices servicesServices
|
||||
, ICoreCmsUserServicesOrderServices userServicesOrderServices
|
||||
, ICoreCmsUserWeChatInfoServices userWeChatInfoServices
|
||||
, IOptions<WeChatOptions> weChatOptions
|
||||
)
|
||||
, IOptions<WeChatOptions> weChatOptions, ICoreCmsTopUpTypeServices topUpTypeServices, ICoreCmsUserPointLogServices userPointLogServices)
|
||||
{
|
||||
this._dal = dal;
|
||||
base.BaseDal = dal;
|
||||
@@ -94,6 +95,8 @@ namespace CoreCms.Net.Services
|
||||
_servicesServices = servicesServices;
|
||||
_userServicesOrderServices = userServicesOrderServices;
|
||||
_userWeChatInfoServices = userWeChatInfoServices;
|
||||
_topUpTypeServices = topUpTypeServices;
|
||||
_userPointLogServices = userPointLogServices;
|
||||
_weChatOptions = weChatOptions.Value;
|
||||
}
|
||||
|
||||
@@ -152,9 +155,17 @@ namespace CoreCms.Net.Services
|
||||
//充值
|
||||
else if (type == (int)GlobalEnumVars.BillPaymentsType.Recharge)
|
||||
{
|
||||
if (@params != null && @params.ContainsKey("money"))
|
||||
var typeId = Convert.ToInt16(orderId);
|
||||
var typeModel = await _topUpTypeServices.QueryByClauseAsync(p => p.id == typeId, true);
|
||||
|
||||
if (typeModel != null)
|
||||
{
|
||||
dto.money = @params["money"].ObjectToDecimal(0); //充值金额
|
||||
dto.rel.Add(new Rel()
|
||||
{
|
||||
sourceId = orderId,
|
||||
money = typeModel.defaultMoney
|
||||
});
|
||||
dto.money += typeModel.defaultMoney;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -162,11 +173,7 @@ namespace CoreCms.Net.Services
|
||||
jm.msg = "请输入正确的充值金额";
|
||||
return jm;
|
||||
}
|
||||
dto.rel.Add(new Rel()
|
||||
{
|
||||
sourceId = orderId,
|
||||
money = dto.money
|
||||
});
|
||||
|
||||
jm.status = true;
|
||||
jm.data = dto;
|
||||
}
|
||||
@@ -310,23 +317,27 @@ namespace CoreCms.Net.Services
|
||||
//充值
|
||||
else if (type == (int)GlobalEnumVars.BillPaymentsType.Recharge)
|
||||
{
|
||||
if (@params != null && @params.ContainsKey("money"))
|
||||
{
|
||||
dto.money = @params["money"].ObjectToDecimal(0); //充值金额
|
||||
}
|
||||
else
|
||||
{
|
||||
jm.status = false;
|
||||
jm.msg = "请输入正确的充值金额";
|
||||
return jm;
|
||||
}
|
||||
foreach (var item in sourceStr)
|
||||
{
|
||||
dto.rel.Add(new Rel()
|
||||
var typeId = Convert.ToInt16(item);
|
||||
var typeModel = await _topUpTypeServices.QueryByClauseAsync(p => p.id == typeId, true);
|
||||
|
||||
if (typeModel != null)
|
||||
{
|
||||
sourceId = item,
|
||||
money = dto.money
|
||||
});
|
||||
dto.rel.Add(new Rel()
|
||||
{
|
||||
sourceId = item,
|
||||
money = typeModel.defaultMoney
|
||||
});
|
||||
dto.money += typeModel.defaultMoney;
|
||||
}
|
||||
else
|
||||
{
|
||||
jm.status = false;
|
||||
jm.msg = "请输入正确的充值金额";
|
||||
return jm;
|
||||
}
|
||||
|
||||
}
|
||||
jm.status = true;
|
||||
jm.data = dto;
|
||||
@@ -425,7 +436,7 @@ namespace CoreCms.Net.Services
|
||||
/// <summary>
|
||||
/// 支付,先生成支付单,然后去支付
|
||||
/// </summary>
|
||||
/// <param name="sourceStr">来源,一般是订单号或者用户id,比如充值</param>
|
||||
/// <param name="sourceStr">来源,一般是订单号或者用户id</param>
|
||||
/// <param name="paymentCode">支付方式</param>
|
||||
/// <param name="userId">用户序列</param>
|
||||
/// <param name="type">订单/充值/服务订单</param>
|
||||
@@ -443,10 +454,10 @@ namespace CoreCms.Net.Services
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
//如果支付类型为余额充值,那么资源ID就是用户ID
|
||||
if (type == (int)GlobalEnumVars.BillPaymentsType.Recharge)
|
||||
{
|
||||
sourceStr = userId.ToString();
|
||||
}
|
||||
//if (type == (int)GlobalEnumVars.BillPaymentsType.Recharge)
|
||||
//{
|
||||
// sourceStr = userId.ToString();
|
||||
//}
|
||||
//判断支付方式是否开启
|
||||
var paymentInfo = await _paymentsServices.QueryByClauseAsync(p => p.code == paymentCode && p.isEnable == true);
|
||||
if (paymentInfo == null)
|
||||
@@ -611,6 +622,12 @@ namespace CoreCms.Net.Services
|
||||
|
||||
jm.data = jm.code = 10059;
|
||||
jm.msg = GlobalErrorCodeVars.Code10059;
|
||||
jm.otherData = new
|
||||
{
|
||||
sourceStrArr,
|
||||
sourceStr,
|
||||
paymentRelData
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
//取支付标题,就不往数据库里存了吧
|
||||
@@ -679,8 +696,20 @@ namespace CoreCms.Net.Services
|
||||
else if (billPaymentInfo.type == (int)GlobalEnumVars.BillPaymentsType.Recharge)
|
||||
{
|
||||
//给用户做充值
|
||||
var userId = billPaymentInfo.sourceId.ObjectToInt(0);
|
||||
await _userBalanceServices.Change(userId, (int)GlobalEnumVars.UserBalanceSourceTypes.Recharge, billPaymentInfo.money, billPaymentInfo.paymentId);
|
||||
var topUpTypeId = billPaymentInfo.sourceId.ObjectToInt(0);
|
||||
|
||||
var topUpTypeModel = await _topUpTypeServices.QueryByClauseAsync(p => p.id == topUpTypeId, true);
|
||||
if (topUpTypeModel != null)
|
||||
{
|
||||
var topUpMoney = topUpTypeModel.defaultMoney + topUpTypeModel.giftMoney;
|
||||
await _userBalanceServices.Change(billPaymentInfo.userId, (int)GlobalEnumVars.UserBalanceSourceTypes.Recharge, topUpMoney, billPaymentInfo.paymentId);
|
||||
|
||||
if (topUpTypeModel.giftPoint > 0)
|
||||
{
|
||||
await _userPointLogServices.SetPoint(billPaymentInfo.userId, topUpTypeModel.giftPoint,
|
||||
(int)GlobalEnumVars.UserPointSourceTypes.PointTypeTopUp, "充值赠送积分");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (billPaymentInfo.type == (int)GlobalEnumVars.BillPaymentsType.ServiceOrder)
|
||||
{
|
||||
|
||||
111
CoreCms.Net.Services/Shop/CoreCmsTopUpTypeServices.cs
Normal file
111
CoreCms.Net.Services/Shop/CoreCmsTopUpTypeServices.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2023/3/20 21:20:30
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.Basics;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
namespace CoreCms.Net.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 充值类型 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsTopUpTypeServices : BaseServices<CoreCmsTopUpType>, ICoreCmsTopUpTypeServices
|
||||
{
|
||||
private readonly ICoreCmsTopUpTypeRepository _dal;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public CoreCmsTopUpTypeServices(IUnitOfWork unitOfWork, ICoreCmsTopUpTypeRepository dal)
|
||||
{
|
||||
this._dal = dal;
|
||||
base.BaseDal = dal;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
#region 实现重写增删改查操作==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步插入方法
|
||||
/// </summary>
|
||||
/// <param name="entity">实体数据</param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> InsertAsync(CoreCmsTopUpType entity)
|
||||
{
|
||||
return await _dal.InsertAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> UpdateAsync(CoreCmsTopUpType entity)
|
||||
{
|
||||
return await _dal.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID的数据
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> DeleteByIdAsync(object id)
|
||||
{
|
||||
return await _dal.DeleteByIdAsync(id);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取缓存的所有数据==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存的所有数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<CoreCmsTopUpType>> GetCaChe()
|
||||
{
|
||||
return await _dal.GetCaChe();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 重写根据条件查询分页数据
|
||||
/// <summary>
|
||||
/// 重写根据条件查询分页数据
|
||||
/// </summary>
|
||||
/// <param name="predicate">判断集合</param>
|
||||
/// <param name="orderByType">排序方式</param>
|
||||
/// <param name="pageIndex">当前页面索引</param>
|
||||
/// <param name="pageSize">分布大小</param>
|
||||
/// <param name="orderByExpression"></param>
|
||||
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<IPageList<CoreCmsTopUpType>> QueryPageAsync(Expression<Func<CoreCmsTopUpType, bool>> predicate,
|
||||
Expression<Func<CoreCmsTopUpType, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
|
||||
int pageSize = 20, bool blUseNoLock = false)
|
||||
{
|
||||
return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user