Commit 2f963457 authored by 吴春's avatar 吴春
parents d654ab8e f7c90817
......@@ -12,8 +12,6 @@ namespace Mall.Common.Pay.WeChatPat
public class TokenHelper
{
/// <summary>
/// 获取token
/// </summary>
......@@ -41,7 +39,58 @@ namespace Mall.Common.Pay.WeChatPat
return token;
}
/// <summary>
/// 获取微信用户头像
/// </summary>
/// <param name="access_token"></param>
/// <param name="openid"></param>
/// <returns></returns>
public static string GetWeiXinUserPhoto(string access_token, string openid)
{
openid = openid.Replace("/t", "");
string url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + access_token + "&openid=" + openid + "&lang=zh_CN";
//string url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openid + "&lang=zh_CN";
string type = "utf-8";
Mall.Common.Plugin.GetUsersHelper GetUsersHelper = new Mall.Common.Plugin.GetUsersHelper();
string wenXinResult = string.Empty;
string Photo = "";
try
{
wenXinResult = GetUsersHelper.GetUrltoHtml(url, type);
var jo = (JObject)JsonConvert.DeserializeObject(wenXinResult);
Photo = jo["headimgurl"].ToString();
}
catch (Exception ex)
{
Plugin.LogHelper.Write(ex, string.Format("GetWx:GetWeiXinUserPhoto:{0}", wenXinResult));
}
return Photo;
}
/// <summary>
/// 获取赞羊下级用户
/// </summary>
/// <param name="UserId"></param>
/// <returns></returns>
public static string GetZYUserInfo(int UserId,string cookie)
{
string url = "http://wx.weibaoge.cn/web/index.php?r=mall%2Fshare%2Fteam&status=1&id=" + UserId;
string wenXinResult = string.Empty;
string data = "";
try
{
wenXinResult = Mall.Common.Plugin.HttpHelper.HttpGet(url, System.Text.Encoding.UTF8, "", cookie);
var jo = (JObject)JsonConvert.DeserializeObject(wenXinResult);
if (jo["code"].ToString() == "0") {
data = jo["data"].ToString();
}
}
catch (Exception ex)
{
Plugin.LogHelper.Write(ex, string.Format("GetZYUserInfo:{0}", wenXinResult));
}
return data;
}
}
......
......@@ -65,13 +65,17 @@ namespace Mall.Common.Plugin
/// <param name="encode">编码方式</param>
/// <param name="Source">来源</param>
/// <returns></returns>
public static string HttpGet(string url, Encoding encode, string Source)
public static string HttpGet(string url, Encoding encode, string Source, string cookie="")
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
if (!string.IsNullOrEmpty(Source))
{
myRequest.Referer = Source;
}
if (!string.IsNullOrEmpty(cookie))
{
myRequest.Headers.Add("cookie", cookie);
}
myRequest.Method = "GET";
HttpWebResponse myResponse = null;
try
......
......@@ -25,15 +25,16 @@ namespace Mall.Model.Entity.User
/// <summary>
/// 头部图片
/// </summary>
public int? HeadImage
public string HeadImage
{
get;
set;
}
/// <summary>
/// 底部图片
/// </summary>
public int? BottomImage
public string BottomImage
{
get;
set;
......@@ -97,7 +98,7 @@ namespace Mall.Model.Entity.User
/// <summary>
/// 分销佣金图片
/// </summary>
public int? DistributionCommissionImage
public string DistributionCommissionImage
{
get;
set;
......@@ -113,7 +114,7 @@ namespace Mall.Model.Entity.User
/// <summary>
/// 分销订单图片
/// </summary>
public int? DistributionOrderImage
public string DistributionOrderImage
{
get;
set;
......@@ -129,7 +130,7 @@ namespace Mall.Model.Entity.User
/// <summary>
/// 提现明细图片
/// </summary>
public int? WithdrawDetialsImage
public string WithdrawDetialsImage
{
get;
set;
......@@ -145,7 +146,7 @@ namespace Mall.Model.Entity.User
/// <summary>
/// 我的团队图片
/// </summary>
public int? MyTeamImage
public string MyTeamImage
{
get;
set;
......@@ -161,7 +162,7 @@ namespace Mall.Model.Entity.User
/// <summary>
/// 推广二维码图片
/// </summary>
public int? PromoteQRCodeImage
public string PromoteQRCodeImage
{
get;
set;
......
......@@ -13,6 +13,10 @@ namespace Mall.Model.Extend.User
[DB(ConnectionName = "DefaultConnection")]
public class RB_Member_User_Extend : RB_Member_User
{
/// <summary>
/// 是否用户头像为空 1是 2否
/// </summary>
public int? IsEmptyUserPhoto { get; set; }
/// <summary>
/// 会员等级名称
/// </summary>
......@@ -28,6 +32,11 @@ namespace Mall.Model.Extend.User
/// </summary>
public string UserIds { get; set; }
/// <summary>
/// 获取用户
/// </summary>
public int? MinUserId { get; set; }
/// <summary>
/// 用户名str
/// </summary>
......
......@@ -104,7 +104,7 @@ namespace Mall.Model.Query
/// 赞羊区域导入
/// </summary>
[Serializable]
public class GoodsAreaListImport {
public class GoodsAreaListImport {
/// <summary>
/// 列表
/// </summary>
......@@ -127,4 +127,20 @@ namespace Mall.Model.Query
public string name { get; set; }
}
/// <summary>
/// 用户下级
/// </summary>
[Serializable]
public class UserSuperiorImport
{
/// <summary>
/// 昵称
/// </summary>
public string nickname { get; set; }
/// <summary>
/// 加入时间
/// </summary>
public string junior_at { get; set; }
}
}
......@@ -111,23 +111,23 @@ namespace Mall.Module.User
{
Id = 0,
ApplicationAgreement = "分销申请协议",
HeadImage = 1,
BottomImage = 2,
HeadImage =Common.Config.GetFileUrl("/Upload/Set/1587968479000.png"),
BottomImage = Common.Config.GetFileUrl("/Upload/Set/1587968716000.png"),
ButtonColor = "#FF4544",
ButtonFilletPX = 40,
ButtonText = "申请成为分销商",
ButtonTextColor = "#FFFFFF",
DistributionApplication = "分销申请",
DistributionCommissionName = "分销佣金",
DistributionCommissionImage = 3,
DistributionCommissionImage = Common.Config.GetFileUrl("/Upload/Set/1587968503000.png"),
DistributionOrderName = "分销订单",
DistributionOrderImage = 4,
DistributionOrderImage = Common.Config.GetFileUrl("/Upload/Set/1587968517000.png"),
WithdrawDetialsName = "提现明细",
WithdrawDetialsImage = 5,
WithdrawDetialsImage = Common.Config.GetFileUrl("/Upload/Set/1587968599000.png"),
MyTeamName = "我的团队",
MyTeamImage = 6,
MyTeamImage = Common.Config.GetFileUrl("/Upload/Set/1587968613000.png"),
PromoteQRCodeName = "推广二维码",
PromoteQRCodeImage = 7,
PromoteQRCodeImage = Common.Config.GetFileUrl("/Upload/Set/1587968626000.png"),
ReferrerName = "推荐人",
CommissionForWithdrawalName = "可提现佣金",
WithdrawDepositName = "提现",
......
......@@ -16,6 +16,8 @@ using Newtonsoft.Json;
using Mall.Repository.BaseSetUp;
using Mall.Common.Enum.User;
using Mall.Common.API;
using Newtonsoft.Json.Linq;
using System.Threading;
namespace Mall.Module.User
{
......@@ -2665,6 +2667,108 @@ namespace Mall.Module.User
#endregion
#region 用户转移
/// <summary>
/// 更新用户微信头像
/// </summary>
/// <param name="userId"></param>
/// <param name="count"></param>
/// <param name="tenantId"></param>
/// <param name="mallBaseId"></param>
/// <returns></returns>
public bool UpdateUserPhotoForWeiXin(int userId, int count, int tenantId, int mallBaseId)
{
var list = member_UserRepository.GetPageList(1, count, out long rcount, new RB_Member_User_Extend() { TenantId = tenantId, MallBaseId = mallBaseId, Id = userId, Source = UserSourceEnum.WeiXin, IsEmptyUserPhoto = 1 });
var appletWeChatModel = miniProgramRepository.GetEntity(mallBaseId);
string token = CacheManager.AppletWeChat.WeiXinReidsCache.Get(appletWeChatModel.MiniAppId);
if (string.IsNullOrEmpty(token))
{
token = Mall.Common.Pay.WeChatPat.TokenHelper.GetLXYToken(token, appletWeChatModel.MiniAppId, appletWeChatModel.MiniAppSecret);
System.Threading.Tasks.Task.Run(() => CacheManager.AppletWeChat.WeiXinReidsCache.Set(appletWeChatModel.MiniAppId, token));
}
foreach (var item in list) {
string photo = Mall.Common.Pay.WeChatPat.TokenHelper.GetWeiXinUserPhoto(token, item.OpenId);
if (!string.IsNullOrEmpty(photo)) {
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Member_User.Photo),photo}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Member_User.Id),
FiledValue=item.Id,
OperatorEnum=OperatorEnum.Equal
}
};
member_UserRepository.Update(keyValues, wheres);
}
}
return true;
}
/// <summary>
/// 更新用户上下级关系
/// </summary>
/// <param name="userId"></param>
/// <param name="count"></param>
/// <param name="tenantId"></param>
/// <param name="mallBaseId"></param>
/// <returns></returns>
public int UpdateUserSuperiorForWeiXin(int userId, int count, int tenantId, int mallBaseId)
{
string cookie = "__login_route=%2Fadmin%2Fpassport%2Flogin; __login_role=admin; search={'keyword':'','status':' - 1','sort_prop':'','sort_type':'','cats'[],'date_start':null,'date_end':null}; HJ_SESSION_ID=kmmormovvm2u9qh5drkgsbj1ta; _csrf=7a980bb65eabe0ac3d77199092030044b17ae9779de00eaed628c8095ab2fe0ca%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22rsnZWVWkZkpfvVhLBXu8sGG3px0Dgcsx%22%3B%7D";
var list = member_UserRepository.GetPageList(1, count, out long rcount, new RB_Member_User_Extend() { TenantId = tenantId, MallBaseId = mallBaseId, MinUserId = userId, Source = UserSourceEnum.WeiXin });
foreach (var item in list)
{
string data = Mall.Common.Pay.WeChatPat.TokenHelper.GetZYUserInfo(item.Id, cookie);
if (!string.IsNullOrEmpty(data))
{
var data1 = Encoding.GetEncoding("GBK").GetBytes(data);
data = Encoding.GetEncoding("GBK").GetString(data1);
var jdata = (JObject)JsonConvert.DeserializeObject(data);
var List = jdata["list"].ToString();
if (List != "" && List != "[]") {
//根据用户名 查询一次用户列表
List<Model.Query.UserSuperiorImport> UserList = JsonConvert.DeserializeObject<List<Model.Query.UserSuperiorImport>>(List);
foreach (var uitem in UserList) {
uitem.nickname = uitem.nickname.Replace("'", "\"");
uitem.nickname = uitem.nickname.Replace("??", "?");
if (uitem.nickname.Length > 20)
{
uitem.nickname = "'" + uitem.nickname[..20] + "'";
}
else {
uitem.nickname = "'" + uitem.nickname.Replace("'", "") + "\t'";
}
}
string UserNameStr = string.Join(",", UserList.Select(x => x.nickname));
var uList = member_UserRepository.GetList(new RB_Member_User_Extend() { UserNameStr = UserNameStr, TenantId = tenantId, MallBaseId = mallBaseId });
foreach (var qitem in uList) {
if (qitem.SuperiorId == 0)
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_Member_User.SuperiorId),item.Id}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Member_User.Id),
FiledValue=qitem.Id,
OperatorEnum=OperatorEnum.Equal
}
};
member_UserRepository.Update(keyValues, wheres);
}
}
}
}
}
return list.Max(x => x.Id);
}
#endregion
#region 数据统计-分销排行
/// <summary>
/// 分页列表
......
......@@ -23,7 +23,7 @@ namespace Mall.Repository.Product
/// <returns></returns>
public List<RB_Material_Info_Extend> GetPageList(int pageIndex, int pageSize, out long rowCount, RB_Material_Info_Extend dmodel)
{
string where = $" 1=1 and Id>100 and {nameof(RB_Material_Info.Status)}=0";
string where = $" 1=1 and {nameof(RB_Material_Info.Status)}=0";
if (dmodel.Id >= 100)
{
if (dmodel.TenantId > 0)
......
......@@ -33,7 +33,7 @@ namespace Mall.Repository.User
}
if (dmodel.Id > 0) {
where += $@" and {nameof(RB_Member_User.Id)}={dmodel.Id}";
}
}
if (!string.IsNullOrEmpty(dmodel.Name)) {
where += $@" and {nameof(RB_Member_User.Name)} like '%{dmodel.Name}%'";
}
......@@ -52,8 +52,18 @@ namespace Mall.Repository.User
if (dmodel.SuperiorId > 0) {
where += $@" and {nameof(RB_Member_User.SuperiorId)}={dmodel.SuperiorId}";
}
if (dmodel.IsEmptyUserPhoto == 1) {
where += $@" and IFNULL({nameof(RB_Member_User.Photo)},'')=''";
}
string orderBy = "CreateDate desc";
if (dmodel.MinUserId > 0)
{
where += $@" and {nameof(RB_Member_User.Id)}>{dmodel.MinUserId}";
orderBy = "Id asc";
}
string sql = $@"
select * from RB_Member_User where {where} order by CreateDate desc
select * from RB_Member_User where {where} order by {orderBy}
";
return GetPage<RB_Member_User_Extend>(pageIndex, pageSize, out rowCount, sql).ToList();
}
......
......@@ -874,11 +874,11 @@ namespace Mall.WebApi.Controllers.User
{
var requestParm = RequestParm;
RB_Distributor_Custom_Extend demodel = JsonConvert.DeserializeObject<RB_Distributor_Custom_Extend>(requestParm.msg.ToString());
if ((demodel.HeadImage ?? 0) <= 0)
if (demodel.HeadImage==null ||string.IsNullOrWhiteSpace(demodel.HeadImage))
{
return ApiResult.ParamIsNull("请传递分销申请下头部图片");
}
if ((demodel.BottomImage ?? 0) <= 0)
if (demodel.BottomImage == null || string.IsNullOrWhiteSpace(demodel.BottomImage))
{
return ApiResult.ParamIsNull("请传递分销申请下底部图片");
}
......@@ -890,10 +890,6 @@ namespace Mall.WebApi.Controllers.User
{
return ApiResult.ParamIsNull("请传递分销申请下分销申请协议");
}
if ((demodel.BottomImage ?? 0) <= 0)
{
return ApiResult.ParamIsNull("请传递分销申请下按钮圆角像素");
}
if (string.IsNullOrEmpty(demodel.ButtonText))
{
return ApiResult.ParamIsNull("请传递分销申请下按钮文本");
......@@ -911,7 +907,7 @@ namespace Mall.WebApi.Controllers.User
{
return ApiResult.ParamIsNull("请传递分销中心下分销佣金");
}
if ((demodel.DistributionCommissionImage ?? 0) <= 0)
if (demodel.DistributionCommissionImage==null || string.IsNullOrWhiteSpace(demodel.DistributionCommissionImage))
{
return ApiResult.ParamIsNull("请传递分销中心下分销佣金图片");
}
......@@ -919,7 +915,7 @@ namespace Mall.WebApi.Controllers.User
{
return ApiResult.ParamIsNull("请传递分销中心下分销订单");
}
if ((demodel.DistributionOrderImage ?? 0) <= 0)
if (demodel.DistributionOrderImage==null ||string.IsNullOrWhiteSpace(demodel.DistributionOrderImage))
{
return ApiResult.ParamIsNull("请传递分销中心下分销订单图片");
}
......@@ -927,7 +923,7 @@ namespace Mall.WebApi.Controllers.User
{
return ApiResult.ParamIsNull("请传递分销中心下提现明细");
}
if ((demodel.WithdrawDetialsImage ?? 0) <= 0)
if (demodel.WithdrawDetialsImage==null || string.IsNullOrWhiteSpace(demodel.WithdrawDetialsImage))
{
return ApiResult.ParamIsNull("请传递分销中心下提现明细图片");
}
......@@ -935,7 +931,7 @@ namespace Mall.WebApi.Controllers.User
{
return ApiResult.ParamIsNull("请传递分销中心下我的团队");
}
if ((demodel.MyTeamImage ?? 0) <= 0)
if (demodel.MyTeamImage==null ||string.IsNullOrWhiteSpace(demodel.MyTeamImage))
{
return ApiResult.ParamIsNull("请传递分销中心下我的团队图片");
}
......@@ -943,7 +939,7 @@ namespace Mall.WebApi.Controllers.User
{
return ApiResult.ParamIsNull("请传递分销中心下推广二维码");
}
if ((demodel.PromoteQRCodeImage ?? 0) <= 0)
if (demodel.PromoteQRCodeImage==null ||string.IsNullOrWhiteSpace(demodel.PromoteQRCodeImage))
{
return ApiResult.ParamIsNull("请传递分销中心下推广二维码图片");
}
......@@ -2130,5 +2126,63 @@ namespace Mall.WebApi.Controllers.User
}
#endregion
#region 用户转移
/// <summary>
/// 更新微信用户头像
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult UpdateUserPhotoForWeiXin() {
var req = RequestParm;
JObject parms = JObject.Parse(req.msg.ToString());
int Count = parms.GetInt("Count", 1);
int UserId = parms.GetInt("UserId", 0);
if (Count == 0) { Count = 1; }
if (UserId <= 0 && Count == 0) {
return ApiResult.ParamIsNull();
}
bool flag = userModule.UpdateUserPhotoForWeiXin(UserId, Count, req.TenantId, req.MallBaseId);
if (flag)
{
return ApiResult.Success();
}
else {
return ApiResult.Failed();
}
}
/// <summary>
/// 更新用户上下级关系
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult UpdateUserSuperiorForWeiXin()
{
var req = RequestParm;
JObject parms = JObject.Parse(req.msg.ToString());
int Count = parms.GetInt("Count", 1);
int UserId = parms.GetInt("UserId", 0);
if (Count == 0) { Count = 1; }
if (UserId <= 0 && Count == 0)
{
return ApiResult.ParamIsNull();
}
int MaxId = userModule.UpdateUserSuperiorForWeiXin(UserId, Count, req.TenantId, req.MallBaseId);
if (MaxId > 0)
{
return ApiResult.Success("", MaxId);
}
else
{
return ApiResult.Failed();
}
}
#endregion
}
}
\ No newline at end of file
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