Commit d468afd0 authored by liudong1993's avatar liudong1993

我的学习 + 订单线下付款

parent 67a200ad
using VT.FW.DB;
using Mall.Common.Enum.User;
using System;
using System.Collections.Generic;
using System.Text;
using Mall.Common.Enum.Goods;
namespace Mall.Model.Entity.Product
{
/// <summary>
/// 网课学习表实体
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Goods_WK_CourseStudy
{
/// <summary>
/// Id
/// </summary>
public int Id
{
get;
set;
}
/// <summary>
/// 商品id
/// </summary>
public int GoodsId
{
get;
set;
}
/// <summary>
/// 用户id
/// </summary>
public int UserId
{
get;
set;
}
/// <summary>
/// 课程id
/// </summary>
public int CourseId { get; set; }
/// <summary>
/// CreateDate
/// </summary>
public DateTime? CreateDate
{
get;
set;
}
}
}
using VT.FW.DB;
using Mall.Common.Enum.User;
using System;
using System.Collections.Generic;
using System.Text;
using Mall.Common.Enum.Goods;
namespace Mall.Model.Entity.Product
{
/// <summary>
/// 网课学习时间表实体
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Goods_WK_StudyTime
{
/// <summary>
/// Id
/// </summary>
public int Id
{
get;
set;
}
/// <summary>
/// 商品id
/// </summary>
public int GoodsId
{
get;
set;
}
/// <summary>
/// 用户id
/// </summary>
public int UserId
{
get;
set;
}
/// <summary>
/// 学习时长 秒
/// </summary>
public int Time { get; set; }
/// <summary>
/// CreateDate
/// </summary>
public DateTime? CreateDate
{
get;
set;
}
/// <summary>
/// UpdateDate
/// </summary>
public DateTime? UpdateDate
{
get;
set;
}
}
}
using VT.FW.DB;
using System;
using System.Collections.Generic;
using System.Text;
using Mall.Model.Entity.Product;
namespace Mall.Model.Extend.Product
{
/// <summary>
/// 网课学习表扩展实体
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Goods_WK_CourseStudy_Extend : RB_Goods_WK_CourseStudy
{
/// <summary>
/// 商品ids
/// </summary>
public string GoodsIds { get; set; }
}
}
using VT.FW.DB;
using System;
using System.Collections.Generic;
using System.Text;
using Mall.Model.Entity.Product;
namespace Mall.Model.Extend.Product
{
/// <summary>
/// 网课学习时间表扩展实体
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Goods_WK_StudyTime_Extend : RB_Goods_WK_StudyTime
{
/// <summary>
/// 商品ids
/// </summary>
public string GoodsIds { get; set; }
}
}
......@@ -108,6 +108,15 @@ namespace Mall.Module.Education
/// </summary>
private readonly RB_Education_ArticleCommentRepository educationArticleCommentRepository = new RB_Education_ArticleCommentRepository();
/// <summary>
/// 网课学习
/// </summary>
private readonly RB_Goods_WK_CourseStudyRepository goods_WK_CourseStudyRepository = new RB_Goods_WK_CourseStudyRepository();
/// <summary>
/// 网课学习时间
/// </summary>
private readonly RB_Goods_WK_StudyTimeRepository goods_WK_StudyTimeRepository = new RB_Goods_WK_StudyTimeRepository();
#region 课程管理
......@@ -1185,6 +1194,186 @@ namespace Mall.Module.Education
#endregion
#region 我的学习
/// <summary>
/// 获取我的学习时间
/// </summary>
/// <param name="day"></param>
/// <param name="userId"></param>
/// <returns></returns>
public object GetMyStudyTime(int day, int userId)
{
object MyStudyTimeList = new object();
if (day > 0) {
//倒退查询几天学习时间
string EndTime = DateTime.Now.ToString("yyyy-MM-dd");
string StartTime = DateTime.Now.AddDays(1 - day).ToString("yyyy-MM-dd");
var list = goods_WK_StudyTimeRepository.GetMyStudyTimeByDay(userId, StartTime, EndTime);
if (list.Count() != day) {
while (Convert.ToDateTime(StartTime) <= Convert.ToDateTime(EndTime)) {
var model = list.Where(x => x.CreateDate == Convert.ToDateTime(StartTime)).FirstOrDefault();
if (model == null) {
list.Add(new RB_Goods_WK_StudyTime_Extend()
{
CreateDate = Convert.ToDateTime(StartTime),
Time = 0
});
}
}
}
MyStudyTimeList = list.OrderBy(x => x.CreateDate).Select(x => new
{
Date = x.CreateDate.Value.ToString("yyyy-MM-dd"),
TimeFormat = GetTimeConvert(x.Time)
});
}
//今日学习时间
int ToDayTime = goods_WK_StudyTimeRepository.GetMyStudyTimeByToDay(userId, DateTime.Now.ToString("yyyy-MM-dd"));
//累积学习时间
int TotalTime = goods_WK_StudyTimeRepository.GetMyStudyTimeByTotal(userId);
//连续学习天数
int StydyDay = goods_WK_StudyTimeRepository.GetMyStudyTimeByStydyDay(userId);
return new
{
MyStudyTimeList,
ToDayTime = GetTimeConvert(ToDayTime),
TotalTime = GetTimeConvert(TotalTime),
StydyDay
};
}
/// <summary>
/// 获取时间转换
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public object GetTimeConvert(int time) {
decimal minute = Convert.ToDecimal(time) / 60;
if (minute >= 1)
{
decimal hour = minute / 60;
if (hour >= 1)
{
decimal day = hour / 24;
if (day >= 1)
{
return new
{
Time = Math.Truncate(day * 10) / 10,
Unit = "天"
};
}
else {
return new
{
Time = Math.Truncate(hour * 10) / 10,
Unit = "小时"
};
}
}
else {
return new
{
Time = Math.Truncate(minute * 10) / 10,
Unit = "分钟"
};
}
}
else {
return new
{
Time = Convert.ToDecimal(time),
Unit = "秒"
};
}
}
/// <summary>
/// 设置学习时间
/// </summary>
/// <param name="goodsId"></param>
/// <param name="time"></param>
/// <param name="userId"></param>
/// <returns></returns>
public bool SetMyStudyTime(int goodsId, int time, int userId)
{
//获取最后一条记录
var model = goods_WK_StudyTimeRepository.GetMyStudyTimeByLast(userId);
if (model != null && model.GoodsId == goodsId && model.CreateDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
{
//增加时间
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Goods_WK_StudyTime.Time),model.Time + time},
{ nameof(RB_Goods_WK_StudyTime.UpdateDate),DateTime.Now }
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Goods_WK_StudyTime.Id),
FiledValue=model.Id,
OperatorEnum=OperatorEnum.Equal
}
};
return goods_WK_StudyTimeRepository.Update(keyValues, wheres);
}
else {
//插入
return goods_WK_StudyTimeRepository.Insert(new RB_Goods_WK_StudyTime()
{
GoodsId = goodsId,
CreateDate = DateTime.Now,
Id = 0,
Time = time,
UpdateDate = DateTime.Now
}) > 0;
}
}
/// <summary>
/// 设置课程已观看
/// </summary>
/// <param name="goodsId"></param>
/// <param name="courseId"></param>
/// <param name="userId"></param>
/// <returns></returns>
public bool SetMyCourseStudyOK(int goodsId, int courseId, int userId)
{
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Goods_WK_CourseStudy.GoodsId),
FiledValue=goodsId,
OperatorEnum=OperatorEnum.Equal
},
new WhereHelper(){
FiledName=nameof(RB_Goods_WK_CourseStudy.CourseId),
FiledValue=courseId,
OperatorEnum=OperatorEnum.Equal
},
new WhereHelper(){
FiledName=nameof(RB_Goods_WK_CourseStudy.UserId),
FiledValue=userId,
OperatorEnum=OperatorEnum.Equal
}
};
if (goods_WK_CourseStudyRepository.Exists(wheres))
{
return true;
}
else {
//插入记录
return goods_WK_CourseStudyRepository.Insert(new RB_Goods_WK_CourseStudy()
{
UserId = userId,
CourseId = courseId,
CreateDate = DateTime.Now,
GoodsId = goodsId,
Id = 0
}) > 0;
}
}
#endregion
#region 教师管理
/// <summary>
///教师配置列表
......
......@@ -5971,7 +5971,8 @@ namespace Mall.Module.Product
InsuranceMoney = item.InsuranceMoney ?? 0,
InsuranceCostMoney = item.InsuranceCostMoney ?? 0,
InsuranceFinanceId = 0,
CommentGiveIntegral = item.CommentGiveIntegral
CommentGiveIntegral = item.CommentGiveIntegral,
EducationCouponId = item.EducationCouponId
}, trans);
item.Id = detailId;
if (detailId > 0 && SatisfiedGoodsList.Any())
......@@ -10609,7 +10610,15 @@ namespace Mall.Module.Product
{
if (otherType == 21)
{
keyValues.Add(nameof(RB_Goods_OrderDetail.RealMoney), (model.RealMoney ?? 0) + money);
if ((model.YSMoney ?? 0) == 0)
{
//如果应收=0 实收不更新 ld 2020-10-11
keyValues.Add(nameof(RB_Goods_OrderDetail.RealMoney), (model.RealMoney ?? 0));
}
else
{
keyValues.Add(nameof(RB_Goods_OrderDetail.RealMoney), (model.RealMoney ?? 0) + money);
}
}
else
{
......
......@@ -1572,5 +1572,56 @@ namespace Mall.Module.Product
return ApiResult.Failed();
}
}
#region 电商订单线下付款
public bool SetOrderOfflinePayment(RB_Goods_Order_Extend orderModel, int tenantId, int mallBaseId, int empId)
{
//修改订单状态
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Goods_Order.OrderStatus),OrderStatusEnum.WaitSendGoods},
{ nameof(RB_Goods_Order.OrderSource),UserSourceEnum.ERP},
{ nameof(RB_Goods_Order.PaymentTime),DateTime.Now}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Goods_Order.OrderId),
FiledValue=orderModel.OrderId,
OperatorEnum=OperatorEnum.Equal
}
};
bool flag = goods_OrderRepository.Update(keyValues, wheres);
if (flag)
{
//修改订单明细 其他收入
var list = goods_OrderDetailRepository.GetOrderDetailList(new RB_Goods_OrderDetail_Extend() { OrderId = orderModel.OrderId, TenantId = tenantId, MallBaseId = mallBaseId });
foreach (var item in list) {
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_Goods_OrderDetail.YSMoney),0}
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Goods_OrderDetail.Id),
FiledValue=item.Id,
OperatorEnum=OperatorEnum.Equal
}
};
goods_OrderDetailRepository.Update(keyValues1, wheres1);
}
//记录日志
goods_LogRepository.Insert(new RB_Goods_Log()
{
Id = 0,
Type = 1,
SourceId = orderModel.OrderId,
Content = "修改订单为线下付款,EmpId:" + empId,
CreateDate = DateTime.Now,
MallBaseId = mallBaseId,
TenantId = tenantId
});
}
return flag;
}
#endregion
}
}
......@@ -3377,7 +3377,8 @@ namespace Mall.Module.Product
teacher_id = x.TeacherId,
teacher_logo = x.TeacherLogo,
teacher_name = x.Name
})
}),
course_lable_list = !string.IsNullOrEmpty(model?.CourseLable) && model?.CourseLable != "[]" ? JsonConvert.DeserializeObject<List<string>>(model?.CourseLable) : new List<string>()
},
delivery = ""
};
......
using System;
using System.Collections.Generic;
using System.Text;
using Mall.Model.Entity.Product;
using Mall.Model.Extend.Product;
using System.Linq;
namespace Mall.Repository.Product
{
/// <summary>
/// 网课学习仓储层
/// </summary>
public class RB_Goods_WK_CourseStudyRepository : BaseRepository<RB_Goods_WK_CourseStudy>
{
/// <summary>
/// 列表
/// </summary>
/// <param name="dmodel">查询条件</param>
/// <returns></returns>
public List<RB_Goods_WK_CourseStudy_Extend> GetList(RB_Goods_WK_CourseStudy_Extend dmodel)
{
string where = $" 1=1";
if (dmodel.Id > 0) {
where += $@" and gc.{nameof(RB_Goods_WK_CourseStudy.Id)}={dmodel.Id}";
}
if (dmodel.UserId > 0) {
where += $@" and gc.{nameof(RB_Goods_WK_CourseStudy.UserId)}={dmodel.UserId}";
}
if (dmodel.GoodsId > 0) {
where += $@" and gc.{nameof(RB_Goods_WK_CourseStudy.GoodsId)}={dmodel.GoodsId}";
}
if (dmodel.CourseId > 0) {
where += $@" and gc.{nameof(RB_Goods_WK_CourseStudy.CourseId)}={dmodel.CourseId}";
}
if (!string.IsNullOrEmpty(dmodel.GoodsIds)) {
where += $@" and gc.{nameof(RB_Goods_WK_CourseStudy.GoodsId)} in({dmodel.GoodsIds})";
}
string sql = $@"
SELECT gc.* FROM RB_Goods_WK_CourseStudy gc
WHERE {where} ORDER BY gc.Id desc ";
return Get<RB_Goods_WK_CourseStudy_Extend>(sql).ToList();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Mall.Model.Entity.Product;
using Mall.Model.Extend.Product;
using System.Linq;
namespace Mall.Repository.Product
{
/// <summary>
/// 网课学习时间仓储层
/// </summary>
public class RB_Goods_WK_StudyTimeRepository : BaseRepository<RB_Goods_WK_StudyTime>
{
/// <summary>
/// 列表
/// </summary>
/// <param name="dmodel">查询条件</param>
/// <returns></returns>
public List<RB_Goods_WK_StudyTime_Extend> GetList(RB_Goods_WK_StudyTime_Extend dmodel)
{
string where = $" 1=1";
if (dmodel.Id > 0) {
where += $@" and gc.{nameof(RB_Goods_WK_StudyTime.Id)}={dmodel.Id}";
}
if (dmodel.UserId > 0) {
where += $@" and gc.{nameof(RB_Goods_WK_StudyTime.UserId)}={dmodel.UserId}";
}
if (dmodel.GoodsId > 0) {
where += $@" and gc.{nameof(RB_Goods_WK_StudyTime.GoodsId)}={dmodel.GoodsId}";
}
if (!string.IsNullOrEmpty(dmodel.GoodsIds)) {
where += $@" and gc.{nameof(RB_Goods_WK_StudyTime.GoodsId)} in({dmodel.GoodsIds})";
}
string sql = $@"
SELECT gc.* FROM RB_Goods_WK_StudyTime gc
WHERE {where} ORDER BY gc.Id desc ";
return Get<RB_Goods_WK_StudyTime_Extend>(sql).ToList();
}
/// <summary>
/// 获取分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <param name="dmodel"></param>
/// <returns></returns>
public List<RB_Goods_WK_StudyTime_Extend> GetPageList(int pageIndex, int pageSize, out long count, RB_Goods_WK_StudyTime_Extend dmodel)
{
string where = $" 1=1";
if (dmodel.Id > 0)
{
where += $@" and gc.{nameof(RB_Goods_WK_StudyTime.Id)}={dmodel.Id}";
}
if (dmodel.UserId > 0)
{
where += $@" and gc.{nameof(RB_Goods_WK_StudyTime.UserId)}={dmodel.UserId}";
}
if (dmodel.GoodsId > 0)
{
where += $@" and gc.{nameof(RB_Goods_WK_StudyTime.GoodsId)}={dmodel.GoodsId}";
}
if (!string.IsNullOrEmpty(dmodel.GoodsIds))
{
where += $@" and gc.{nameof(RB_Goods_WK_StudyTime.GoodsId)} in({dmodel.GoodsIds})";
}
string sql = $@"
SELECT gc.* FROM RB_Goods_WK_StudyTime gc
WHERE {where} ORDER BY gc.Id desc ";
return GetPage<RB_Goods_WK_StudyTime_Extend>(pageIndex, pageSize, out count, sql).ToList();
}
/// <summary>
/// 学习时间
/// </summary>
/// <param name="userId"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public List<RB_Goods_WK_StudyTime_Extend> GetMyStudyTimeByDay(int userId, string startTime, string endTime)
{
string sql = $@"SELECT DATE_FORMAT(CreateDate,'%Y-%m-%d') CreateDate,SUM(Time) Time FROM rb_goods_wk_studytime WHERE UserId = {userId} AND CreateDate >='{startTime}' AND CreateDate <= '{endTime} 23:59:59'
GROUP BY DATE_FORMAT(CreateDate,'%Y-%m-%d') ORDER BY DATE_FORMAT(CreateDate,'%Y-%m-%d')";
return Get<RB_Goods_WK_StudyTime_Extend>(sql).ToList();
}
/// <summary>
/// 获取今天学习时间
/// </summary>
/// <param name="userId"></param>
/// <param name="time"></param>
/// <returns></returns>
public int GetMyStudyTimeByToDay(int userId, string time)
{
string sql = $@"SELECT DATE_FORMAT(CreateDate,'%Y-%m-%d') CreateDate,SUM(Time) Time FROM rb_goods_wk_studytime WHERE UserId = {userId} AND CreateDate >='{time}' AND CreateDate <= '{time} 23:59:59'
GROUP BY DATE_FORMAT(CreateDate,'%Y-%m-%d') ORDER BY DATE_FORMAT(CreateDate,'%Y-%m-%d')";
var model = Get<RB_Goods_WK_StudyTime_Extend>(sql).FirstOrDefault();
if (model != null)
{
return model.Time;
}
else {
return 0;
}
}
/// <summary>
/// 获取累积学习时间
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public int GetMyStudyTimeByTotal(int userId)
{
string sql = $@"SELECT SUM(Time) Time FROM rb_goods_wk_studytime WHERE UserId = {userId}";
var model = Get<RB_Goods_WK_StudyTime_Extend>(sql).FirstOrDefault();
if (model != null)
{
return model.Time;
}
else
{
return 0;
}
}
/// <summary>
/// 获取连续学习天数
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public int GetMyStudyTimeByStydyDay(int userId)
{
string sql = $@"select GetUserStudyDay({userId})";
var obj = ExecuteScalar(sql);
if (obj != null)
{
return Convert.ToInt32(obj);
}
else {
return 0;
}
}
/// <summary>
/// 获取最后一条记录
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public RB_Goods_WK_StudyTime_Extend GetMyStudyTimeByLast(int userId)
{
string sql = $@"SELECT *FROM rb_goods_wk_studytime WHERE UserId = {userId} limit 1";
return Get<RB_Goods_WK_StudyTime_Extend>(sql).FirstOrDefault();
}
}
}
......@@ -415,6 +415,81 @@ namespace Mall.WebApi.Controllers.Education
#endregion
#region 我的学习
/// <summary>
/// 获取我的学习时间
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetMyStudyTime() {
var req = RequestParm;
var userInfo = AppletUserInfo;
JObject parms = JObject.Parse(req.msg.ToString());
int Day = parms.GetInt("Day", 0);
var obj = educationModule.GetMyStudyTime(Day, userInfo.UserId);
return ApiResult.Success("", obj);
}
/// <summary>
/// 增加课程学习时间
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetMyStudyTime() {
var req = RequestParm;
var userInfo = AppletUserInfo;
JObject parms = JObject.Parse(req.msg.ToString());
int GoodsId = parms.GetInt("GoodsId", 0);
int Time = parms.GetInt("Time", 10);//秒
int CourseId = parms.GetInt("CourseId", 0);//课程id
if (GoodsId <= 0) {
return ApiResult.ParamIsNull("请传递课程id");
}
if (Time <= 0) {
return ApiResult.ParamIsNull("时间不能小于等于0");
}
bool flag = educationModule.SetMyStudyTime(GoodsId, Time, userInfo.UserId);
if (flag)
{
return ApiResult.Success();
}
else {
return ApiResult.Failed();
}
}
/// <summary>
/// 设置课程已观看
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetMyCourseStudyOK()
{
var req = RequestParm;
var userInfo = AppletUserInfo;
JObject parms = JObject.Parse(req.msg.ToString());
int GoodsId = parms.GetInt("GoodsId", 0);
int CourseId = parms.GetInt("CourseId", 0);//课程id
if (GoodsId <= 0)
{
return ApiResult.ParamIsNull("请传递课程id");
}
if (CourseId <= 0)
{
return ApiResult.ParamIsNull("请传递课程id");
}
bool flag = educationModule.SetMyCourseStudyOK(GoodsId, CourseId, userInfo.UserId);
if (flag)
{
return ApiResult.Success();
}
else
{
return ApiResult.Failed();
}
}
#endregion
#region 资讯留言
......
......@@ -1557,7 +1557,39 @@ namespace Mall.WebApi.Controllers.MallBase
}
/// <summary>
/// 设置订单为线下付款
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetOrderOfflinePayment()
{
var req = RequestParm;
JObject parms = JObject.Parse(req.msg.ToString());
int OrderId = parms.GetInt("OrderId", 0);
if (OrderId <= 0)
{
return ApiResult.ParamIsNull("请传递订单明细id");
}
var orderModel = orderModule.GetOrderInfo(OrderId);
if (orderModel == null) {
return ApiResult.Failed("订单不存在");
}
if (orderModel.OrderStatus != OrderStatusEnum.Cancel && orderModel.OrderStatus != OrderStatusEnum.NonPayment && orderModel.PaymentTime.HasValue)
{
return ApiResult.Failed("订单状态不正确");
}
bool flag = orderModule.SetOrderOfflinePayment(orderModel, req.TenantId, req.MallBaseId, req.EmpId);
if (flag)
{
return ApiResult.Success();
}
else
{
return ApiResult.Failed();
}
}
#endregion
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment