diff --git a/KJD_WebService/BLL/WXXD/WXUserManage.cs b/KJD_WebService/BLL/WXXD/WXUserManage.cs index a1fbec5..c6cc054 100644 --- a/KJD_WebService/BLL/WXXD/WXUserManage.cs +++ b/KJD_WebService/BLL/WXXD/WXUserManage.cs @@ -547,6 +547,7 @@ namespace KJD_Web.BLL.WXXD postage_per_order = row.Table.Columns.Contains("postage_per_order") ? row["postage_per_order"].ParseToNullableDecimal() : null, refund_postage_per_order = row.Table.Columns.Contains("refund_postage_per_order") ? row["refund_postage_per_order"].ParseToNullableDecimal() : null, gift_oem_amount_per_order = row.Table.Columns.Contains("gift_oem_amount_per_order") ? row["gift_oem_amount_per_order"].ParseToNullableDecimal() : null, + sync_logistics_per_order = row.Table.Columns.Contains("sync_logistics_per_order") ? row["sync_logistics_per_order"].ParseToNullableDecimal() : null, }; var main_authority = row.Table.Columns.Contains("main_authority") ? row["main_authority"].ParseToString() : ""; var main_oem_id = row.Table.Columns.Contains("main_oem_id") ? row["main_oem_id"].ParseToString() : ""; @@ -765,6 +766,7 @@ namespace KJD_Web.BLL.WXXD var postage_per_order = RegexUtils.GetStringQuery(ref inputData, "postage_per_order")?.Replace("'", "\\'"); var refund_postage_per_order = RegexUtils.GetStringQuery(ref inputData, "refund_postage_per_order")?.Replace("'", "\\'"); var gift_oem_amount_per_order = RegexUtils.GetStringQuery(ref inputData, "gift_oem_amount_per_order")?.Replace("'", "\\'"); + var sync_logistics_per_order = RegexUtils.GetStringQuery(ref inputData, "sync_logistics_per_order")?.Replace("'", "\\'"); var oem_id = RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'"); string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; @@ -803,6 +805,8 @@ namespace KJD_Web.BLL.WXXD sql += " refund_postage_per_order=" + refund_postage_per_order + ","; if (gift_oem_amount_per_order != null) sql += " gift_oem_amount_per_order=" + gift_oem_amount_per_order + ","; + if (sync_logistics_per_order != null) + sql += " sync_logistics_per_order=" + sync_logistics_per_order + ","; if (oem_id != null) sql += " oem_id='" + oem_id + "',"; sql = sql.TrimEnd(','); @@ -1641,7 +1645,7 @@ namespace KJD_Web.BLL.WXXD remark = row["remark"].ParseToString(), type = row["type"].ParseToInt(), update_by = row["update_by"].ParseToString(), - update_time = row["update_time"].ParseToString().ParseToDateTime(), + update_time = row["update_time"].ParseToString().ParseToDateTime(), oem_amount = row["oem_amount"].ParseToDecimal(), refund_flow_no = row["oem_amount"].ParseToString(), settlement = row["settlement"].ParseToNullableInt(), diff --git a/KJD_WebService/KJD_WebService.csproj b/KJD_WebService/KJD_WebService.csproj index 58e3844..b481898 100644 --- a/KJD_WebService/KJD_WebService.csproj +++ b/KJD_WebService/KJD_WebService.csproj @@ -215,17 +215,12 @@ - - - - - diff --git a/KJD_WebService/Mappers/WeOrderMapper.cs b/KJD_WebService/Mappers/WeOrderMapper.cs index 791435d..afa3bbf 100644 --- a/KJD_WebService/Mappers/WeOrderMapper.cs +++ b/KJD_WebService/Mappers/WeOrderMapper.cs @@ -1,5 +1,4 @@ using AutoMapper; -using KJD_Web.Entitys; using System; using System.Collections.Generic; using System.Linq; diff --git a/KJD_WebService/Model/UserLoginResultParam.cs b/KJD_WebService/Model/UserLoginResultParam.cs index 83fe7a0..287d1f9 100644 --- a/KJD_WebService/Model/UserLoginResultParam.cs +++ b/KJD_WebService/Model/UserLoginResultParam.cs @@ -107,5 +107,7 @@ namespace KJD_Web.Model /// 每一单礼物额外收取费用 /// public decimal? gift_oem_amount_per_order { get; set; } - } + public decimal? sync_logistics_per_order { get; set; } + + } } \ No newline at end of file diff --git a/KJD_WebService/Requests/Users/CUUserInfoRequest.cs b/KJD_WebService/Requests/Users/CUUserInfoRequest.cs index bdb65be..ca186f2 100644 --- a/KJD_WebService/Requests/Users/CUUserInfoRequest.cs +++ b/KJD_WebService/Requests/Users/CUUserInfoRequest.cs @@ -17,9 +17,6 @@ public class CUUserInfoRequest : SignRequestBase /// 昵称(URL 解码) public string NickName { get; set; } - /// 用户名(URL 解码) - public string UserName { get; set; } - /// 手机号(URL 解码) public string Mobile { get; set; } @@ -58,6 +55,10 @@ public class CUUserInfoRequest : SignRequestBase /// 每单赠送 OEM 金额 public decimal? GiftOemAmountPerOrder { get; set; } + /// + /// 同步物流收费 + /// + public decimal? SyncLogisticsPerOrder { get; set; } /// OEM ID public string OemId { get; set; } diff --git a/KJD_WebService/Services/Users/UserService.FeeRecord.cs b/KJD_WebService/Services/Users/UserService.FeeRecord.cs index 25811f6..d1f7749 100644 --- a/KJD_WebService/Services/Users/UserService.FeeRecord.cs +++ b/KJD_WebService/Services/Users/UserService.FeeRecord.cs @@ -1,7 +1,7 @@ -using KJD_Web.Entitys; -using KJD_Web.Model.WxModel; +using KJD_Web.Model.WxModel; using MySqlX.XDevAPI; using Newtonsoft.Json; +using Store.Contracts.User.Entitys; using System; using System.Collections.Generic; using System.Data.Common; @@ -272,11 +272,11 @@ namespace KJD_Web.Services.Users - } - /// - /// 填充历史数据 - /// + + // /// + // /// 填充历史数据 + // /// // public void FillHistoryOemAmount() // { // List data = new List(); @@ -289,7 +289,7 @@ namespace KJD_Web.Services.Users // { // data = _freeSql.Select() // .Where(a => a.type == 20 || a.type == 26) - // .Where(a => a.create_time > DateTime.Parse("2026-09-01 00:00:00")) + // .Where(a => a.create_time < DateTime.Parse("2026-09-01 00:00:00")) // .OrderBy(a => a.id) // .ToList(); // } @@ -304,7 +304,9 @@ namespace KJD_Web.Services.Users // { // if (!string.IsNullOrEmpty(item.remark)) // { - // item.OrderId = item.remark.Split(':')[1]; + // var ls = item.remark.Split(':'); + // if (ls.Length != 2) continue; + // item.OrderId = ls[1]; // list.Add(item); // if (list.Count == max) // { @@ -324,8 +326,8 @@ namespace KJD_Web.Services.Users // list.ForEach(a => a.IsFill = true); // File.WriteAllText(path, JsonConvert.SerializeObject(data)); // count += list.Count; - // list.Clear(); // Debug.WriteLine($"成功修改;{list.Count}"); + // list.Clear(); // Debug.WriteLine($"共修改;{count}"); // } @@ -399,38 +401,38 @@ namespace KJD_Web.Services.Users // } // return amount; // } - //} + } - //[FreeSql.DataAnnotations.Table(Name = "wxxd.user_payment_record")] - //public class UserPaymentRecordSmall() - //{ - // public long id { get; set; } - // public int type { get; set; } - // /// - // /// 金额(元) - // /// - // public decimal? amount { get; set; } - // /// - // /// 归属oem用户的金额 - // /// - // public decimal? oem_amount { get; set; } - // public string remark { get; set; } + [FreeSql.DataAnnotations.Table(Name = "wxxd.user_payment_record")] + public class UserPaymentRecordSmall() + { + public long id { get; set; } + public int type { get; set; } + /// + /// 金额(元) + /// + public decimal? amount { get; set; } + /// + /// 归属oem用户的金额 + /// + public decimal? oem_amount { get; set; } + public string remark { get; set; } - // public DateTime create_time { get; set; } + public DateTime create_time { get; set; } - // [FreeSql.DataAnnotations.Column(IsIgnore = true)] - // public bool IsFill { get; set; } + [FreeSql.DataAnnotations.Column(IsIgnore = true)] + public bool IsFill { get; set; } - // [FreeSql.DataAnnotations.Column(IsIgnore = true)] - // public string OrderId { get; set; } - //} - //[FreeSql.DataAnnotations.Table(Name = "erp.oms_wei_order")] - //public class weiOrder - //{ - // public string order_id { get; set; } - // public string province_name { get; set; } - //} + [FreeSql.DataAnnotations.Column(IsIgnore = true)] + public string OrderId { get; set; } + } + [FreeSql.DataAnnotations.Table(Name = "erp.oms_wei_order")] + public class weiOrder + { + public string order_id { get; set; } + public string province_name { get; set; } + } public class UserAmountSummary diff --git a/KJD_WebService/Services/Users/UserService.OEM.cs b/KJD_WebService/Services/Users/UserService.OEM.cs index 6297637..a42419b 100644 --- a/KJD_WebService/Services/Users/UserService.OEM.cs +++ b/KJD_WebService/Services/Users/UserService.OEM.cs @@ -1,8 +1,8 @@ using FreeSql.Internal.Model; -using KJD_Web.Entitys; using KJD_Web.Requests.Users; using KJD_Web.Responses.Users; using MAX.Core.DependencyInjection; +using Store.Contracts.User.Entitys; using System; using System.Collections.Generic; using System.Linq; diff --git a/KJD_WebService/Services/Users/UserService.cs b/KJD_WebService/Services/Users/UserService.cs index c53e8fa..a033482 100644 --- a/KJD_WebService/Services/Users/UserService.cs +++ b/KJD_WebService/Services/Users/UserService.cs @@ -1,21 +1,26 @@ using FreeSql; using KJD_Web.Dtos.Users; -using KJD_Web.Entitys; using KJD_Web.Model; using KJD_Web.Model.ShopModel; using KJD_Web.Requests.Users; using KJD_Web.Utils; using MAX.Core.DependencyInjection; +using MAX.Core.Logger; using NaiBa.Util.Extension; +using Store.Contracts.Order.Entitys; +using Store.Contracts.User.Entitys; +using Store.Contracts.User.Enums; +using Store.Contracts.User.Interfaces; using System; using System.Collections.Generic; +using System.Data.Common; using System.Linq; using Ubiety.Dns.Core; using YourNamespace; namespace KJD_Web.Services.Users { - public partial class UserService : ITransientDependency + public partial class UserService : IUserService, ITransientDependency { /// /// 商铺续费每月30 @@ -27,10 +32,12 @@ namespace KJD_Web.Services.Users private const int MaxRenewDuration = 120; private readonly IFreeSql _freeSql; + private readonly ILoggerFacade _logger; - public UserService(IFreeSql freeSql) + public UserService(IFreeSql freeSql, ILoggerFacade logger) { _freeSql = freeSql ?? throw new ArgumentNullException(nameof(freeSql)); + _logger = logger; } public bool IsOem(string userName) @@ -326,6 +333,8 @@ namespace KJD_Web.Services.Users if (userinfo.GiftOemAmountPerOrder.HasValue) update = update.Set(a => a.GiftOemAmountPerOrder, userinfo.GiftOemAmountPerOrder.Value); + if (userinfo.SyncLogisticsPerOrder.HasValue) + update = update.Set(a => a.SyncLogisticsPerOrder, userinfo.SyncLogisticsPerOrder.Value); //主账户允许修改OEM if (oldUser.IsMainUser) { @@ -365,5 +374,75 @@ namespace KJD_Web.Services.Users work.Commit(); } + + /// + /// 用户消费付款记录 + /// + /// + /// + /// + /// + /// + public void UserPayment(string userName, string orderId, UserPaymentTypes type, DbTransaction tarn = null) + { + using var work = tarn != null ? _freeSql.CreateUnitOfWork(tarn) : _freeSql.CreateUnitOfWork(); + var trFreeSql = work.Orm; + var user = trFreeSql.Select() + .Where(a => a.UserName == userName) + .First(); + if (user == null) + { + throw new Exception("用户不存在"); + } + if (user.IsMainUser == false) + { + var mainUser = _freeSql.Select() + .Where(a => a.UserName == user.ParentUserName) + .First(); + if (mainUser == null) + { + throw new Exception("错误的账户"); + } + user.SyncLogisticsPerOrder = mainUser.SyncLogisticsPerOrder; + } + if (type != UserPaymentTypes.同步单号) throw new Exception("不支持的类型"); + var payItem = new UserPaymentRecordEntity + { + Type = (int)type, + Amount = (user.SyncLogisticsPerOrder ?? 0.0m) + 1.7m, + UserName = user.UserName, + PlatformCode = "WEISHOP", + OrderId = orderId, + CreateBy = user.UserName, + CreateTime = DateTime.Now, + Remark = "同步物流:", + CounterpartyAccountName = user.UserName, + }; + if (user.IsOEMTenant) + { + payItem.OemAmount = user.SyncLogisticsPerOrder; + } + payItem.Balance = user.Balance - payItem.Amount; + var affrows = trFreeSql.Insert(payItem).ExecuteAffrows(); + if (affrows != 1) + { + _logger.Error($"付款失败:{userName},{orderId},{type}"); + throw new Exception("付款失败"); + } + affrows = trFreeSql.Update() + .Set(a => a.Balance - payItem.Amount) + .Where(a => a.UserName == user.UserName) + .Where(a => a.Balance >= payItem.Amount) + .ExecuteAffrows(); + if (affrows != 1) + { + _logger.Error($"付款失败,余额不足:{userName},{orderId},{type}"); + throw new Exception("余额不足"); + } + work.Commit(); + } + + + } } diff --git a/Store.Contracts/Class1.cs b/Store.Contracts/Class1.cs deleted file mode 100644 index c3a5a3b..0000000 --- a/Store.Contracts/Class1.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Store.Contracts; - -public class Class1 -{ - -} diff --git a/Store.Contracts/Shops/ShopEntity.cs b/Store.Contracts/Shops/ShopEntity.cs new file mode 100644 index 0000000..470e17d --- /dev/null +++ b/Store.Contracts/Shops/ShopEntity.cs @@ -0,0 +1,255 @@ +using FreeSql.DataAnnotations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Store.Contracts.Shops; + +/// +/// 店铺表 +/// +[Table(Name = "erp.o_shop")] +public class ShopEntity +{ + /// + /// 主键 + /// + [Column(Name = "id", IsPrimary = true, IsIdentity = true)] + public long Id { get; set; } + + /// + /// 店铺名 + /// + [Column(Name = "name")] + public string Name { get; set; } + + /// + /// 对应第三方平台Id + /// + [Column(Name = "type")] + public int Type { get; set; } + + /// + /// 登录获取的Cookie信息 + /// + [Column(Name = "login_cookie")] + public string LoginCookie { get; set; } + + /// + /// 访问需要的header参数 + /// + [Column(Name = "header_params")] + public string HeaderParams { get; set; } + + /// + /// 店铺url + /// + [Column(Name = "url")] + public string Url { get; set; } + + /// + /// 排序 + /// + [Column(Name = "sort")] + public int Sort { get; set; } + + /// + /// 状态(1正常2已删除) + /// + [Column(Name = "status")] + public int? Status { get; set; } + + /// + /// 描述 + /// + [Column(Name = "remark")] + public string Remark { get; set; } + + /// + /// 第三方平台店铺id,淘宝天猫开放平台使用 + /// + [Column(Name = "seller_id")] + public long? SellerId { get; set; } + + /// + /// 授权时间 + /// + [Column(Name = "auth_time")] + public long? AuthTime { get; set; } + + /// + /// 服务市场授权到期时间 + /// + [Column(Name = "expire_time")] + public long? ExpireTime { get; set; } + + /// + /// Appkey + /// + [Column(Name = "app_key")] + public string AppKey { get; set; } + + /// + /// Appsercet + /// + [Column(Name = "app_secret")] + public string AppSecret { get; set; } + + /// + /// 小红椒的access_token + /// + [Column(Name = "access_token_xhj")] + public string AccessTokenXhj { get; set; } + + /// + /// 第三方平台sessionKey(access_token) + /// + [Column(Name = "access_token")] + public string AccessToken { get; set; } + + /// + /// 小红椒多久到期 + /// + [Column(Name = "expires_in_xhj")] + public long? ExpiresInXhj { get; set; } + + /// + /// 到期 + /// + [Column(Name = "expires_in")] + public long? ExpiresIn { get; set; } + + /// + /// 小红椒access_token开始时间 + /// + [Column(Name = "access_token_begin_xhj")] + public long? AccessTokenBeginXhj { get; set; } + + /// + /// access_token开始时间 + /// + [Column(Name = "access_token_begin")] + public long? AccessTokenBegin { get; set; } + + /// + /// 刷新token + /// + [Column(Name = "refresh_token")] + public string RefreshToken { get; set; } + + /// + /// 刷新token过期时间 + /// + [Column(Name = "refresh_token_timeout")] + public long? RefreshTokenTimeout { get; set; } + + /// + /// 代理api请求凭证 + /// + [Column(Name = "session")] + public string Session { get; set; } + + /// + /// 代理api获取请求凭证的shopkey字段 + /// + [Column(Name = "shop_key")] + public string ShopKey { get; set; } + + /// + /// 请求url + /// + [Column(Name = "api_request_url")] + public string ApiRequestUrl { get; set; } + + /// + /// 回掉URL + /// + [Column(Name = "api_callback_url")] + public string ApiCallbackUrl { get; set; } + + /// + /// 负责人id + /// + [Column(Name = "manage_user_id")] + public long? ManageUserId { get; set; } + + /// + /// 默认运费模板id,抖店上传商品使用 + /// + [Column(Name = "default_freight_template_id")] + public long? DefaultFreightTemplateId { get; set; } + + /// + /// 默认品牌id,抖店上传商品使用 + /// + [Column(Name = "default_brand_id")] + public long? DefaultBrandId { get; set; } + + /// + /// 店铺是否已开启尺码自动优化,0:不需要开启,1:未开启,2:已开启 + /// + [Column(Name = "auto_size_template_optimize")] + public byte? AutoSizeTemplateOptimize { get; set; } + + /// + /// 店铺分组 + /// + [Column(Name = "shop_group_id")] + public long? ShopGroupId { get; set; } + + /// + /// 企业账号用户id + /// + [Column(Name = "corporate_account_user_id")] + public long? CorporateAccountUserId { get; set; } + + /// + /// 国家/地区 + /// + [Column(Name = "region_id")] + public long? RegionId { get; set; } + + /// + /// 商户ID + /// + [Column(Name = "merchant_id")] + public long? MerchantId { get; set; } + + /// + /// 创建时间 + /// + [Column(Name = "create_time")] + public DateTime? CreateTime { get; set; } + + /// + /// 创建人 + /// + [Column(Name = "create_by")] + public string CreateBy { get; set; } + + /// + /// 更新时间 + /// + [Column(Name = "update_time")] + public DateTime? UpdateTime { get; set; } + + /// + /// 更新人 + /// + [Column(Name = "update_by")] + public string UpdateBy { get; set; } + + /// + /// api调用状态0未开启1已开启 + /// + [Column(Name = "api_status")] + public int ApiStatus { get; set; } + + /// + /// 是否开启自动购买外采礼物单,0:未开启,1:已开启 + /// + [Column(Name = "auto_purchase_external_gift")] + public int? AutoPurchaseExternalGift { get; set; } +} diff --git a/Store.Contracts/Store.Contracts.csproj b/Store.Contracts/Store.Contracts.csproj index b7f4f2f..bcfe5a3 100644 --- a/Store.Contracts/Store.Contracts.csproj +++ b/Store.Contracts/Store.Contracts.csproj @@ -9,8 +9,4 @@ - - - - diff --git a/KJD_WebService/Entitys/OEMEntity.cs b/Store.Contracts/User/Entitys/OEMEntity.cs similarity index 97% rename from KJD_WebService/Entitys/OEMEntity.cs rename to Store.Contracts/User/Entitys/OEMEntity.cs index c60672c..632ca1b 100644 --- a/KJD_WebService/Entitys/OEMEntity.cs +++ b/Store.Contracts/User/Entitys/OEMEntity.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Web; -namespace KJD_Web.Entitys; +namespace Store.Contracts.User.Entitys; /// diff --git a/KJD_WebService/Entitys/UserEntity.cs b/Store.Contracts/User/Entitys/UserEntity.cs similarity index 91% rename from KJD_WebService/Entitys/UserEntity.cs rename to Store.Contracts/User/Entitys/UserEntity.cs index 041de86..0fc08fb 100644 --- a/KJD_WebService/Entitys/UserEntity.cs +++ b/Store.Contracts/User/Entitys/UserEntity.cs @@ -1,7 +1,7 @@ using FreeSql.DataAnnotations; using System; -namespace KJD_Web.Entitys +namespace Store.Contracts.User.Entitys { /// /// 用户表 @@ -153,6 +153,13 @@ namespace KJD_Web.Entitys [Column(Name = "gift_oem_amount_per_order")] public decimal? GiftOemAmountPerOrder { get; set; } + + /// + /// 同步物流费用,单位元,两位小数 + /// + [Column(Name = "sync_logistics_per_order")] + public decimal? SyncLogisticsPerOrder { get; set; } + /// /// 是否主账户 /// @@ -160,5 +167,9 @@ namespace KJD_Web.Entitys { get => string.IsNullOrWhiteSpace(ParentUserName); } + /// + /// 是否OEM租户 + /// + public bool IsOEMTenant => !string.IsNullOrWhiteSpace(OemId); } } \ No newline at end of file diff --git a/KJD_WebService/Entitys/UserPaymentRecordEntity.cs b/Store.Contracts/User/Entitys/UserPaymentRecordEntity.cs similarity index 93% rename from KJD_WebService/Entitys/UserPaymentRecordEntity.cs rename to Store.Contracts/User/Entitys/UserPaymentRecordEntity.cs index 4854617..1eb4805 100644 --- a/KJD_WebService/Entitys/UserPaymentRecordEntity.cs +++ b/Store.Contracts/User/Entitys/UserPaymentRecordEntity.cs @@ -1,10 +1,11 @@ using FreeSql.DataAnnotations; +using Store.Contracts.User.Enums; using System; using System.Collections.Generic; using System.Linq; using System.Web; -namespace KJD_Web.Entitys; +namespace Store.Contracts.User.Entitys; [Table(Name = "wxxd.user_payment_record")] public class UserPaymentRecordEntity @@ -61,7 +62,7 @@ public class UserPaymentRecordEntity /// 售后单id /// [Column(Name = "after_sale_id")] - public long AfterSaleId { get; set; } + public long? AfterSaleId { get; set; } /// /// 创建人 @@ -91,7 +92,7 @@ public class UserPaymentRecordEntity /// 是否已删除 /// [Column(Name = "is_deleted")] - public int? IsDeleted { get; set; } + public int IsDeleted { get; set; } /// /// 备注 @@ -109,7 +110,7 @@ public class UserPaymentRecordEntity /// OEM是否结算 0未结算 1已结算 /// [Column(Name = "settlement")] - public byte? Settlement { get; set; } + public byte Settlement { get; set; } = 0; /// /// 退款流水号 外采&订单号 diff --git a/KJD_WebService/Entitys/UserPointsRecordEntity.cs b/Store.Contracts/User/Entitys/UserPointsRecordEntity.cs similarity index 98% rename from KJD_WebService/Entitys/UserPointsRecordEntity.cs rename to Store.Contracts/User/Entitys/UserPointsRecordEntity.cs index 3c93341..381a127 100644 --- a/KJD_WebService/Entitys/UserPointsRecordEntity.cs +++ b/Store.Contracts/User/Entitys/UserPointsRecordEntity.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Web; -namespace KJD_Web.Entitys +namespace Store.Contracts.User.Entitys { [Table(Name = "wxxd.user_points_record")] diff --git a/KJD_WebService/Entitys/UserPointsShopExpire.cs b/Store.Contracts/User/Entitys/UserPointsShopExpire.cs similarity index 95% rename from KJD_WebService/Entitys/UserPointsShopExpire.cs rename to Store.Contracts/User/Entitys/UserPointsShopExpire.cs index 287abec..139aa67 100644 --- a/KJD_WebService/Entitys/UserPointsShopExpire.cs +++ b/Store.Contracts/User/Entitys/UserPointsShopExpire.cs @@ -1,7 +1,7 @@ using FreeSql.DataAnnotations; using System; -namespace KJD_Web.Entitys +namespace Store.Contracts.User.Entitys { /// /// 用户积分商店过期 diff --git a/Store.Contracts/User/Enums/PaymentTypes.cs b/Store.Contracts/User/Enums/PaymentTypes.cs new file mode 100644 index 0000000..91a8784 --- /dev/null +++ b/Store.Contracts/User/Enums/PaymentTypes.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Store.Contracts.User.Enums; +/// +/// 用户付款类型 +/// +public enum UserPaymentTypes +{ + 充值 = 1, + //采购花费 = 2, + //产品退款到账 = 3, + //运费退款到账 = 4, + //采购收款 = 5, + //产品退款扣除 = 6, + //运费退款扣除 = 7, + 礼物单支出 = 16, + 中转仓扣费支出 = 20, + 中转仓作废返还收入 = 23, + 中转仓超重支出 = 24, + 退货包裹扣费支出 = 26, + 中转仓快递超重费用 = 28, + 支付宝在线充值 = 30, + 云仓退货支出 = 31, + 礼物单退费 = 34, + 同步单号 = 55, +} diff --git a/Store.Contracts/User/Interfaces/IUserService.cs b/Store.Contracts/User/Interfaces/IUserService.cs new file mode 100644 index 0000000..dc7860c --- /dev/null +++ b/Store.Contracts/User/Interfaces/IUserService.cs @@ -0,0 +1,32 @@ +using Store.Contracts.User.Entitys; +using Store.Contracts.User.Enums; +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Store.Contracts.User.Interfaces; + +public interface IUserService +{ + OEMEntity GetOEMByOemId(string oemId, bool isCache = true); + OEMEntity GetOEMByUserName(string userName, bool isCache = true); + List GetOEMUsers(string oemId, bool includeSu = true); + + List GetUserAndSubUser(string userName); + UserEntity GetUserByUserName(string userName); + bool IsOem(string userName); + OEMEntity SettleOemFlows(string userName, DbTransaction tarn = null); + long SettleUserFlows(string userName, DbTransaction tarn = null); + /// + /// 用户消费付款记录 + /// + /// + /// + /// + /// + /// + void UserPayment(string userName, string orderId, UserPaymentTypes type, DbTransaction tarn = null); +} diff --git a/Store.SyncLogistics/Apis/VirtualLogisticsApi.cs b/Store.SyncLogistics/Apis/VirtualLogisticsApi.cs index 65a3378..174270e 100644 --- a/Store.SyncLogistics/Apis/VirtualLogisticsApi.cs +++ b/Store.SyncLogistics/Apis/VirtualLogisticsApi.cs @@ -177,7 +177,7 @@ public class VirtualLogisticsApi : ISingletonDependency } item.Encoding = Encoding.UTF8; - item.ProxyIp = "127.0.0.1:8080"; + //item.ProxyIp = "127.0.0.1:8080"; long unix = DateHelper.GetCurrentUnixTimestampInSeconds(); diff --git a/Store.SyncLogistics/Controllers/LogisticsController.cs b/Store.SyncLogistics/Controllers/LogisticsController.cs index 9e4ae48..3f3d324 100644 --- a/Store.SyncLogistics/Controllers/LogisticsController.cs +++ b/Store.SyncLogistics/Controllers/LogisticsController.cs @@ -1,5 +1,6 @@ using Store.Framework.Base; using Store.Framework.Models; +using Store.SyncLogistics.Dtos; using Store.VirtualLogistics.Apis; using Store.VirtualLogistics.Entitys; using Store.VirtualLogistics.Models; @@ -99,11 +100,13 @@ public class LogisticsController : ApiControllerBase /// 购买快递 /// [HttpPost] - public IHttpActionResult Buy(string orderId) + public IHttpActionResult Buy(BuyLogisticsRequest request) { try { - var result = _logisticsService.Buy(orderId, ""); + string orderId = request.OrderId; + string agentOrderId = request.AgentOrderId; + var result = _logisticsService.Buy(request.UserName, orderId, agentOrderId); return Ok(ApiResult.Success(result)); } catch (Exception ex) diff --git a/Store.SyncLogistics/Dtos/BuyLogisticsRequest.cs b/Store.SyncLogistics/Dtos/BuyLogisticsRequest.cs new file mode 100644 index 0000000..cabe2e0 --- /dev/null +++ b/Store.SyncLogistics/Dtos/BuyLogisticsRequest.cs @@ -0,0 +1,14 @@ +using Store.Framework.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Store.SyncLogistics.Dtos; + +public class BuyLogisticsRequest : SignRequestBase +{ + public string OrderId { get; set; } + public string AgentOrderId { get; set; } +} diff --git a/Store.SyncLogistics/Models/BuyModels.cs b/Store.SyncLogistics/Models/BuyModels.cs index a7676d9..6c6a1a9 100644 --- a/Store.SyncLogistics/Models/BuyModels.cs +++ b/Store.SyncLogistics/Models/BuyModels.cs @@ -261,7 +261,7 @@ public class EncryptDatas /// 订单商品数量,视频号必填 /// [JsonProperty("sku_cnt")] - public string SkuCnt { get; set; } + public int SkuCnt { get; set; } } public class ExtendParams { diff --git a/Store.SyncLogistics/Services/VirtualLogisticsService.cs b/Store.SyncLogistics/Services/VirtualLogisticsService.cs index 20eb178..a14e644 100644 --- a/Store.SyncLogistics/Services/VirtualLogisticsService.cs +++ b/Store.SyncLogistics/Services/VirtualLogisticsService.cs @@ -2,6 +2,9 @@ using MAX.Core.Commons; using MAX.Core.DependencyInjection; using MAX.Core.Logger; using Store.Contracts.Order.Entitys; +using Store.Contracts.Shops; +using Store.Contracts.User.Entitys; +using Store.Contracts.User.Interfaces; using Store.VirtualLogistics.Apis; using Store.VirtualLogistics.Entitys; using Store.VirtualLogistics.Models; @@ -16,14 +19,20 @@ namespace Store.VirtualLogistics.Services; public class VirtualLogisticsService : ITransientDependency { + /// + /// 固定费用1.7元 + /// + const decimal FIXEDFEES = 1.7m; private IFreeSql _freeSql; private readonly ILoggerFacade _logger; + private readonly IUserService _userService; private readonly VirtualLogisticsApi _api; - public VirtualLogisticsService(VirtualLogisticsApi api, IFreeSql freeSql, ILoggerFacade logger) + public VirtualLogisticsService(VirtualLogisticsApi api, IFreeSql freeSql, ILoggerFacade logger, IUserService userService) { _freeSql = freeSql ?? throw new ArgumentNullException(nameof(freeSql)); _logger = logger; + _userService = userService; _api = api; } @@ -64,15 +73,22 @@ public class VirtualLogisticsService : ITransientDependency /// /// 购买快递 /// - public List Buy(string orderId, string ds_orderId) + public List Buy(string userName, string orderId, string agentOrderId) { - var item = _freeSql.Select() + if (string.IsNullOrEmpty(orderId) || string.IsNullOrWhiteSpace(agentOrderId)) + { + throw new ArgumentNullException(nameof(orderId)); + } + var user = _userService.GetUserByUserName(userName); + if (user == null) throw new Exception("错误的账号"); + //中间订单 + var middleOrder = _freeSql.Select() .Where(a => a.OrderSn == orderId) .First(); - if (item == null) throw new Exception("错误的订单号"); - + if (middleOrder == null) throw new Exception("错误的订单号"); + //middleOrder.TrackingNumber = "YT0709726946568"; var w_order = _freeSql.Select() - .Where(a => a.OrderId == item.WxOrderId) + .Where(a => a.OrderId == middleOrder.WxOrderId) .First(); if (w_order == null) throw new Exception("错误的订单号"); @@ -81,6 +97,12 @@ public class VirtualLogisticsService : ITransientDependency .First(); if (productItem == null) throw new Exception("错误的订单详情号"); + var shop = _freeSql.Select() + .Where(a => a.Id == productItem.ShopId) + .First(); + if (shop == null) throw new Exception("错误的店铺"); + + BuyRequest request = new BuyRequest() { KuaidiId = "874", @@ -98,20 +120,28 @@ public class VirtualLogisticsService : ITransientDependency new RecItem { OrderSn = orderId, + ShopOrder =w_order.OrderId, RecName = w_order.UserName, RecMobile = w_order.TelNumber, RecProvince = w_order.ProvinceName, RecCity = w_order.CityName, RecDistrict = w_order.CountyName, RecAddress = w_order.DetailInfo, + EwaybillOrderCode="wx7809625286c28f2f", EncryptDatas=new EncryptDatas { - DsOrderId=ds_orderId, + DsOrderId=agentOrderId, SkuId = productItem.SkuId, ProductId = productItem.ProductId, - SkuCnt = productItem.SkuCnt.ToString(), + SkuCnt = productItem.SkuCnt, + FromShopCode = shop.AppKey, }, - OtherKuaidiSn= "6738192431"//item.TrackingNumber, + ExtendParams=new ExtendParams{ + Token="", + Api="", + DsOrderId =agentOrderId + }, + OtherKuaidiSn= middleOrder.TrackingNumber, } ] @@ -141,6 +171,9 @@ public class VirtualLogisticsService : ITransientDependency _logger.Error("购买同步单提交到数据库错误"); throw new Exception("记录同步单失败"); } + + //todo 更新UserBlance + _userService.UserPayment(user.UserName, orderId, type: Contracts.User.Enums.UserPaymentTypes.同步单号); return yhSyncs; } diff --git a/test/WebServiceTest/GiftLogisticsTest.cs b/test/WebServiceTest/GiftLogisticsTest.cs index 372d92a..741f72f 100644 --- a/test/WebServiceTest/GiftLogisticsTest.cs +++ b/test/WebServiceTest/GiftLogisticsTest.cs @@ -84,7 +84,7 @@ internal class GiftLogisticsTest { try { - var ret = logisticsApi.QueryOrderStatus(["260705-168736857712823"]); + var ret = logisticsApi.QueryOrderStatus(["260923-405295603341688"]); Console.WriteLine(string.Join(" ", ret.Data.Select(a => $"{a.OrderSn}:{a.KuaidiSn}({a.Status})"))); } catch (Exception ex) @@ -95,41 +95,14 @@ internal class GiftLogisticsTest [Test] public void BuyTest() { - //var request = new BuyRequest - //{ - // KuaidiId = "874", - // GoodsId = "8473", - // CangId = "914", - // Platform = 6, - // Auth = 1, - // SendName = "张三", - // SendMobile = "18255185853", - // SendProvince = "辽宁省", - // SendCity = "大连市", - // SendDistrict = "甘井子区", - // SendAddress = "革镇堡幸福家园2栋", - // RecList = new List - // { - // new RecItem - // { - // OrderSn = "3739252814971847936", - // RecName = "李四", - // RecMobile = "18255185853", - // RecProvince = "湖南省", - // RecCity = "衡阳市", - // RecDistrict = "雁峰区", - // RecAddress = "和谐小区 1栋", - // OtherKuaidiSn="315097997688420" - // } - // } - //}; - //var ret = logisticsApi.Buy(request); - var userService = _container.Resolve(); - var ret = userService.Buy("260705-168736857712823", "4439341152678214144"); + var logisticsService = _container.Resolve(); + var ret = logisticsService.Buy("260923-573109716621688", "4439363558732480512", "15222220006"); if (ret != null) { Console.WriteLine(string.Join(" ", ret.Select(a => $"{a.OrderId}:{a.TrackingNumber}"))); } + //var userService = _container.Resolve(); + //userService.UserPayment("15222220006", "260923-405295603341688", type: Store.Contracts.User.Enums.UserPaymentTypes.同步单号); } [Test] public void UploadPickupTest()