Commit 0539f41e authored by 吴春's avatar 吴春
parents 76f7c688 f684281f
......@@ -1066,7 +1066,7 @@ namespace Mall.Module.Product
}
}
#endregion
List<RB_Goods_CouponModel> GoodsCouponList = new List<RB_Goods_CouponModel>();
List<RB_Goods_CouponModel> GoodsCouponList = new List<RB_Goods_CouponModel>();//商品优惠卷 价格(每个商品优惠的价格)
//初始化值
foreach (var item in demodel.DetailList)
{
......@@ -1593,6 +1593,7 @@ namespace Mall.Module.Product
}
}
#region 其他封装
List<object> mch_list = new List<object>();
var minModel = miniProgramRepository.GetEntity(demodel.MallBaseId);
......@@ -1661,6 +1662,7 @@ namespace Mall.Module.Product
//hasCity= false,
template_message_list= new List<string>() { "WPELErDfYO3JnizA5Zikta6Y8qrBBAgecuj2aLoucuY", "pCmTJwvTqNpyRREo7vvqIYBcrATNWoitfbLS61fLhzU", "i6QPsaOHgfNwlIRMwmvFGSCqX28g0cRa8XaLZ5_gpgc" }
};
#endregion
return ApiResult.Success("", Robj);
}
......@@ -1894,8 +1896,49 @@ namespace Mall.Module.Product
decimal TotalExpress = 0;
decimal TotalMoney = 0;
string GoodsIds = "";
List<RB_Goods_CouponModel> GoodsCouponList = new List<RB_Goods_CouponModel>();//商品优惠卷 价格(每个商品优惠的价格)
decimal CouponsMoney = 0;//优惠卷验证
#region 优惠卷初始化
List<RB_Member_DiscountCoupon_Extend> cList = new List<RB_Member_DiscountCoupon_Extend>();
List<Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend> dcList = new List<Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend>();
List<Model.Extend.MarketingCenter.RB_DiscountCoupon_Product_Extend> dcpList = new List<Model.Extend.MarketingCenter.RB_DiscountCoupon_Product_Extend>();
demodel.CouponsIds = "";
if (demodel.User_Coupon_Id > 0)
{
demodel.CouponsIds = demodel.User_Coupon_Id.ToString();
if (!string.IsNullOrEmpty(demodel.CouponsIds))
{
cList = member_CouponRepository.GetList(new RB_Member_DiscountCoupon_Extend() { UseState = 0, Ids = demodel.CouponsIds, UserId = umodel.Id, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
if (cList.Any())
{
string cIds = string.Join(",", cList.Select(x => x.CouponId).Distinct());
dcList = discountCouponRepository.GetDiscountCouponList(new Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend() { CouponIds = cIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
dcpList = discountCoupon_ProductRepository.GetListByDiscountCouponIds(new Model.Entity.MarketingCenter.RB_DiscountCoupon() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }, cIds);
if (dcList.Any())
{
foreach (var item in cList)
{
if (item.CouponId > 0)
{
if (!dcList.Where(x => x.ID == item.CouponId).Any())
{
return ApiResult.Failed("优惠券不存在,请核实后再试");
}
}
}
}
}
}
}
#endregion
if (demodel.DetailList.Any())
{
//积分
Model.Entity.MarketingCenter.RB_Integral_Settings integralModel = new Model.Entity.MarketingCenter.RB_Integral_Settings();
if (demodel.Use_Integral == 1 && umodel.Integral > 0)
{
integralModel = integral_SettingsRepository.GetIntegralSettingsList(new Model.Entity.MarketingCenter.RB_Integral_Settings() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }).FirstOrDefault();
}
int DefFreightId = 0;//默认运费id
GoodsIds = string.Join(",", demodel.DetailList.Select(x => x.GoodsId));
var gList = goodsRepository.GetList(new RB_Goods_Extend() { GoodsIds = GoodsIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
......@@ -1906,7 +1949,7 @@ namespace Mall.Module.Product
List<Model.Extend.BaseSetUp.RB_Logistics_Rules_Extend> rulesList = new List<Model.Extend.BaseSetUp.RB_Logistics_Rules_Extend>();
List<Model.Extend.BaseSetUp.RB_Logistics_RulesPrice_Extend> priceList = new List<Model.Extend.BaseSetUp.RB_Logistics_RulesPrice_Extend>();
List<Model.Extend.BaseSetUp.RB_Logistics_RulesRegion_Extend> regionList = new List<Model.Extend.BaseSetUp.RB_Logistics_RulesRegion_Extend>();
if (gList.Any() && demodel.DeliveryMethod != OrderDeliveryMethodEnum.VerificationShop)
if (gList.Any() && demodel.DeliveryMethod == OrderDeliveryMethodEnum.ExpressDistribution)
{
List<int> FreightIdList = new List<int>();
if (gList.Where(x => x.FreightId > 0).Any())
......@@ -1932,6 +1975,7 @@ namespace Mall.Module.Product
}
}
foreach (var item in demodel.DetailList)
{
var gmodel = gList.Where(x => x.Id == item.GoodsId).FirstOrDefault();
......@@ -1939,6 +1983,7 @@ namespace Mall.Module.Product
{
return ApiResult.Failed("有商品不存在或者商品已失效");
}
var categoryList = clist.Where(x => x.GoodsId == item.GoodsId).ToList();
item.InventoryNum = gmodel.InventoryNum ?? 0;
item.CostMoney = gmodel.CostPrice ?? 0;
item.ProductCode = gmodel.GoodsNumbers;
......@@ -1986,7 +2031,7 @@ namespace Mall.Module.Product
}
}
#endregion
//会员价格
#region 会员价格
gmodel.MemberPrice = gmodel.SellingPrice ?? 0;
if (umodel.MemberGrade > 0)
{
......@@ -2003,9 +2048,10 @@ namespace Mall.Module.Product
item.DiscountRate = gradeModel?.Discount ?? 10;
}
}
//运费
#endregion
#region 运费
decimal Express = 0;
if (demodel.DeliveryMethod != OrderDeliveryMethodEnum.VerificationShop)
if (demodel.DeliveryMethod == OrderDeliveryMethodEnum.ExpressDistribution)
{
int FreightId2 = gmodel.FreightId ?? 0;
if (gmodel.FreightId == 0)
......@@ -2086,114 +2132,251 @@ namespace Mall.Module.Product
}
}
TotalExpress += Express;
#endregion
item.FreightMoney = Express;
item.Unit_Price = gmodel.SellingPrice ?? 0;
item.Original_Price = (item.Unit_Price) * (item.Number);
if (umodel.MemberGrade > 0)
{
TotalMoney += gmodel.MemberPrice * (item.Number ?? 0);
item.Final_Price= gmodel.MemberPrice * (item.Number ?? 0);
}
else {
TotalMoney += (gmodel.SellingPrice ?? 0) * (item.Number ?? 0);
item.Final_Price = (gmodel.SellingPrice ?? 0) * (item.Number ?? 0);
item.Final_Price = gmodel.MemberPrice * (item.Number ?? 0);
}
item.OrderType = gmodel.GoodsType;
item.GoodsName = gmodel.Name;
item.CoverImage = "";
if (!string.IsNullOrEmpty(gmodel.CarouselImage) && gmodel.CarouselImage != "[]")
else
{
List<string> CarouselIdList = JsonConvert.DeserializeObject<List<string>>(gmodel.CarouselImage);
//封面图
item.CoverImage = CarouselIdList[0];
item.Final_Price = (gmodel.SellingPrice ?? 0) * (item.Number ?? 0);
}
item.SeparateDistribution = gmodel.SeparateDistribution;
item.SeparateDistributionType = gmodel.SeparateDistributionType;
item.SeparateDistributionMoneyType = gmodel.SeparateDistributionMoneyType;
item.IntegralPresent = gmodel.IntegralPresent;
item.IntegralPresentType = gmodel.IntegralPresentType;
}
}
if (demodel.FreightMoney != TotalExpress) {
return ApiResult.Failed("运费不正确");
}
//优惠卷验证
decimal CouponsMoney = 0;
List<RB_Member_DiscountCoupon_Extend> cList = new List<RB_Member_DiscountCoupon_Extend>();
if (!string.IsNullOrEmpty(demodel.CouponsIds))
{
cList = member_CouponRepository.GetList(new RB_Member_DiscountCoupon_Extend() { UseState = 0, CouponIds = demodel.CouponsIds, UserId = umodel.Id, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
string[] arr = demodel.CouponsIds.Split(",");
foreach (var item in arr)
{
if (!string.IsNullOrEmpty(item))
#region 积分
if (umodel.Integral > 0 && gmodel.PointsDeduction > 0 && integralModel.IntegralNum > 0)
{
if (!cList.Where(x => x.CouponId == Convert.ToInt32(item)).Any())
decimal SingleMaxMoney = 0, MultMaxMoney = 0;
if (gmodel.PointsDeductionType == 1)
{
return ApiResult.Failed("优惠券不存在,请核实后再试");
SingleMaxMoney = Math.Round(gmodel.MemberPrice * (gmodel.PointsDeduction ?? 0) / 100, 2, MidpointRounding.AwayFromZero);
MultMaxMoney = Math.Round(gmodel.MemberPrice * (item.Number ?? 0) * (gmodel.PointsDeduction ?? 0) / 100, 2, MidpointRounding.AwayFromZero);
}
}
}
if (cList.Any())
{
var dcList = discountCouponRepository.GetDiscountCouponList(new Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend() { CouponIds = demodel.CouponsIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
var dcpList = discountCoupon_ProductRepository.GetListByDiscountCouponIds(new Model.Entity.MarketingCenter.RB_DiscountCoupon() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId }, demodel.CouponsIds);
foreach (var item in arr) {
if (!string.IsNullOrEmpty(item))
if (gmodel.IsMultipleDeduction == 1)
{
var dcModel = dcList.Where(x => x.ID == Convert.ToInt32(item)).FirstOrDefault();
if (dcModel == null) {
return ApiResult.Failed("优惠卷不存在,亲核实后再试");
//可以多件商品可累计抵扣
if (gmodel.PointsDeductionType == 1)
{
int MaxInterral = Convert.ToInt32(MultMaxMoney * integralModel.IntegralNum);
//最多可抵扣积分
if (umodel.Integral > MaxInterral)
{
item.IntegralNumber = MaxInterral;
item.IntegralMoney = Math.Round(Convert.ToDecimal(MaxInterral) / integralModel.IntegralNum, 2, MidpointRounding.AwayFromZero);
umodel.Integral -= MaxInterral;
}
else
{
item.IntegralNumber = umodel.Integral;
item.IntegralMoney = Math.Round(Convert.ToDecimal(umodel.Integral ?? 0) / integralModel.IntegralNum, 2, MidpointRounding.AwayFromZero);
umodel.Integral = 0;
}
}
dcModel.DiscountsPrice = dcModel.DiscountsPrice == 0 ? 10 : dcModel.DiscountsPrice;
decimal FinalMoney = 0;
if (dcModel.UseType == Common.Enum.MarketingCenter.UseTypeEnum.Category) //指定分类
else
{
var categoryList = dcpList.Where(x => x.DiscountCouponId == Convert.ToInt32(item) && x.DiscountCouponType == Common.Enum.MarketingCenter.UseTypeEnum.Category).Select(x=>x.ProductId).ToList();//获取特殊优惠卷
foreach (var qitem in demodel.DetailList) {
if (qitem.CategoryIdList.Where(x => categoryList.Contains(x)).Any()) {
FinalMoney += qitem.Final_Price ?? 0;
}
int MaxInterral = Convert.ToInt32((gmodel.PointsDeduction ?? 0) * integralModel.IntegralNum * (item.Number ?? 0));
//最多可抵扣积分
if (umodel.Integral > MaxInterral)
{
item.IntegralNumber = MaxInterral;
item.IntegralMoney = Math.Round(Convert.ToDecimal(MaxInterral) / integralModel.IntegralNum, 2, MidpointRounding.AwayFromZero);
umodel.Integral -= MaxInterral;
}
if (FinalMoney <= 0) {
return ApiResult.Failed("Id"+ item+"的优惠券,未匹配到适用类型的商品");
else
{
item.IntegralNumber = umodel.Integral;
item.IntegralMoney = Math.Round(Convert.ToDecimal(umodel.Integral ?? 0) / integralModel.IntegralNum, 2, MidpointRounding.AwayFromZero);
umodel.Integral = 0;
}
}
else if (dcModel.UseType == Common.Enum.MarketingCenter.UseTypeEnum.Product)//指定商品
}
else
{
//单件商品
if (gmodel.PointsDeductionType == 1)
{
var goodsList = dcpList.Where(x => x.DiscountCouponId == Convert.ToInt32(item) && x.DiscountCouponType == Common.Enum.MarketingCenter.UseTypeEnum.Product).Select(x => x.ProductId).ToList();//获取特殊优惠卷
if (!demodel.DetailList.Where(x => goodsList.Contains(x.GoodsId ?? 0)).Any()) {
return ApiResult.Failed("Id" + item + "的优惠券,未匹配到适用的商品");
int MaxInterral = Convert.ToInt32(SingleMaxMoney * integralModel.IntegralNum);
//最多可抵扣积分
if (umodel.Integral > MaxInterral)
{
item.IntegralNumber = MaxInterral;
item.IntegralMoney = Math.Round(Convert.ToDecimal(MaxInterral) / integralModel.IntegralNum, 2, MidpointRounding.AwayFromZero);
umodel.Integral -= MaxInterral;
}
else
{
item.IntegralNumber = umodel.Integral;
item.IntegralMoney = Math.Round(Convert.ToDecimal(umodel.Integral ?? 0) / integralModel.IntegralNum, 2, MidpointRounding.AwayFromZero);
umodel.Integral = 0;
}
FinalMoney = demodel.DetailList.Where(x => goodsList.Contains(x.GoodsId ?? 0)).Sum(x => x.Final_Price ?? 0);
}
else {
FinalMoney = TotalMoney;
else
{
int MaxInterral = Convert.ToInt32((gmodel.PointsDeduction ?? 0) * integralModel.IntegralNum);
//最多可抵扣积分
if (umodel.Integral > MaxInterral)
{
item.IntegralNumber = MaxInterral;
item.IntegralMoney = Math.Round(Convert.ToDecimal(MaxInterral) / integralModel.IntegralNum, 2, MidpointRounding.AwayFromZero);
umodel.Integral -= MaxInterral;
}
else
{
item.IntegralNumber = umodel.Integral;
item.IntegralMoney = Math.Round(Convert.ToDecimal(umodel.Integral ?? 0) / integralModel.IntegralNum, 2, MidpointRounding.AwayFromZero);
umodel.Integral = 0;
}
}
}
}
if (demodel.Use_Integral == 1)
{
item.Final_Price -= (item.IntegralMoney ?? 0);
}
#endregion
#region 优惠券
//decimal CouponsMoney = 0;
if (demodel.User_Coupon_Id > 0)
{
var ccmodel = cList.Where(x => x.Id == demodel.User_Coupon_Id).FirstOrDefault();
string couponItem = (ccmodel?.CouponId ?? 0).ToString();
if (!string.IsNullOrEmpty(couponItem))
{
var dcModel = dcList.Where(x => x.ID == Convert.ToInt32(couponItem)).FirstOrDefault();
if (dcModel == null)
{
return ApiResult.Failed("优惠卷不存在,亲核实后再试");
}
if (dcModel.MinConsumePrice > 0)
dcModel.DiscountsPrice = dcModel.DiscountsPrice == 0 ? 10 : dcModel.DiscountsPrice;
if (dcModel.UseType == Common.Enum.MarketingCenter.UseTypeEnum.Category) //指定分类
{
if (FinalMoney < dcModel.MinConsumePrice)
var categoryList1 = dcpList.Where(x => x.DiscountCouponId == Convert.ToInt32(couponItem) && x.DiscountCouponType == Common.Enum.MarketingCenter.UseTypeEnum.Category).Select(x => x.ProductId).ToList();//获取特殊优惠卷
if (categoryList.Select(x => x.Id).Where(x => categoryList1.Contains(x)).Any())
{
return ApiResult.Failed("Id" + item + "优惠卷未达到使用要求");
GoodsCouponList.Add(new RB_Goods_CouponModel()
{
GoodsId = item.GoodsId ?? 0,
Key = item.SpecificationSort,
TotalMoney = item.Final_Price ?? 0,
CouponMoney = 0
});
}
}
if (dcModel.CouponType == Common.Enum.MarketingCenter.CouponTypeEnum.FullReduction)
else if (dcModel.UseType == Common.Enum.MarketingCenter.UseTypeEnum.Product)//指定商品
{
CouponsMoney += dcModel.DiscountsPrice;
var goodsList = dcpList.Where(x => x.DiscountCouponId == Convert.ToInt32(couponItem) && x.DiscountCouponType == Common.Enum.MarketingCenter.UseTypeEnum.Product).Select(x => x.ProductId).ToList();//获取特殊优惠卷
if (goodsList.Contains(item.GoodsId ?? 0))
{
GoodsCouponList.Add(new RB_Goods_CouponModel()
{
GoodsId = item.GoodsId ?? 0,
Key = item.SpecificationSort,
TotalMoney = item.Final_Price ?? 0,
CouponMoney = 0
});
}
}
else
{
decimal disMoney = Math.Round(FinalMoney * (10 - dcModel.DiscountsPrice) / 10, 2, MidpointRounding.AwayFromZero);
if (dcModel.MaxDiscountsPrice > 0 && dcModel.MaxDiscountsPrice < disMoney) {
disMoney = dcModel.MaxDiscountsPrice;
}
CouponsMoney += disMoney;
GoodsCouponList.Add(new RB_Goods_CouponModel()
{
GoodsId = item.GoodsId ?? 0,
Key = item.SpecificationSort,
TotalMoney = item.Final_Price ?? 0,
CouponMoney = 0
});
}
}
}
#endregion
TotalMoney += (item.Final_Price ?? 0);
item.OrderType = gmodel.GoodsType;
item.GoodsName = gmodel.Name;
item.CoverImage = "";
if (!string.IsNullOrEmpty(gmodel.CarouselImage) && gmodel.CarouselImage != "[]")
{
List<string> CarouselIdList = JsonConvert.DeserializeObject<List<string>>(gmodel.CarouselImage);
//封面图
item.CoverImage = CarouselIdList[0];
}
item.SeparateDistribution = gmodel.SeparateDistribution;
item.SeparateDistributionType = gmodel.SeparateDistributionType;
item.SeparateDistributionMoneyType = gmodel.SeparateDistributionMoneyType;
item.IntegralPresent = gmodel.IntegralPresent;
item.IntegralPresentType = gmodel.IntegralPresentType;
}
if (demodel.User_Coupon_Id > 0 && GoodsCouponList.Any())
{
decimal FinalMoney = GoodsCouponList.Sum(x => x.TotalMoney);
var ccmodel = cList.Where(x => x.Id == demodel.User_Coupon_Id).FirstOrDefault();
var dcModel = dcList.Where(x => x.ID == (ccmodel?.CouponId ?? 0)).FirstOrDefault();
if (dcModel == null)
{
return ApiResult.Failed("优惠卷不存在,亲核实后再试");
}
if (dcModel.MinConsumePrice > 0)
{
if (FinalMoney < dcModel.MinConsumePrice)
{
FinalMoney = 0;
}
}
if (dcModel.CouponType == Common.Enum.MarketingCenter.CouponTypeEnum.FullReduction && FinalMoney > 0)
{
CouponsMoney = dcModel.DiscountsPrice;
}
else if (dcModel.CouponType == Common.Enum.MarketingCenter.CouponTypeEnum.Discount && FinalMoney > 0)
{
decimal disMoney = Math.Round(FinalMoney * (10 - dcModel.DiscountsPrice) / 10, 2, MidpointRounding.AwayFromZero);
if (dcModel.MaxDiscountsPrice > 0 && dcModel.MaxDiscountsPrice < disMoney)
{
disMoney = dcModel.MaxDiscountsPrice;
}
CouponsMoney = disMoney;
}
//每个商品优惠券分摊金额
if (CouponsMoney > 0)
{
foreach (var item in GoodsCouponList)
{
item.CouponMoney = Math.Round((item.TotalMoney / FinalMoney) * CouponsMoney, 2, MidpointRounding.AwayFromZero);
}
if (CouponsMoney != GoodsCouponList.Sum(x => x.CouponMoney))
{
//四舍五入存在差值
decimal diffMoney = CouponsMoney - GoodsCouponList.Sum(x => x.CouponMoney);
var gcModel = GoodsCouponList.OrderBy(x => x.CouponMoney).Take(1).FirstOrDefault();
gcModel.CouponMoney += diffMoney;
}
}
}
foreach (var item in demodel.DetailList)
{
var gmodel = gList.Where(x => x.Id == item.GoodsId).FirstOrDefault();
if (gmodel == null || gmodel.GoodsStatus != 1)
{
continue;
}
item.CouponMoney = 0;
var couponModel = GoodsCouponList.Where(x => x.GoodsId == item.GoodsId).FirstOrDefault();
if (couponModel != null)
{
item.CouponMoney = couponModel.CouponMoney;
TotalMoney -= (item.CouponMoney ?? 0);//总价格需减去优惠券金额
}
}
}
if (demodel.FreightMoney != TotalExpress) {
return ApiResult.Failed("运费不正确");
}
if (CouponsMoney != demodel.CouponMoney) {
return ApiResult.Failed("优惠金额计算有误");
}
......
......@@ -1656,14 +1656,14 @@ namespace Mall.WebApi.Controllers.MallBase
icon_url = qitem.MenuIcon,
name = qitem.MenuName,
is_show = 1,
link_url = qitem.MenuUrl,
link_url = qitem.MenuUrl.Trim(),
}),
//自定义菜单
menus = miniProgram?.SelfMenuList.Select(qitem => new
{
icon_url = qitem.MenuIcon,
name = qitem.MenuName,
link_url = qitem.MenuUrl,
link_url = qitem.MenuUrl.Trim(),
open_type = "navigate",
@params = "",
......@@ -1673,7 +1673,7 @@ namespace Mall.WebApi.Controllers.MallBase
{
icon_url = qitem.MenuIcon,
name = qitem.MenuName,
link_url = qitem.MenuUrl,
link_url = qitem.MenuUrl.Trim(),
open_type = "navigate",
text = "",
}),
......@@ -1682,7 +1682,7 @@ namespace Mall.WebApi.Controllers.MallBase
{
icon_url = qitem.MenuIcon,
name = qitem.MenuName,
link_url = qitem.MenuUrl,
link_url = qitem.MenuUrl.Trim(),
open_type = "navigate",
}),
//版权设置
......@@ -1690,7 +1690,7 @@ namespace Mall.WebApi.Controllers.MallBase
{
pic_url = miniProgram.CopyRightImg,
description = miniProgram.CopyRightWord,
link_url = miniProgram.CopyRightLink,
link_url = miniProgram.CopyRightLink.Trim(),
}
}
};
......
......@@ -37,6 +37,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mall.Module.Product", "Mall
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mall.Module.MarketingCenter", "Mall.Module.MarketingCenter\Mall.Module.MarketingCenter.csproj", "{339DE5B1-FA62-4B3D-80D4-0C50398D2848}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{E56AB52A-2396-4A34-82AE-344EBF51F248}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -95,6 +97,10 @@ Global
{339DE5B1-FA62-4B3D-80D4-0C50398D2848}.Debug|Any CPU.Build.0 = Debug|Any CPU
{339DE5B1-FA62-4B3D-80D4-0C50398D2848}.Release|Any CPU.ActiveCfg = Release|Any CPU
{339DE5B1-FA62-4B3D-80D4-0C50398D2848}.Release|Any CPU.Build.0 = Release|Any CPU
{E56AB52A-2396-4A34-82AE-344EBF51F248}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E56AB52A-2396-4A34-82AE-344EBF51F248}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E56AB52A-2396-4A34-82AE-344EBF51F248}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E56AB52A-2396-4A34-82AE-344EBF51F248}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
<connectionStrings>
<add name="DefaultConnection" providerName="MySql.Data.MySqlClient" connectionString="server=192.168.2.214;user id=reborn;password=Reborn@2018;database=reborn_mall;CharSet=utf8; Convert Zero Datetime=true; " />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test.DBHelper
{
/// <summary>
/// MySql帮助类
/// </summary>
public class MySqlHelper
{
/// <summary>
/// 默认连接字符串
/// </summary>
public static readonly string defaultConnection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
{
MySqlCommand cmd = new MySqlCommand();
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
}
public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
{
// Create a new MySql command
MySqlCommand cmd = new MySqlCommand();
//Create a connection
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
//Prepare the command
PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
//Execute the command
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/// <summary>
/// Internal function to prepare a command for execution by the database
/// </summary>
/// <param name="cmd">Existing command object</param>
/// <param name="conn">Database connection object</param>
/// <param name="trans">Optional transaction object</param>
/// <param name="cmdType">Command type, e.g. stored procedure</param>
/// <param name="cmdText">Command test</param>
/// <param name="commandParameters">Parameters for the command</param>
private static void PrepareCommand(MySqlCommand cmd, MySqlConnection conn, MySqlTransaction trans, CommandType cmdType, string cmdText, MySqlParameter[] commandParameters)
{
//Open the connection if required
if (conn.State != ConnectionState.Open)
conn.Open();
//Set up the command
cmd.Connection = conn;
cmd.CommandText = cmdText;
cmd.CommandType = cmdType;
//Bind it to the transaction if it exists
if (trans != null)
cmd.Transaction = trans;
// Bind the parameters passed in
if (commandParameters != null)
{
foreach (MySqlParameter parm in commandParameters)
cmd.Parameters.Add(parm);
}
}
}
}
using Newtonsoft.Json.Linq;
using Test.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Text.RegularExpressions;
using Test.DBHelper;
namespace Test.Helper
{
/// <summary>
/// 商城帮助类
/// </summary>
public class MallHelper
{
/// <summary>
/// 获取数据
/// </summary>
public static void GetData()
{
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";
GetGategoryImgList(cookie);
}
/// <summary>
/// 获取分类
/// </summary>
/// <param name="cookie"></param>
static void GetGategoryImgList(string cookie)
{
var CategoryList = GetCategoryList(cookie);
if (CategoryList != null && CategoryList.Count > 0)
{
var index = 1;
foreach (var item in CategoryList)
{
Console.WriteLine(index+"/"+ CategoryList.Count + item.name + "分类Start");
StringBuilder builder = new StringBuilder();
builder.AppendFormat(" INSERT INTO rb_material_group(Name,Type,Sort,Recycled,Status,TenantId,MallBaseId,CreateDate,UpdateDate)");
builder.AppendFormat(" VALUES('{0}',{1},{2},1,0,1,1,'{3}','{4}');SELECT LAST_INSERT_ID()", item.name, item.type, item.is_recycle, DateTime.Now, DateTime.Now);
int parentId = 0;
try
{
var res = MySqlHelper.ExecuteScalar(MySqlHelper.defaultConnection, System.Data.CommandType.Text, builder.ToString(), null);
if (res != null && Convert.ToInt32(res) > 0)
{
Int32.TryParse(res.ToString(), out parentId);
}
}
catch (Exception ex)
{
}
int pageIndex = 1;
int pageCount = 1;
List<CategoryImg> imgList = new List<CategoryImg>();
while (pageIndex <= pageCount)
{
var tempImgList = GetCategoryImgList(cookie, pageIndex, item.id, out pageCount);
Console.WriteLine(pageIndex + "/" + pageCount + item.name + "分类ing");
if (tempImgList != null && tempImgList.Count > 0)
{
foreach (var subItem in tempImgList)
{
CreateImage(subItem.url);
string path = "https://viitto-1301420277.cos.ap-chengdu.myqcloud.com" + GetFileUrl(subItem.url);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendFormat("INSERT INTO rb_material_info(Name,Type,GroupId,Path,Image,VideoTime,WithHeight,TenantId,MallBaseId,CreateDate,UpdateDate,Recycled,Status)");
stringBuilder.AppendFormat(" VALUES('{0}',{1},{2},'{3}','{4}',0,0,1,1,'{5}','{6}',1,0)", subItem.name, subItem.type, parentId, path, "", DateTime.Now, DateTime.Now);
try
{
var newResult = MySqlHelper.ExecuteNonQuery(MySqlHelper.defaultConnection, System.Data.CommandType.Text, stringBuilder.ToString(), null);
}
catch (Exception ex)
{
}
}
}
pageIndex++;
var ranDomNum = new Random().Next(1, 20);
Thread.Sleep(1000 * ranDomNum);
}
index++;
Console.WriteLine(index + "/" + CategoryList.Count + item.name + "分类End");
}
}
}
/// <summary>
/// 生成图片
/// </summary>
/// <param name="url"></param>
static void CreateImage(string url)
{
string tempPath = GetFileUrl(url);
string path = Environment.CurrentDirectory + tempPath;//下载到的地址+文件名 // 设置参数
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
//发送请求并获取相应回应数据
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
Stream responseStream = response.GetResponseStream();
string newFilePath = path.Substring(0, path.LastIndexOf("/"));
if (!System.IO.Directory.Exists(newFilePath))//如果不存在就创建file文件夹
{
System.IO.Directory.CreateDirectory(newFilePath);
}
//创建本地文件写入流
Stream stream = new FileStream(path, FileMode.Create);
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, (int)bArr.Length);
while (size > 0)
{
stream.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, (int)bArr.Length);
}
stream.Close();
responseStream.Close();
}
/// <summary>
/// 获取Oss文件全路径
/// </summary>
/// <param name="path">文件相对路径</param>
/// <returns></returns>
public static string GetFileUrl(string path)
{
return path.Replace("https://cdnimg.iotweixin.com", "");
}
/// <summary>
/// 获取分类图片
/// </summary>
/// <param name="cookie"></param>
/// <param name="pageIndex"></param>
/// <param name="Id">分类编号</param>
/// <param name="pageCount"></param>
/// <returns></returns>
static List<CategoryImg> GetCategoryImgList(string cookie, int pageIndex, int Id, out int pageCount)
{
pageCount = 0;
List<CategoryImg> list = new List<CategoryImg>();
string imgApi = "https://wx.weibaoge.cn/web/index.php?r=common%2Fattachment%2Flist&page={0}&attachment_group_id={1}&type=image&is_recycle=0&keyword=";
string newImaApi = string.Format(imgApi, pageIndex, Id);
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";
string jsonData = HttpGet(newImaApi, cookie);
if (jsonData != null && !string.IsNullOrEmpty(jsonData))
{
JObject obj = JObject.Parse(jsonData);
JObject dataObj = JObject.Parse(obj["data"].ToString());
list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<CategoryImg>>(dataObj["list"].ToString());
var pageObj = JObject.Parse(dataObj["pagination"].ToString());
Int32.TryParse(pageObj["page_count"].ToString(), out pageCount);
}
return list;
}
/// <summary>
/// 获取商品分类
/// </summary>
/// <param name="cookie"></param>
/// <returns></returns>
static List<Category> GetCategoryList(string cookie)
{
List<Category> list = new List<Category>();
string ApiUrl = "https://wx.weibaoge.cn/web/index.php?r=common%2Fattachment%2Fgroup-list&is_recycle=0&type=image";
string jsonData = HttpGet(ApiUrl, cookie);
if (jsonData != null && !string.IsNullOrEmpty(jsonData))
{
JObject obj = JObject.Parse(jsonData);
JObject dataObj = JObject.Parse(obj["data"].ToString());
list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Category>>(dataObj["list"].ToString());
}
return list;
}
/// <summary>
/// Get获取数据
/// </summary>
/// <param name="url">url地址</param>
/// <param name="encode">编码方式</param>
/// <param name="Source">来源</param>
/// <returns></returns>
static string HttpGet(string url, string cookie)
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Headers.Add("cookie", cookie);
myRequest.Method = "GET";
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
reader.Close();
return content;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test.Model
{
/// <summary>
/// 分类实体
/// </summary>
public class Category
{
/// <summary>
/// 分类编号
/// </summary>
public int id { get; set; }
/// <summary>
/// 商城Id
/// </summary>
public int mall_id { get; set; }
public int mch_id { get; set; }
/// <summary>
/// 分类名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 1-图片,2-视频
/// </summary>
public int type { get; set; }
public int is_recycle { get; set; }
}
/// <summary>
/// 分类图片实体
/// </summary>
public class CategoryImg
{
/// <summary>
/// 主键编号
/// </summary>
public int id { get; set; }
/// <summary>
/// storage_id
/// </summary>
public int storage_id { get; set; }
/// <summary>
/// 分类编号
/// </summary>
public int attachment_group_id { get; set; }
/// <summary>
/// 分类名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 图片大小
/// </summary>
public int size { get; set; }
/// <summary>
/// 图片地址
/// </summary>
public string url { get; set; }
/// <summary>
/// 缩略图地址
/// </summary>
public string thumb_url { get; set; }
/// <summary>
/// 1-图片,2-视频
/// </summary>
public int type { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start......");
Helper.MallHelper.GetData();
Console.WriteLine("End......");
Console.ReadLine();
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Test")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("e56ab52a-2396-4a34-82ae-344ebf51f248")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E56AB52A-2396-4A34-82AE-344EBF51F248}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Test</RootNamespace>
<AssemblyName>Test</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MySql.Data, Version=6.7.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.6.7.9\lib\net45\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DBHelper\MySqlHelper.cs" />
<Compile Include="Helper\MallHelper.cs" />
<Compile Include="Model\Category.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MySql.Data" version="6.7.9" targetFramework="net46" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
</packages>
\ 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