Commit 0beda736 authored by 吴春's avatar 吴春

提交自动发放优惠劵

parent e99585d7
......@@ -32,6 +32,11 @@ namespace Mall.Model.Extend.MarketingCenter
/// 发放数量
/// </summary>
public int GrantNum { get; set; }
/// <summary>
/// 触发事件,1-分享,2-购买并付款,3-新人领券
/// </summary>
public int TriggerType { get; set; }
/// <summary>
/// 优惠卷ids
/// </summary>
......
......@@ -6,7 +6,9 @@ using Mall.Model.Extend.User;
using Mall.Model.Query;
using Mall.Repository;
using Mall.Repository.MarketingCenter;
using Mall.Repository.User;
using MySqlX.XDevAPI.Relational;
using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Crypto.Tls;
using System;
using System.Collections.Generic;
......@@ -27,7 +29,10 @@ namespace Mall.Module.MarketingCenter
private RB_Coupon_SelfMotionRepository selfMotionRepository = new RB_Coupon_SelfMotionRepository();
/// <summary>
/// 会员信息
/// </summary>
private readonly RB_Member_UserRepository member_UserRepository = new RB_Member_UserRepository();
......@@ -872,5 +877,117 @@ namespace Mall.Module.MarketingCenter
}
#endregion
#region 自动发放给会员优惠券
/// <summary>
/// 自动给会员发放优惠券
/// </summary>
/// <param name="userId"></param>
/// <param name="getType">1-分享,2-购买并付款,3-新人领券</param>
/// <returns></returns>
public bool AutoCoupon(RB_DiscountCoupon_Extend model)
{
//先查找会员是否存在
var memberUserModel = member_UserRepository.GetEntity(model.UserId);
if (memberUserModel == null)
{
return false;
}
//根据发放类型获取对应的优惠券信息
var couponList = discountCouponRepository.GetSelfmotionCouponList(model);
if (couponList != null && couponList.Any(x => x.TotalNum == -1 || ((x.TotalNum - x.ReceiveNum) > 0)))//存在满足条件的优惠券可以发放
{
bool isReceive = false;
//查询已发放的优惠券信息
var memberCouponList = memberCouponRepository.GetAutoMemberCouponPageList(new RB_Member_DiscountCoupon_Extend { UserId = model.UserId, GetType = model.TriggerType, TenantId = model.TenantId, MallBaseId = model.MallBaseId });
foreach (var item in couponList.Where(x => x.TotalNum == -1 || ((x.TotalNum - x.ReceiveNum) > 0)))//判断当前优惠券是否已超过领取数
{
int membercouponCoun = memberCouponList.Where(x => x.CouponId == item.ID).Count();
if (!isReceive && membercouponCoun < item.GrantNum)//此次没有领取,并且当前优惠券没有超过领取数量
{
var trans = memberCouponRepository.DbTransaction;
try
{
RB_Member_DiscountCoupon nowMemberCoupon = new RB_Member_DiscountCoupon
{
Id = 0,
TenantId = item.TenantId,
MallBaseId = item.MallBaseId,
Status = 0,
CreateDate = System.DateTime.Now,
UserId = item.UserId,
Description = item.TriggerType == 1 ? "分享自动发放优惠券" : (item.TriggerType == 2 ? "购买并付款自动发放优惠券" : "新人领劵自动发放优惠券"),
Remarks = item.TriggerType == 1 ? "分享" : (item.TriggerType == 2 ? "购买并付款" : "新人领劵"),
UseState = 0,
CouponId = item.ID,
StartDate = item.IndateType == Common.Enum.MarketingCenter.IndateTypeEnum.DayHorizon ? System.DateTime.Now : item.StartDate,
EndDate = item.IndateType == Common.Enum.MarketingCenter.IndateTypeEnum.DayHorizon ? System.DateTime.Now.AddDays(item.IndateDay) : item.EndDate,
GetType = item.TriggerType,
UseType = item.UseType,
MinConsumePrice = item.MinConsumePrice,
DiscountsPrice = item.DiscountsPrice,
MaxDiscountsPrice = item.MaxDiscountsPrice,
CouponType = item.CouponType,
Name = item.Name
};
isReceive = memberCouponRepository.Insert(nowMemberCoupon, trans) > 0;
if (isReceive)//更新当前优惠券的领取数量
{
Dictionary<string, object> cols1;
if (item.TotalNum != -1)
{
cols1 = new Dictionary<string, object>()
{
{ nameof(RB_DiscountCoupon.ReceiveNum),item.ReceiveNum+1},
{ nameof(RB_DiscountCoupon.TotalNum),item.TotalNum - 1},
{ nameof(RB_DiscountCoupon.UpdateDate),DateTime.Now},
};
}
else
{
cols1 = new Dictionary<string, object>()
{
{ nameof(RB_DiscountCoupon.ReceiveNum),item.ReceiveNum+1},
{ nameof(RB_DiscountCoupon.UpdateDate),DateTime.Now},
};
}
List<WhereHelper> wheres1 = new List<WhereHelper>()
{
new WhereHelper(){
FiledName=nameof(RB_DiscountCoupon.ID),
FiledValue=item.ID,
OperatorEnum=OperatorEnum.Equal
},
new WhereHelper(){
FiledName=nameof(RB_DiscountCoupon.TenantId),
FiledValue=item.TenantId,
OperatorEnum=OperatorEnum.Equal
},
new WhereHelper(){
FiledName=nameof(RB_DiscountCoupon.MallBaseId),
FiledValue=item.MallBaseId,
OperatorEnum=OperatorEnum.Equal
}
};
discountCouponRepository.Update(cols1, wheres1, trans);
}
memberCouponRepository.DBSession.Commit();
return true;
}
catch (Exception ex)
{
LogHelper.Write(ex, "AutoCoupon");
memberCouponRepository.DBSession.Rollback("AutoCoupon");
return false;
}
}
}
}
return true;
}
#endregion
}
}
......@@ -34,6 +34,7 @@ namespace Mall.Module.User
{
string ids = string.Join(",", list.Select(x => x.BankAccountId));
var backList = clientBankAccountRepository.GetList(new RB_ClientBankAccount(), "", ids);
ids = string.Join(",", list.Select(x => x.ID));
var supplierCommissionList = supplierCommissionRepository.GetListBySupplierIds(ids);
foreach (var item in list)
{
......@@ -60,6 +61,7 @@ namespace Mall.Module.User
{
string ids = string.Join(",", list.Select(x => x.BankAccountId));
var backList = clientBankAccountRepository.GetList(new RB_ClientBankAccount(), "", ids);
ids = string.Join(",", list.Select(x => x.ID));
var supplierCommissionList = supplierCommissionRepository.GetListBySupplierIds(ids);
foreach (var item in list)
{
......@@ -127,7 +129,8 @@ namespace Mall.Module.User
{ nameof(RB_Supplier.Name),model.Name},
{ nameof(RB_Supplier.Mobile),model.Mobile},
{ nameof(RB_Supplier.Address),model.Address},
{ nameof(RB_Supplier.UpdateDate),model.UpdateDate}
{ nameof(RB_Supplier.UpdateDate),model.UpdateDate},
{ nameof(RB_Supplier.Introducer),model.Introducer}
};
IList<WhereHelper> whereHelpersSupplier = new List<WhereHelper>()
{
......@@ -137,24 +140,46 @@ namespace Mall.Module.User
}
var supplierCommissionList = supplierCommissionRepository.GetSupplierCommissionList(new RB_SupplierCommission { SupplierId = model.ID });
foreach (var item in model.SupplierCommissionList)
if (model.SupplierCommissionList != null && model.SupplierCommissionList.Any())
{
var commissionModel = supplierCommissionList.Where(x => x.CommissionType == item.CommissionType).FirstOrDefault();
if (commissionModel != null)
foreach (var item in model.SupplierCommissionList)
{
commissionModel.CommissionRate = item.CommissionRate;
var commissionModel = supplierCommissionList.Where(x => x.CommissionType == item.CommissionType).FirstOrDefault();
if (commissionModel != null)
{
commissionModel.CommissionRate = item.CommissionRate;
supplierCommissionRepository.Update(commissionModel);
supplierCommissionRepository.Update(commissionModel);
}
else
{
item.CreateDate = System.DateTime.Now;
item.UpdateDate = System.DateTime.Now;
item.MallBaseId = model.MallBaseId;
item.TenantId = model.TenantId;
item.SupplierId = model.ID;
item.Status = model.Status;
supplierCommissionRepository.Insert(item);
}
}
else
}
else
{
if (supplierCommissionList != null && supplierCommissionList.Any())
{
item.CreateDate = System.DateTime.Now;
item.UpdateDate = System.DateTime.Now;
item.MallBaseId = model.MallBaseId;
item.TenantId = model.TenantId;
item.SupplierId = model.ID;
item.Status = model.Status;
supplierCommissionRepository.Insert(item);
foreach (var item in supplierCommissionList)
{
IDictionary<string, object> filedsSupplierCommission = new Dictionary<string, object>()
{
{ nameof(RB_SupplierCommission.Status),1},
{ nameof(RB_SupplierCommission.UpdateDate),model.UpdateDate}
};
IList<WhereHelper> whereHelpersSupplierCommission = new List<WhereHelper>()
{
new WhereHelper (){ FiledName=nameof(RB_SupplierCommission.ID),FiledValue=item.ID,OperatorEnum=OperatorEnum.Equal}
};
supplierCommissionRepository.Update(filedsSupplierCommission, whereHelpersSupplierCommission);
}
}
}
}
......@@ -167,12 +192,17 @@ namespace Mall.Module.User
{
model.BankAccountId = id;
int supplierId = supplierRepository.Insert(model);
model.SupplierCommissionList.ForEach(x => x.CreateDate = model.CreateDate);
model.SupplierCommissionList.ForEach(x => x.UpdateDate = model.UpdateDate);
model.SupplierCommissionList.ForEach(x => x.MallBaseId = model.MallBaseId);
model.SupplierCommissionList.ForEach(x => x.TenantId = model.TenantId);
model.SupplierCommissionList.ForEach(x => x.SupplierId = supplierId);
supplierCommissionRepository.InsertBatch(model.SupplierCommissionList);
if (model.SupplierCommissionList != null && model.SupplierCommissionList.Any())
{
model.SupplierCommissionList.ForEach(x => x.CreateDate = model.CreateDate);
model.SupplierCommissionList.ForEach(x => x.UpdateDate = model.UpdateDate);
model.SupplierCommissionList.ForEach(x => x.MallBaseId = model.MallBaseId);
model.SupplierCommissionList.ForEach(x => x.TenantId = model.TenantId);
model.SupplierCommissionList.ForEach(x => x.SupplierId = supplierId);
model.SupplierCommissionList.ForEach(x => x.Status = 0);
supplierCommissionRepository.InsertBatch(model.SupplierCommissionList);
}
flag = supplierId > 0;
//IDictionary<string, object> fileds = new Dictionary<string, object>()
//{
......
......@@ -12,6 +12,7 @@ using Mall.Repository.Product;
using Mall.Model.Extend.Product;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Mall.Model.Entity.MarketingCenter;
namespace Mall.Module.User
{
......@@ -77,6 +78,11 @@ namespace Mall.Module.User
/// vip购买仓储层
/// </summary>
private readonly RB_Vip_BuyRepository vipBuyRepository = new RB_Vip_BuyRepository();
private Repository.MarketingCenter.RB_DiscountCouponRepository discountCouponRepository = new Repository.MarketingCenter.RB_DiscountCouponRepository();
private Repository.User.RB_Member_CouponRepository memberCouponRepository = new Repository.User.RB_Member_CouponRepository();
/// <summary>
/// 初始化分销基础配置
/// </summary>
......@@ -346,6 +352,99 @@ namespace Mall.Module.User
}
//2020-08-04 add by:W 购买并支付自动发放优惠券
var couponList = discountCouponRepository.GetSelfmotionCouponList(new Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend { TenantId = oldOrder.TenantId, MallBaseId = oldOrder.MallBaseId, UserId = oldOrder.UserId ?? 0, TriggerType = 2 });
if (couponList != null && couponList.Any(x => x.TotalNum == -1 || ((x.TotalNum - x.ReceiveNum) > 0)))//存在满足条件的优惠券可以发放
{
bool isReceive = false;
//查询已发放的优惠券信息
var memberCouponList = memberCouponRepository.GetAutoMemberCouponPageList(new RB_Member_DiscountCoupon_Extend { UserId = oldOrder.UserId, GetType =2, TenantId = oldOrder.TenantId, MallBaseId = oldOrder.MallBaseId });
foreach (var item in couponList.Where(x => x.TotalNum == -1 || ((x.TotalNum - x.ReceiveNum) > 0)))//判断当前优惠券是否已超过领取数
{
int membercouponCoun = memberCouponList.Where(x => x.CouponId == item.ID).Count();
if (!isReceive && membercouponCoun < item.GrantNum)//此次没有领取,并且当前优惠券没有超过领取数量
{
var trans = memberCouponRepository.DbTransaction;
try
{
RB_Member_DiscountCoupon nowMemberCoupon = new RB_Member_DiscountCoupon
{
Id = 0,
TenantId = oldOrder.TenantId,
MallBaseId = oldOrder.MallBaseId,
Status = 0,
CreateDate = System.DateTime.Now,
UserId = oldOrder.UserId,
Description = item.TriggerType == 1 ? "分享自动发放优惠券" : (item.TriggerType == 2 ? "购买并付款自动发放优惠券" : "新人领劵自动发放优惠券"),
Remarks = item.TriggerType == 1 ? "分享" : (item.TriggerType == 2 ? "购买并付款" : "新人领劵"),
UseState = 0,
CouponId = item.ID,
StartDate = item.IndateType == Common.Enum.MarketingCenter.IndateTypeEnum.DayHorizon ? System.DateTime.Now : item.StartDate,
EndDate = item.IndateType == Common.Enum.MarketingCenter.IndateTypeEnum.DayHorizon ? System.DateTime.Now.AddDays(item.IndateDay) : item.EndDate,
GetType = item.TriggerType,
UseType = item.UseType,
MinConsumePrice = item.MinConsumePrice,
DiscountsPrice = item.DiscountsPrice,
MaxDiscountsPrice = item.MaxDiscountsPrice,
CouponType = item.CouponType,
Name = item.Name
};
isReceive = memberCouponRepository.Insert(nowMemberCoupon, trans) > 0;
if (isReceive)//更新当前优惠券的领取数量
{
Dictionary<string, object> cols1;
if (item.TotalNum != -1)
{
cols1 = new Dictionary<string, object>()
{
{ nameof(RB_DiscountCoupon.ReceiveNum),item.ReceiveNum+1},
{ nameof(RB_DiscountCoupon.TotalNum),item.TotalNum - 1},
{ nameof(RB_DiscountCoupon.UpdateDate),DateTime.Now},
};
}
else
{
cols1 = new Dictionary<string, object>()
{
{ nameof(RB_DiscountCoupon.ReceiveNum),item.ReceiveNum+1},
{ nameof(RB_DiscountCoupon.UpdateDate),DateTime.Now},
};
}
List<WhereHelper> wheres1 = new List<WhereHelper>()
{
new WhereHelper(){
FiledName=nameof(RB_DiscountCoupon.ID),
FiledValue=item.ID,
OperatorEnum=OperatorEnum.Equal
},
new WhereHelper(){
FiledName=nameof(RB_DiscountCoupon.TenantId),
FiledValue=item.TenantId,
OperatorEnum=OperatorEnum.Equal
},
new WhereHelper(){
FiledName=nameof(RB_DiscountCoupon.MallBaseId),
FiledValue=item.MallBaseId,
OperatorEnum=OperatorEnum.Equal
}
};
discountCouponRepository.Update(cols1, wheres1, trans);
}
memberCouponRepository.DBSession.Commit();
return true;
}
catch (Exception ex)
{
LogHelper.Write(ex, "AutoCoupon");
memberCouponRepository.DBSession.Rollback("AutoCoupon");
return false;
}
}
}
}
//发送订阅消息
......@@ -454,7 +553,7 @@ namespace Mall.Module.User
flag = vipBuyRepository.Update(keyValuesVip, wheresVip, trans);//更新会员购买记录 2020-07-17 Add By: W End
//2020-07-20 Add By:W
Dictionary<string, object> keyValuesDistributor = new Dictionary<string, object>() {
{ nameof(RB_Distributor_Info.VipExpiryDate),distributorModel.VipExpiryDate},
......
......@@ -48,6 +48,7 @@ LEFT JOIN {UserTableName} as b on a.UserId = b.ID WHERE a.{nameof(RB_Coupon_Se
{
builder.Append($" AND a.{nameof(RB_Coupon_SelfMotionMember_Extend.UserId)}={query.UserId}");
}
//if (!string.IsNullOrWhiteSpace(query.PriceIds))
//{
// builder.Append($" AND a.{nameof(RB_Coupon_SelfMotionMember_Extend.RulesPriceId)} in ({query.PriceIds})");
......
......@@ -281,7 +281,7 @@ as t LEFT JOIN (SELECT CouponId,COUNT(*) as MemberNum from rb_member_discountc
where += $" AND a.{nameof(RB_Member_DiscountCoupon_Extend.EndDate)}<NOW() AND a.{nameof(RB_Member_DiscountCoupon_Extend.UseState)}=0";
}
}
string sql = @$" SELECT a.ID as MemberCouponId,a.UseState,a.StartDate,a.EndDate,b.ID,b.`Name`,b.`Describe`,b.CouponType,b.UseType,a.GetType,
string sql = @$" SELECT a.ID as MemberCouponId,a.UseState,a.StartDate,a.EndDate,b.ID,b.`Name`,b.`Describe`,b.CouponType,b.UseType,a.GetType,a.CreateDate,
b.MinConsumePrice,b.MaxDiscountsPrice,b.DiscountsPrice,b.IndateDay,b.IndateType from rb_member_discountcoupon as a LEFT JOIN rb_discountcoupon as b
on a.CouponId=b.ID {where} ";
return GetPage<RB_DiscountCoupon_Extend>(pageIndex, pageSize, out rowCount, sql).ToList();
......@@ -290,6 +290,50 @@ on a.CouponId=b.ID {where} ";
#endregion
#region 自动发放优惠券信息
/// <summary>
/// 获取自动发放优惠券信息
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_DiscountCoupon_Extend> GetSelfmotionCouponList(RB_DiscountCoupon_Extend query)
{
StringBuilder builder = new StringBuilder();
string userWhere = "";
// builder.Append(@$" SELECT a.*,b.TriggerType,b.GrantNum from rb_coupon_selfmotion as b LEFT JOIN {TableName} as a on a.ID=b.DiscountCouponId WHERE a.{nameof(RB_DiscountCoupon_Extend.Status)}=0 and b.`Status`=0 and (a.IndateType=1 or (a.IndateType=2 and a.StartDate<NOW() and a.EndDate>NOW()))");
if (query != null)
{
if (query.TenantId > 0)
{
builder.Append($" AND a.{nameof(RB_DiscountCoupon_Extend.TenantId)}={query.TenantId}");
}
if (query.TenantId > 0)
{
builder.Append($" AND a.{nameof(RB_DiscountCoupon_Extend.MallBaseId)}={query.MallBaseId}");
}
if (query.TriggerType > 0)
{
builder.Append($" AND b.{nameof(RB_DiscountCoupon_Extend.TriggerType)}={query.TriggerType}");
}
if (query.UserId > 0)
{
userWhere += $"and c.UserId={query.UserId}";
}
}
string sql = @$"SELECT a.*,b.TriggerType,b.GrantNum from rb_coupon_selfmotion as b LEFT JOIN {TableName} as a on a.ID=b.DiscountCouponId
where (a.IndateType=1 or (a.IndateType=2 and a.StartDate<NOW() and a.EndDate>NOW()))
and a.`Status`=0 and b.`Status`=0 and IsAll=0 {builder.ToString()}
UNION ALL
SELECT a.*,b.TriggerType,b.GrantNum from rb_coupon_selfmotion as b LEFT JOIN rb_discountcoupon as a on a.ID=b.DiscountCouponId
LEFT JOIN rb_coupon_selfmotionmember as c on c.SelfMotionId=b.ID
where (a.IndateType=1 or (a.IndateType=2 and a.StartDate<NOW() and a.EndDate>NOW())) {builder.ToString()}
and a.`Status`=0 and b.`Status`=0 and IsAll=1 {userWhere} ";
return Get<RB_DiscountCoupon_Extend> (sql).ToList();
}
#endregion
}
}
......@@ -899,7 +899,7 @@ public List<OrderStatistics_Query> GetOrderProfitLossList(int pageIndex, int pag
}
if (!string.IsNullOrWhiteSpace(dmodel.EndDate))
{
where += $" and DATE_FORMAT(a.CreateDate,'%Y-%m-%d' )< DATE_FORMAT('{dmodel.StartDate}','%Y-%m-%d' ) ";
where += $" and DATE_FORMAT(a.CreateDate,'%Y-%m-%d' )< DATE_FORMAT('{dmodel.EndDate}','%Y-%m-%d' ) ";
}
}
......
......@@ -63,7 +63,8 @@ namespace Mall.Repository.User
{
builder.Append($" AND a.{nameof(RB_Member_DiscountCoupon_Extend.CouponId)} in ({query.CouponIds})");
}
if (!string.IsNullOrEmpty(query.Ids)) {
if (!string.IsNullOrEmpty(query.Ids))
{
builder.Append($" AND a.{nameof(RB_Member_DiscountCoupon_Extend.Id)} in ({query.Ids})");
}
if (query.UseState >= 0)
......@@ -391,7 +392,7 @@ LEFT JOIN rb_member_user as d on d.AliasName=a.UserId where a.UseState=1 {buil
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_Member_DiscountCoupon_Extend> GetAllMemberCouponPageList( RB_Member_DiscountCoupon_Extend query)
public List<RB_Member_DiscountCoupon_Extend> GetAllMemberCouponPageList(RB_Member_DiscountCoupon_Extend query)
{
string where = " where a.`Status`=0 ";
if (query != null)
......@@ -424,7 +425,41 @@ LEFT JOIN rb_member_user as d on d.AliasName=a.UserId where a.UseState=1 {buil
}
}
string sql = @$" SELECT a.* from rb_member_discountcoupon as a {where} ";
return Get<RB_Member_DiscountCoupon_Extend>( sql).ToList();
return Get<RB_Member_DiscountCoupon_Extend>(sql).ToList();
}
/// <summary>
/// 自动发放优惠券信息
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_Member_DiscountCoupon_Extend> GetAutoMemberCouponPageList(RB_Member_DiscountCoupon_Extend query)
{
string where = " where a.`Status`=0 ";
if (query != null)
{
if (query.TenantId > 0)
{
where += $" AND a.{nameof(RB_Member_DiscountCoupon_Extend.TenantId)}={query.TenantId}";
}
if (query.MallBaseId > 0)
{
where += $" AND a.{nameof(RB_Member_DiscountCoupon_Extend.MallBaseId)}={query.MallBaseId}";
}
if (query.UserId > 0)
{
where += $" AND a.{nameof(RB_Member_DiscountCoupon_Extend.UserId)}={query.UserId}";
}
if (query.GetType > 0)
{
where += $" AND a.{nameof(RB_Member_DiscountCoupon_Extend.GetType)}={query.GetType}";
}
}
string sql = @$" SELECT a.* from rb_member_discountcoupon as a {where} ";
return Get<RB_Member_DiscountCoupon_Extend>(sql).ToList();
}
}
}
......@@ -20,6 +20,7 @@ using JWT.Serializers;
using Mall.Common.Enum;
using Mall.CacheKey;
using Mall.Common.Pay.WeChatPat;
using Mall.Module.MarketingCenter;
namespace Mall.WebApi.Controllers.User
{
......@@ -31,7 +32,7 @@ namespace Mall.WebApi.Controllers.User
{
private readonly UserModule userModule = new UserModule();
private readonly CouponModule couponModule = new CouponModule();
/// <summary>
/// 商户小程序处理类
/// </summary>
......@@ -44,19 +45,24 @@ namespace Mall.WebApi.Controllers.User
/// <param name="requestMsg"></param>
/// <returns></returns>
[HttpPost]
public ApiResult Login(object requestMsg) {
public ApiResult Login(object requestMsg)
{
var requestParm = JsonConvert.DeserializeObject<RequestParm>(requestMsg.ToString());
RB_Member_User_Extend demodel = JsonConvert.DeserializeObject<RB_Member_User_Extend>(requestParm.msg.ToString());
if (requestParm.TenantId <= 0) {
if (requestParm.TenantId <= 0)
{
return ApiResult.ParamIsNull("请传递商户号");
}
if (requestParm.MallBaseId <= 0) {
if (requestParm.MallBaseId <= 0)
{
return ApiResult.ParamIsNull("请传递小程序id");
}
if (!demodel.Source.HasValue) {
if (!demodel.Source.HasValue)
{
return ApiResult.ParamIsNull("请传递来源平台");
}
if (string.IsNullOrEmpty(demodel.OpenId)) {
if (string.IsNullOrEmpty(demodel.OpenId))
{
return ApiResult.ParamIsNull("请传递唯一码");
}
//验证是否新用户
......@@ -64,10 +70,12 @@ namespace Mall.WebApi.Controllers.User
{
LogHelper.Write(demodel.OpenId + ",SuperiorId:" + (demodel.SuperiorId ?? 0));
//注册新用户
if (string.IsNullOrEmpty(demodel.Name)) {
if (string.IsNullOrEmpty(demodel.Name))
{
return ApiResult.ParamIsNull("请传递用户名称");
}
if (string.IsNullOrEmpty(demodel.Photo)) {
if (string.IsNullOrEmpty(demodel.Photo))
{
return ApiResult.ParamIsNull("请传递用户头像");
}
#region 赋默认值
......@@ -93,7 +101,8 @@ namespace Mall.WebApi.Controllers.User
demodel.WaitSuperiorId = 0;
demodel.BeDownlineDate = DateTime.Now;
}
else {
else
{
demodel.DownlineCondition = basicsModel?.ReferralsCondition ?? DistrbutorReferralsEnum.SCDJ;
demodel.IsBeDownline = 2;
demodel.WaitSuperiorId = demodel.SuperiorId;
......@@ -107,9 +116,19 @@ namespace Mall.WebApi.Controllers.User
demodel.SecretKey = Guid.NewGuid().ToString();
int UserId = userModule.AddMemberUserInfo(demodel);
bool flag = UserId > 0;
if (flag) {
if (flag)
{
//自动发放新人优惠券 2020-08-04 Add By:W
bool couponResult = couponModule.AutoCoupon(new Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend { UserId = UserId, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId, TriggerType = 3 });
if (!couponResult)
{
LogHelper.WriteInfo("新人优惠券领取失败,用户id"+ UserId);
}
#region 粉象返佣 自动注册分销商 普通会员等级
if ((basicsModel?.IsEnableFXGrade ?? 2) == 1) {
if ((basicsModel?.IsEnableFXGrade ?? 2) == 1)
{
try
{
var FXPModel = userModule.GetFXDistributorGradeList(new RB_Distributor_FXGrade_Extend() { IsGuest = 1, MallBaseId = requestParm.MallBaseId, TenantId = requestParm.TenantId }).FirstOrDefault();
......@@ -141,7 +160,7 @@ namespace Mall.WebApi.Controllers.User
string secret = Config.JwtSecretKey;
string token = encoder.Encode(payload, secret);
#endregion
var mmodel = programModule.GetMiniProgramModule(new RB_MiniProgram_Extend() { MallBaseId= demodel.MallBaseId });
var mmodel = programModule.GetMiniProgramModule(new RB_MiniProgram_Extend() { MallBaseId = demodel.MallBaseId });
AppletUserInfo appletUserInfo = new AppletUserInfo()
{
MallBaseId = demodel.MallBaseId,
......@@ -162,10 +181,12 @@ namespace Mall.WebApi.Controllers.User
}
return ApiResult.Failed("注册失败,请联系管理员");
}
else {
else
{
//查询用户信息
var umodel = userModule.GetMemberUserEntityModule(new RB_Member_User_Extend() { TenantId = requestParm.TenantId, MallBaseId = requestParm.MallBaseId, Source = demodel.Source, OpenId = demodel.OpenId });
if (umodel == null) {
if (umodel == null)
{
return ApiResult.Failed("未能查询到用户信息");
}
TokenUserInfo userInfo = new TokenUserInfo { uid = umodel.Id.ToString(), requestFrom = ApiRequestFromEnum.MiniProgram };
......@@ -187,7 +208,7 @@ namespace Mall.WebApi.Controllers.User
string secret = Config.JwtSecretKey;
string token = encoder.Encode(payload, secret);
#endregion
var mmodel = programModule.GetMiniProgramModule(new RB_MiniProgram_Extend() {MallBaseId= umodel.MallBaseId });
var mmodel = programModule.GetMiniProgramModule(new RB_MiniProgram_Extend() { MallBaseId = umodel.MallBaseId });
AppletUserInfo appletUserInfo = new AppletUserInfo()
{
MallBaseId = umodel.MallBaseId,
......@@ -205,7 +226,7 @@ namespace Mall.WebApi.Controllers.User
};
UserReidsCache.AppletUserInfoSet(UserModuleCacheKeyConfig.Applet_Login_Info + umodel.Id, appletUserInfo, Config.JwtExpirTime);
return ApiResult.Success("", appletUserInfo);
}
}
}
/// <summary>
......@@ -214,7 +235,8 @@ namespace Mall.WebApi.Controllers.User
/// <param name="requestMsg"></param>
/// <returns></returns>
[HttpPost]
public ApiResult GetMallToken(object requestMsg) {
public ApiResult GetMallToken(object requestMsg)
{
var requestParm = JsonConvert.DeserializeObject<RequestParm>(requestMsg.ToString());
if (requestParm.TenantId <= 0)
{
......@@ -226,10 +248,12 @@ namespace Mall.WebApi.Controllers.User
}
var appletWeChatModel = programModule.GetMiniProgramModule(new RB_MiniProgram_Extend() { MallBaseId = requestParm.MallBaseId });
if (appletWeChatModel == null) {
if (appletWeChatModel == null)
{
return ApiResult.ParamIsNull("小程序不存在");
}
if (appletWeChatModel.TenantId != requestParm.TenantId) {
if (appletWeChatModel.TenantId != requestParm.TenantId)
{
return ApiResult.ParamIsNull("商户号错误");
}
string token = CacheManager.AppletWeChat.WeiXinReidsCache.Get(appletWeChatModel.MiniAppId);
......@@ -242,7 +266,8 @@ namespace Mall.WebApi.Controllers.User
{
return ApiResult.Success("", token);
}
else {
else
{
return ApiResult.Failed();
}
......
......@@ -18,6 +18,7 @@ using Mall.Model.Extend.Product;
using Mall.Model.Extend.MarketingCenter;
using Mall.Model.Entity.User;
using NPOI.SS.Formula.Functions;
using Google.Protobuf.WellKnownTypes;
namespace Mall.WebApi.Controllers.User
{
......@@ -1100,6 +1101,33 @@ namespace Mall.WebApi.Controllers.User
return ApiResult.Success("", pagelist);
}
/// <summary>
/// 分享领取优惠券
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult ShareCoupon()
{
var parms = RequestParm;
var userInfo = AppletUserInfo;
var query = JsonConvert.DeserializeObject<RB_DiscountCoupon_Extend>(RequestParm.msg.ToString());
query.TenantId = userInfo.TenantId;
query.MallBaseId = userInfo.MallBaseId;
query.UserId = userInfo.UserId;
query.TriggerType = 1;
bool result = couponModule.AutoCoupon(query);
if (result)
{
return ApiResult.Success("优惠券领取成功");
}
else
{
return ApiResult.Failed("优惠券领取失败");
}
}
#endregion
#region 个人中心- 积分明细
......@@ -1305,7 +1333,7 @@ namespace Mall.WebApi.Controllers.User
demodel.TenantId = userInfo.TenantId;
demodel.MallBaseId = userInfo.MallBaseId;
demodel.UserId = userInfo.UserId;
demodel.PayState =1;
demodel.PayState = 1;
var list = userVipModule.GetVipBuyPageList(pagelist.pageIndex, pagelist.pageSize, out long count, demodel);
pagelist.count = Convert.ToInt32(count);
pagelist.pageData = list.Select(x => new
......
......@@ -66,7 +66,7 @@ namespace Mall.WebApi.Controllers.User
BackId = x.ClientBankAccount != null ? x.ClientBankAccount.ID : 0,
x.SupplierCommissionList,
AccountClassifyStr = x.ClientBankAccount != null ? (x.ClientBankAccount?.AccountClassify == 2 ? "银行" : (x.ClientBankAccount?.AccountClassify == 3 ? "虚拟账户" : (x.ClientBankAccount?.AccountClassify == 4 ? "微信支付宝" : (x.ClientBankAccount?.AccountClassify == 1 ? "平台" : "")))) : "",
});
return ApiResult.Success("", pagelist);
}
......@@ -93,7 +93,13 @@ namespace Mall.WebApi.Controllers.User
{
return ApiResult.Failed("请填写联系电话");
}
if (demodel.Introducer > 0)
{
if (demodel.SupplierCommissionList == null || !demodel.SupplierCommissionList.Any())
{
return ApiResult.Failed("请输入供应商返佣比例");
}
}
//if (string.IsNullOrEmpty(demodel.ClientBankAccount.OpenBankName))
//{
// return ApiResult.Failed("请填写开户行!");
......@@ -205,7 +211,7 @@ namespace Mall.WebApi.Controllers.User
}
/// <summary>
/// 获取供应商下拉列表
/// 获取分销商下拉列表
/// </summary>
/// <returns></returns>
[HttpPost]
......
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