Commit 77d2c9fe authored by 黄奎's avatar 黄奎

代码优化

parent 5d86f031
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace Mall.Common.Plugin
{
/// <summary>
/// 微信帮助类
/// </summary>
public class WeiXinHelper
{
static List<WeChatMiniAppMessage> weChatMiniAppMessages = new List<WeChatMiniAppMessage>();
static readonly List<WeChatMiniAppMessage> weChatMiniAppMessages = new List<WeChatMiniAppMessage>();
static WeiXinHelper()
{
......@@ -206,10 +207,8 @@ namespace Mall.Common.Plugin
System.Net.WebResponse wResp = wReq.GetResponse();
System.IO.Stream respStream = wResp.GetResponseStream();
// Dim reader As StreamReader = New StreamReader(respStream)
using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding(type)))
{
return reader.ReadToEnd();
}
using System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding(type));
return reader.ReadToEnd();
}
catch (System.Exception ex)
{
......@@ -315,7 +314,7 @@ namespace Mall.Common.Plugin
}
//采用排序的Dictionary的好处是方便对数据包进行签名,不用再签名之前再做一次排序
private SortedDictionary<string, object> m_values = new SortedDictionary<string, object>();
private readonly SortedDictionary<string, object> m_values = new SortedDictionary<string, object>();
/**
* 设置某个字段的值
......@@ -334,8 +333,7 @@ namespace Mall.Common.Plugin
*/
public object GetValue(string key)
{
object o = null;
m_values.TryGetValue(key, out o);
m_values.TryGetValue(key, out object o);
return o;
}
......@@ -346,8 +344,7 @@ namespace Mall.Common.Plugin
*/
public bool IsSet(string key)
{
object o = null;
m_values.TryGetValue(key, out o);
m_values.TryGetValue(key, out object o);
if (null != o)
return true;
else
......
......@@ -1341,8 +1341,7 @@ namespace Mall.Module.Product
string QRPath = GetWeiXinQRCode(path, 430, mallBaseId);
var umodel = member_UserRepository.GetEntity(userId);
var goodsModel = goodsRepository.GetEntity(goodsId);
//商品海报配置信息
var config = new object();
//商品信息
var info = new object();
var goodsPoster = miniProgram_GoodPosterRepository.GetEntityExtRepository(new RB_MiniProgram_GoodPoster_Extend()
......@@ -1350,7 +1349,8 @@ namespace Mall.Module.Product
MallBaseId = mallBaseId,
IsOpenSchool = IsOpenSchool
});
config = new
//商品海报配置信息
var config = new
{
poster_style = goodsPoster?.PosterStyleList ?? new List<int>() { 1 },
image_style = goodsPoster?.GoodsImgCountList ?? new List<int>() { 1 },
......@@ -8907,7 +8907,7 @@ namespace Mall.Module.Product
/// <returns></returns>
public bool CancelGoodsProxy(int goodsId, int type, int tenantId, int mallBaseId)
{
var plist = new List<RB_Goods_Proxy_Extend>();
List<RB_Goods_Proxy_Extend> plist;
if (type == 1)
{
plist = goods_ProxyRepository.GetList(new RB_Goods_Proxy_Extend() { GoodsId = goodsId, ProxyMallBaseId = mallBaseId, ProxyTenantId = tenantId });
......@@ -8921,30 +8921,36 @@ namespace Mall.Module.Product
return false;
}
var pModel = plist.FirstOrDefault();
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
Dictionary<string, object> keyValues = new Dictionary<string, object>()
{
{ nameof(RB_Goods_Proxy.Status),1},
{ nameof(RB_Goods_Proxy.Remark),DateTime.Now.ToString("yyyy-MM-dd")+ " 取消代理"}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
List<WhereHelper> wheres = new List<WhereHelper>()
{
new WhereHelper()
{
FiledName=nameof(RB_Goods_Proxy.Id),
FiledValue=pModel.Id,
OperatorEnum=OperatorEnum.Equal
FiledValue=pModel.Id,
OperatorEnum=OperatorEnum.Equal
}
};
bool flag = goods_ProxyRepository.Update(keyValues, wheres);
if (flag)
{
//删除商品
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
Dictionary<string, object> keyValues1 = new Dictionary<string, object>()
{
{ nameof(RB_Goods.Status),1},
{ nameof(RB_Goods.UpdateDate),DateTime.Now}
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
new WhereHelper(){
List<WhereHelper> wheres1 = new List<WhereHelper>()
{
new WhereHelper()
{
FiledName=nameof(RB_Goods.Id),
FiledValue=pModel.ProxyGoodsId,
OperatorEnum=OperatorEnum.Equal
FiledValue=pModel.ProxyGoodsId,
OperatorEnum=OperatorEnum.Equal
}
};
goodsRepository.Update(keyValues1, wheres1);
......
......@@ -355,7 +355,7 @@ namespace Mall.Module.TradePavilion
/// <returns></returns>
public bool SetTradeConsultModule(RB_Commerce_Consult_Extend model)
{
bool flag = false;
bool flag;
if (model.Id > 0)
{
Dictionary<string, object> fileds = new Dictionary<string, object>()
......
......@@ -429,7 +429,7 @@ namespace Mall.Module.TradePavilion
/// <returns></returns>
public int SetCompanyModule(RB_Company_Extend model)
{
int ID = 0;
int ID;
if (model.CompanyId > 0)
{
ID = model.CompanyId;
......
......@@ -4123,7 +4123,7 @@ namespace Mall.Module.User
RList.Add(new
{
Sort = i,
MySelf = member.Id == userId2 ? true : false,
MySelf = member.Id == userId2,
UserInfo = new
{
member.Name,
......@@ -4256,7 +4256,7 @@ namespace Mall.Module.User
CreateDate = item.CreateDate.HasValue ? item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
GeneralizeNum = tgNum,
OrderNum = item.RealOrderNum,
Income = item.Income,
item.Income,
});
}
}
......@@ -5472,7 +5472,7 @@ namespace Mall.Module.User
Msg = "未配置和平返佣"
};
}
List<RB_Distributor_HPCommission_Extend> hpcList = new List<RB_Distributor_HPCommission_Extend>();
List<RB_Distributor_HPCommission_Extend> hpcList;
if (string.IsNullOrEmpty(categoryIds))
{
hpcList = distributor_HPCommissionRepository.GetList(new RB_Distributor_HPCommission_Extend() { Enabled = 1, IsCommon = 1, TenantId = tenantId, MallBaseId = mallBaseId });
......
......@@ -733,10 +733,10 @@ namespace Mall.WebApi.Controllers.MallBase
/// <returns></returns>
[HttpGet]
[HttpPost]
[AllowAnonymous] [RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
[AllowAnonymous]
[RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
public ApiResult GetMessageTemplate()
{
JObject parms = JObject.Parse(RequestParm.msg.ToString());
var result = new object();
if (RequestParm.MiniAppId != null && !string.IsNullOrWhiteSpace(RequestParm.MiniAppId))
{
......
......@@ -393,12 +393,12 @@ namespace Mall.WebApi.Controllers.TradePavilion
{
query.FirstShopNum = "";
}
query.ShopNum = query.ShopNum ?? 0;
query.BuiltUpArea = query.BuiltUpArea ?? 0;
query.EndBuiltUpArea = query.EndBuiltUpArea ?? 0;
query.AreaRequirement = query.AreaRequirement ?? 0;
query.EndAreaRequirement = query.EndAreaRequirement ?? 0;
query.YeJi = query.YeJi ?? 0;
query.ShopNum ??= 0;
query.BuiltUpArea ??= 0;
query.EndBuiltUpArea ??= 0;
query.AreaRequirement ??= 0;
query.EndAreaRequirement ??= 0;
query.YeJi ??= 0;
query.CreateDate = DateTime.Now;
query.MallBaseId = userInfo.MallBaseId;
query.TenantId = userInfo.TenantId;
......@@ -551,12 +551,12 @@ namespace Mall.WebApi.Controllers.TradePavilion
query.MallBaseId = userInfo.MallBaseId;
query.TenantId = userInfo.TenantId;
query.UpdateDate = DateTime.Now;
query.ShopNum = query.ShopNum ?? 0;
query.BuiltUpArea = query.BuiltUpArea ?? 0;
query.EndBuiltUpArea = query.EndBuiltUpArea ?? 0;
query.AreaRequirement = query.AreaRequirement ?? 0;
query.EndAreaRequirement = query.EndAreaRequirement ?? 0;
query.YeJi = query.YeJi ?? 0;
query.ShopNum ??= 0;
query.BuiltUpArea ??= 0;
query.EndBuiltUpArea ??= 0;
query.AreaRequirement ??= 0;
query.EndAreaRequirement ??= 0;
query.YeJi ??= 0;
var oldModel = carrierModule.GetCarrierModel(new RB_Carrier_Extend() { ID = query.ID });
if (oldModel == null) { return ApiResult.Failed("载体不存在"); }
if (oldModel.UserId != userInfo.UserId) { return ApiResult.Failed("无法修改此载体"); }
......
......@@ -793,17 +793,19 @@ namespace Mall.WebApi.Controllers.TradePavilion
{
foreach (var sItem in item.SignUserList)
{
var excelColumns = new List<ExcelColumn>(30);
excelColumns.Add(new ExcelColumn(value: item.UserName) );
excelColumns.Add(new ExcelColumn(value: item.CompanyStatusStr) );
excelColumns.Add(new ExcelColumn(value: item.CompanyName) );
excelColumns.Add(new ExcelColumn(value: item.AuthName) );
excelColumns.Add(new ExcelColumn(value: sItem.CompanyName));
excelColumns.Add(new ExcelColumn(value: sItem.Nature));
excelColumns.Add(new ExcelColumn(value: sItem.LinkMan));
excelColumns.Add(new ExcelColumn(value: sItem.LinkTel));
excelColumns.Add(new ExcelColumn(value: sItem.Post));
excelColumns.Add(new ExcelColumn(value: sItem.CountryInfo));
var excelColumns = new List<ExcelColumn>(30)
{
new ExcelColumn(value: item.UserName),
new ExcelColumn(value: item.CompanyStatusStr),
new ExcelColumn(value: item.CompanyName),
new ExcelColumn(value: item.AuthName),
new ExcelColumn(value: sItem.CompanyName),
new ExcelColumn(value: sItem.Nature),
new ExcelColumn(value: sItem.LinkMan),
new ExcelColumn(value: sItem.LinkTel),
new ExcelColumn(value: sItem.Post),
new ExcelColumn(value: sItem.CountryInfo)
};
ExcelDataSource datarow = new ExcelDataSource()
{
......@@ -1583,12 +1585,12 @@ namespace Mall.WebApi.Controllers.TradePavilion
else {
query.FirstStoreTest = 0;
}
query.ShopNum = query.ShopNum ?? 0;
query.BuiltUpArea = query.BuiltUpArea ?? 0;
query.EndBuiltUpArea = query.EndBuiltUpArea ?? 0;
query.AreaRequirement = query.AreaRequirement ?? 0;
query.EndAreaRequirement = query.EndAreaRequirement ?? 0;
query.YeJi = query.YeJi ?? 0;
query.ShopNum ??= 0;
query.BuiltUpArea ??= 0;
query.EndBuiltUpArea ??= 0;
query.AreaRequirement ??= 0;
query.EndAreaRequirement ??= 0;
query.YeJi ??= 0;
query.UpdateDate = System.DateTime.Now;
bool flag = carrierModule.SetCarrier(query);
return flag ? ApiResult.Success() : ApiResult.Failed();
......
......@@ -154,7 +154,6 @@ namespace Mall.WebApi.Controllers.User
[HttpPost]
public ApiResult DelDiscountCoupon()
{
var parms = RequestParm;
JObject parmsJob = JObject.Parse(RequestParm.msg.ToString());
int Id = parmsJob.GetInt("Id", 0);
int BackId = parmsJob.GetInt("BackId", 0);
......@@ -222,7 +221,7 @@ namespace Mall.WebApi.Controllers.User
var now = new
{
ID = item.TenantId,
Name = item.Name
item.Name
};
result.Add(now);
}
......@@ -310,13 +309,15 @@ namespace Mall.WebApi.Controllers.User
demodel.IsFinance = 2;
var list = orderModule.GetSupplierOrderList(demodel);
var result = new List<RB_Goods_OrderDetail_Extend>();
RB_Finance_Record_Extend record = new RB_Finance_Record_Extend();
record.MallBaseId = demodel.MallBaseId;
record.TenantId = demodel.TenantId;
record.Type = 2;
record.IsFinanceAll = demodel.IsSelectAll;
record.CreateDate = System.DateTime.Now;
record.RecordDetailList = new List<RB_Finance_RecordDetail_Extend>();
RB_Finance_Record_Extend record = new RB_Finance_Record_Extend
{
MallBaseId = demodel.MallBaseId,
TenantId = demodel.TenantId,
Type = 2,
IsFinanceAll = demodel.IsSelectAll,
CreateDate = System.DateTime.Now,
RecordDetailList = new List<RB_Finance_RecordDetail_Extend>()
};
if (list != null && list.Any())
{
......@@ -495,10 +496,10 @@ namespace Mall.WebApi.Controllers.User
var financeObj = new
{
CreateBy = demodel.FinanceCreateBy == 0 ? Config.ExpendDirector : demodel.FinanceCreateBy.ToString(),
IsPublic = demodel.IsPublic,
demodel.IsPublic,
ClientType = supplierModel.ClientBankAccount.Type,
ClientID = supplierModel.BankAccountId,
CurrencyId = financeConfigurineModel.CurrencyId,
financeConfigurineModel.CurrencyId,
WBMoney = totalMonry,
RB_Branch_Id = Config.ExpendBranchId,
PayDate = System.DateTime.Now.ToString("yyyy-MM-dd"),
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Mall.Common.API;
using Mall.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
......@@ -9,10 +8,7 @@ using Microsoft.AspNetCore.Mvc;
using Mall.Model.Extend.User;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using JWT;
using Mall.Common;
using JWT.Algorithms;
using JWT.Serializers;
using Mall.Common.Enum;
using Mall.CacheManager.User;
using Mall.CacheKey;
......@@ -23,9 +19,9 @@ using Mall.Module.Product;
using Microsoft.AspNetCore.Authorization;
using Mall.Model.Query;
using Mall.Model.Extend.AppletWeChat;
using Mall.AOP;
using Mall.Module.User;
using Dnc.Api.Throttle;
using Mall.WebApi.Helper;
namespace Mall.WebApi.Controllers.User
{
......@@ -86,7 +82,8 @@ namespace Mall.WebApi.Controllers.User
private readonly Module.Property.AuthorizeModule authorizeModule = new Module.Property.AuthorizeModule();
#region 商户信息
[AllowAnonymous] [RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
[AllowAnonymous]
[RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
/// <summary>
/// 用户登录
/// </summary>
......@@ -136,7 +133,7 @@ namespace Mall.WebApi.Controllers.User
}
catch
{
}
}
#region add by:W 2020-07-06 erp授权信息
......@@ -158,47 +155,14 @@ namespace Mall.WebApi.Controllers.User
if (erpUserInfo != null && !string.IsNullOrWhiteSpace(erpUserInfo.EmLoginMobile) && erpUserInfo.IsLeave == 0)
{
TokenUserInfo erpUserInfoToken = new TokenUserInfo { uid = erpUserInfo.EmployeeId.ToString(), requestFrom = Common.Enum.ApiRequestFromEnum.ERP };
#region JWT
IDateTimeProvider erpprovider = new UtcDateTimeProvider();
var erpnow = erpprovider.GetNow().AddMinutes(-1);
var erpunixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); // or use JwtValidator.UnixEpoch
var erpsecondsSinceEpoch = Math.Round((erpnow - erpunixEpoch).TotalSeconds);
var erppayload = new Dictionary<string, object>
{
{"iat",erpsecondsSinceEpoch },
{"exp",erpsecondsSinceEpoch+Config.JwtExpirTime},
{"userInfo",erpUserInfoToken }
};
IJwtAlgorithm erpalgorithm = new HMACSHA256Algorithm();
IJsonSerializer erpserializer = new JsonNetSerializer();
IBase64UrlEncoder erpurlEncoder = new JwtBase64UrlEncoder();
IJwtEncoder erpencoder = new JwtEncoder(erpalgorithm, erpserializer, erpurlEncoder);
string erpsecret = Config.JwtSecretKey;
erptoken = erpencoder.Encode(erppayload, erpsecret);
#endregion
erptoken = ApiTokenHelper.CreateToken(erpUserInfoToken);
}
}
}
#endregion
TokenUserInfo userInfo = new TokenUserInfo { uid = model.TenantId.ToString(), requestFrom = ApiRequestFromEnum.Web };
#region JWT
IDateTimeProvider provider = new UtcDateTimeProvider();
var now = provider.GetNow().AddMinutes(-1);
var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); // or use JwtValidator.UnixEpoch
var secondsSinceEpoch = Math.Round((now - unixEpoch).TotalSeconds);
var payload = new Dictionary<string, object>
{
{"iat",secondsSinceEpoch },
{"exp",secondsSinceEpoch+Config.JwtExpirTime},
{"mall_userInfo",userInfo }
};
IJwtAlgorithm algorithm = new HMACSHA256Algorithm();
IJsonSerializer serializer = new JsonNetSerializer();
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder);
string secret = Config.JwtSecretKey;
string token = encoder.Encode(payload, secret);
#region 生成Token
string token = ApiTokenHelper.CreateToken(userInfo);
#endregion
UserInfo obj = new UserInfo
{
......@@ -232,7 +196,8 @@ namespace Mall.WebApi.Controllers.User
/// 用户注册第一步
/// </summary>
/// <returns></returns>
[AllowAnonymous] [RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
[AllowAnonymous]
[RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
public ApiResult SetTenantFirst()
{
var extModel = JsonConvert.DeserializeObject<RB_Tenant_Extend>(RequestParm.msg.ToString());
......@@ -252,7 +217,8 @@ namespace Mall.WebApi.Controllers.User
/// 用户注册第二步
/// </summary>
/// <returns></returns>
[AllowAnonymous] [RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
[AllowAnonymous]
[RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
public ApiResult SetTenantSecond()
{
var extModel = JsonConvert.DeserializeObject<RB_Tenant_Extend>(RequestParm.msg.ToString());
......@@ -285,7 +251,8 @@ namespace Mall.WebApi.Controllers.User
/// 修改密码账号
/// </summary>
/// <returns></returns>
[AllowAnonymous] [RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
[AllowAnonymous]
[RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
public ApiResult UpdateTenantPwd()
{
var extModel = JsonConvert.DeserializeObject<RB_Tenant_Extend>(RequestParm.msg.ToString());
......@@ -1830,7 +1797,7 @@ namespace Mall.WebApi.Controllers.User
var extModel = new RB_PlugIn_Extend()
{
TenantId = RequestParm.TenantId,
QPlugTypeStr= parms.GetStringValue("QPlugTypeStr"),
QPlugTypeStr = parms.GetStringValue("QPlugTypeStr"),
};
var list = plugInModule.GetPlugInListModule(extModel);
var distinctList = list.GroupBy(qitem => new { qitem.PlugType, qitem.GroupName }).Select(qitem => new { qitem.Key.PlugType, qitem.Key.GroupName });
......@@ -1995,7 +1962,6 @@ namespace Mall.WebApi.Controllers.User
}
#endregion
#region 商城首页统计
/// <summary>
......
......@@ -54,11 +54,10 @@ namespace Mall.WebApi.Filter
});
Common.Plugin.LogHelper.Write("OnActionExecuting:" + ip);
}
//请求参数
JObject parm = new JObject();
string token = "";
#region api监控日志
parm = DoApiMonitorLog(actionContext, ref token);
JObject parm = DoApiMonitorLog(actionContext, ref token);
#endregion
bool isCheckToken = true;
var endpoint = actionContext.HttpContext.Features.Get<IEndpointFeature>()?.Endpoint;
......@@ -278,7 +277,7 @@ namespace Mall.WebApi.Filter
data = null
});
}
catch (Exception ex)
catch
{
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(
HttpStatusCode.OK,
......
using JWT;
using JWT.Serializers;
using Mall.Common.API;
using Mall.Common.Plugin;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Mall.WebApi.Helper
{
/// <summary>
/// Token帮助类
/// </summary>
public class TokenHelper
{
/// <summary>
/// 生成Token
/// </summary>
/// <returns></returns>
public static string CreateToken()
{
return "";
}
/// <summary>
/// 解析Token
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
public static TokenUserInfo ParsingToken(string token)
{
TokenUserInfo tokenUser = new TokenUserInfo();
if (string.IsNullOrEmpty(token))
{
IJsonSerializer serializer = new JsonNetSerializer();
IDateTimeProvider provider = new UtcDateTimeProvider();
IJwtValidator validator = new JwtValidator(serializer, provider);
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder);
string secret = Common.Config.JwtSecretKey;
var json = decoder.Decode(token, secret, verify: true);//token为之前生成的字符串
if (!string.IsNullOrEmpty(json))
{
JObject jwtJson = JObject.Parse(json);
var mall_userInfo = JObject.Parse(jwtJson.GetStringValue("mall_userInfo"));
tokenUser.requestFrom = (Common.Enum.ApiRequestFromEnum)mall_userInfo.GetInt("requestFrom");
tokenUser.uid = mall_userInfo.GetStringValue("uid");
}
}
return tokenUser;
}
}
}
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