diff --git a/CoreCms.Net.Configuration/AppSettingsConstVars.cs b/CoreCms.Net.Configuration/AppSettingsConstVars.cs index 0f315abb..13c5771a 100644 --- a/CoreCms.Net.Configuration/AppSettingsConstVars.cs +++ b/CoreCms.Net.Configuration/AppSettingsConstVars.cs @@ -132,40 +132,6 @@ namespace CoreCms.Net.Configuration public static readonly string PayCallBackAlipayRefundUrl = AppSettingsHelper.GetContent("PayCallBack", "AlipayRefundUrl"); #endregion - - #region 易联云打印机================================================================================ - - /// - /// 是否开启 - /// - public static readonly bool YiLianYunConfigEnabled = AppSettingsHelper.GetContent("YiLianYunConfig", "Enabled").ObjToBool(); - /// - /// 应用ID - /// - public static readonly string YiLianYunConfigClientId = AppSettingsHelper.GetContent("YiLianYunConfig", "ClientId"); - /// - /// 应用密钥 - /// - public static readonly string YiLianYunConfigClientSecret = AppSettingsHelper.GetContent("YiLianYunConfig", "ClientSecret"); - /// - /// 打印机设备号 - /// - public static readonly string YiLianYunConfigMachineCode = AppSettingsHelper.GetContent("YiLianYunConfig", "MachineCode"); - /// - /// 打印机终端密钥 - /// - public static readonly string YiLianYunConfigMsign = AppSettingsHelper.GetContent("YiLianYunConfig", "Msign"); - /// - /// 打印机名称 - /// - public static readonly string YiLianYunConfigPrinterName = AppSettingsHelper.GetContent("YiLianYunConfig", "PrinterName"); - /// - /// 打印机设置联系方式 - /// - public static readonly string YiLianYunConfigPhone = AppSettingsHelper.GetContent("YiLianYunConfig", "Phone"); - - #endregion - #region HangFire定时任务================================================================================ /// /// 登录账号 diff --git a/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs b/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs index 59f55541..84400a9a 100644 --- a/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs +++ b/CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs @@ -1,11 +1,7 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using CoreCms.Net.Configuration; -using CoreCms.Net.RedisMQ.Subscribe; -using CoreCms.Net.Utility.Extensions; +using CoreCms.Net.RedisMQ; using InitQ; using Microsoft.Extensions.DependencyInjection; diff --git a/CoreCms.Net.Core/Config/YiLianYunSetup.cs b/CoreCms.Net.Core/Config/YiLianYunSetup.cs deleted file mode 100644 index df67fbf9..00000000 --- a/CoreCms.Net.Core/Config/YiLianYunSetup.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using CoreCms.Net.Configuration; -using CoreCms.Net.RedisMQ.Subscribe; -using CoreCms.Net.Utility.Extensions; -using InitQ; -using Microsoft.Extensions.DependencyInjection; -using Qc.YilianyunSdk; - -namespace CoreCms.Net.Core.Config -{ - /// - /// 易联云打印机 启动服务 - /// - public static class YiLianYunSetup - { - public static void AddYiLianYunSetup(this IServiceCollection services) - { - if (services == null) throw new ArgumentNullException(nameof(services)); - - if (AppSettingsConstVars.YiLianYunConfigEnabled) - { - services.AddYilianyunSdk(opt => - { - // 应用ID请自行前往 dev.10ss.net 获取 - opt.ClientId = AppSettingsConstVars.YiLianYunConfigClientId; - opt.ClientSecret = AppSettingsConstVars.YiLianYunConfigClientSecret; - opt.YilianyunClientType = YilianyunClientType.自有应用; - opt.SaveTokenDirPath = "./App_Data/YiLianYunLogs"; - }); - } - } - } -} diff --git a/CoreCms.Net.Core/CoreCms.Net.Core.csproj b/CoreCms.Net.Core/CoreCms.Net.Core.csproj index db1d40a3..dcb410e4 100644 --- a/CoreCms.Net.Core/CoreCms.Net.Core.csproj +++ b/CoreCms.Net.Core/CoreCms.Net.Core.csproj @@ -25,7 +25,6 @@ - diff --git a/CoreCms.Net.IRepository/Api/ICoreCmsPrinterRepository.cs b/CoreCms.Net.IRepository/Api/ICoreCmsPrinterRepository.cs new file mode 100644 index 00000000..621c8708 --- /dev/null +++ b/CoreCms.Net.IRepository/Api/ICoreCmsPrinterRepository.cs @@ -0,0 +1,82 @@ +/*********************************************************************** + * Project: CoreCms + * ProjectName: 核心内容管理系统 + * Web: https://www.corecms.net + * Author: 大灰灰 + * Email: jianweie@163.com + * CreateTime: 2022/9/16 20:41:09 + * Description: 暂无 + ***********************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; +using CoreCms.Net.Model.Entities; +using CoreCms.Net.Model.ViewModels.Basics; +using CoreCms.Net.Model.ViewModels.UI; +using SqlSugar; + + +namespace CoreCms.Net.IRepository +{ + /// + /// 打印机列表 工厂接口 + /// + public interface ICoreCmsPrinterRepository : IBaseRepository + { + #region 重写增删改查操作=========================================================== + + /// + /// 重写异步插入方法 + /// + /// + /// + Task InsertAsync(CoreCmsPrinter entity); + + + /// + /// 重写异步更新方法 + /// + /// + /// + Task UpdateAsync(CoreCmsPrinter entity); + + + /// + /// 重写删除指定ID的数据 + /// + /// + /// + Task DeleteByIdAsync(object id); + + #endregion + + #region 获取缓存的所有数据========================================================== + + /// + /// 获取缓存的所有数据 + /// + /// + Task> GetCaChe(); + + #endregion + + + /// + /// 重写根据条件查询分页数据 + /// + /// 判断集合 + /// 排序方式 + /// 当前页面索引 + /// 分布大小 + /// + /// 是否使用WITH(NOLOCK) + /// + Task> QueryPageAsync( + Expression> predicate, + Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1, + int pageSize = 20, bool blUseNoLock = false); + + } +} diff --git a/CoreCms.Net.IServices/Api/ICoreCmsPrinterServices.cs b/CoreCms.Net.IServices/Api/ICoreCmsPrinterServices.cs new file mode 100644 index 00000000..b46ff7e4 --- /dev/null +++ b/CoreCms.Net.IServices/Api/ICoreCmsPrinterServices.cs @@ -0,0 +1,69 @@ +/*********************************************************************** + * Project: CoreCms + * ProjectName: 核心内容管理系统 + * Web: https://www.corecms.net + * Author: 大灰灰 + * Email: jianweie@163.com + * CreateTime: 2022/9/16 20:41:09 + * Description: 暂无 + ***********************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; +using CoreCms.Net.Model.Entities; +using CoreCms.Net.Model.ViewModels.Basics; +using CoreCms.Net.Model.ViewModels.UI; +using SqlSugar; + +namespace CoreCms.Net.IServices +{ + /// + /// 打印机列表 服务工厂接口 + /// + public interface ICoreCmsPrinterServices : IBaseServices + { + #region 重写增删改查操作=========================================================== + + /// + /// 重写异步插入方法 + /// + /// + /// + Task InsertAsync(CoreCmsPrinter entity); + + /// + /// 重写异步更新方法 + /// + /// + /// + Task UpdateAsync(CoreCmsPrinter entity); + + /// + /// 重写删除指定ID的数据 + /// + /// + /// + Task DeleteByIdAsync(object id); + + #endregion + + #region 重写根据条件查询分页数据 + /// + /// 重写根据条件查询分页数据 + /// + /// 判断集合 + /// 排序方式 + /// 当前页面索引 + /// 分布大小 + /// + /// 是否使用WITH(NOLOCK) + /// + Task> QueryPageAsync( + Expression> predicate, + Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1, + int pageSize = 20, bool blUseNoLock = false); + #endregion + } +} diff --git a/CoreCms.Net.Model/Entities/Api/CoreCmsPrinter.cs b/CoreCms.Net.Model/Entities/Api/CoreCmsPrinter.cs new file mode 100644 index 00000000..c0ee5e80 --- /dev/null +++ b/CoreCms.Net.Model/Entities/Api/CoreCmsPrinter.cs @@ -0,0 +1,210 @@ +/*********************************************************************** + * Project: CoreCms + * ProjectName: 核心内容管理系统 + * Web: https://www.corecms.net + * Author: 大灰灰 + * Email: jianweie@163.com + * CreateTime: 2022/9/16 20:41:09 + * Description: 暂无 + ***********************************************************************/ + +using SqlSugar; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace CoreCms.Net.Model.Entities +{ + /// + /// 打印机列表 + /// + public partial class CoreCmsPrinter + { + /// + /// 构造函数 + /// + public CoreCmsPrinter() + { + } + + /// + /// 序列 + /// + [Display(Name = "序列")] + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + [Required(ErrorMessage = "请输入{0}")] + + + public System.Int32 id { get; set; } + + + /// + /// 应用名称 + /// + [Display(Name = "应用名称")] + [Required(ErrorMessage = "请输入{0}")] + [StringLength(maximumLength: 50, ErrorMessage = "{0}不能超过{1}字")] + + + public System.String name { get; set; } + + + /// + /// 应用编码 + /// + [Display(Name = "应用编码")] + [Required(ErrorMessage = "请输入{0}")] + [StringLength(maximumLength: 50, ErrorMessage = "{0}不能超过{1}字")] + + + public System.String code { get; set; } + + + /// + /// 易联云应用id + /// + [Display(Name = "易联云应用id")] + [Required(ErrorMessage = "请输入{0}")] + [StringLength(maximumLength: 50, ErrorMessage = "{0}不能超过{1}字")] + + + public System.String clientId { get; set; } + + + /// + /// 易联云应用密钥 + /// + [Display(Name = "易联云应用密钥")] + [Required(ErrorMessage = "请输入{0}")] + [StringLength(maximumLength: 50, ErrorMessage = "{0}不能超过{1}字")] + + + public System.String clientSecret { get; set; } + + + /// + /// 易联云终端号 + /// + [Display(Name = "易联云终端号")] + [Required(ErrorMessage = "请输入{0}")] + [StringLength(maximumLength: 50, ErrorMessage = "{0}不能超过{1}字")] + + + public System.String machineCode { get; set; } + + + /// + /// 易联云终端密钥 + /// + [Display(Name = "易联云终端密钥")] + [Required(ErrorMessage = "请输入{0}")] + [StringLength(maximumLength: 50, ErrorMessage = "{0}不能超过{1}字")] + + + public System.String msign { get; set; } + + + /// + /// 打印机名称 + /// + [Display(Name = "打印机名称")] + [Required(ErrorMessage = "请输入{0}")] + [StringLength(maximumLength: 50, ErrorMessage = "{0}不能超过{1}字")] + + + public System.String printerName { get; set; } + + + /// + /// 联系电话 + /// + [Display(Name = "联系电话")] + [Required(ErrorMessage = "请输入{0}")] + [StringLength(maximumLength: 50, ErrorMessage = "{0}不能超过{1}字")] + + + public System.String phone { get; set; } + + + /// + /// 访问令牌,API调用时需要,令牌可以重复使用无失效时间,请开发者全局保存 + /// + [Display(Name = "访问令牌,API调用时需要,令牌可以重复使用无失效时间,请开发者全局保存")] + [StringLength(maximumLength: 50, ErrorMessage = "{0}不能超过{1}字")] + + + public System.String accessToken { get; set; } + + + /// + /// 更新access_token所需,有效时间35天 + /// + [Display(Name = "更新access_token所需,有效时间35天")] + [StringLength(maximumLength: 50, ErrorMessage = "{0}不能超过{1}字")] + + + public System.String refreshToken { get; set; } + + + /// + /// 令牌的有效时间,单位秒 (30天),注:该模式下可忽略此参数 + /// + [Display(Name = "令牌的有效时间,单位秒 (30天),注:该模式下可忽略此参数")] + + + public System.Int32? expiresIn { get; set; } + + + /// + /// 有效期截止时间 + /// + [Display(Name = "有效期截止时间")] + public System.DateTime? expiressEndTime { get; set; } + + + /// + /// 其他参数 + /// + [Display(Name = "其他参数")] + public System.String parameters { get; set; } + + + /// + /// 创建时间 + /// + [Display(Name = "创建时间")] + [Required(ErrorMessage = "请输入{0}")] + + + public System.DateTime createTime { get; set; } + + + /// + /// 是否默认 + /// + [Display(Name = "是否默认")] + [Required(ErrorMessage = "请输入{0}")] + + + public System.Boolean isDefault { get; set; } + + + /// + /// 是否开启 + /// + [Display(Name = "是否开启")] + [Required(ErrorMessage = "请输入{0}")] + + + public System.Boolean isOpen { get; set; } + + + /// + /// 绑定门店 + /// + [Display(Name = "绑定门店")] + [Required(ErrorMessage = "请输入{0}")] + + + public System.Int32 storeId { get; set; } + } +} \ No newline at end of file diff --git a/CoreCms.Net.Model/ViewModels/YiLianYun/YiLianYunConfig.cs b/CoreCms.Net.Model/ViewModels/YiLianYun/YiLianYunConfig.cs new file mode 100644 index 00000000..35572e12 --- /dev/null +++ b/CoreCms.Net.Model/ViewModels/YiLianYun/YiLianYunConfig.cs @@ -0,0 +1,67 @@ +using CoreCms.Net.Model.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreCms.Net.Model.ViewModels.YiLianYun +{ + /// + /// 易联云全局配置 + /// + public static class YiLianYunConfig + { + /// + /// 授权相关地址 + /// + public const string AuthUrl = "https://open-api.10ss.net/oauth/oauth"; + + /// + /// 获取终端状态地址 + + /// + + public const string GetPrintStatusUrl = "https://open-api.10ss.net/printer/getprintstatus"; + + /// + /// 文本打印地址 + /// + + public const string PrintTextUrl = "https://open-api.10ss.net/print/index"; + + /// + /// 小票打印模板 + /// + public static StringBuilder PrintTmpModel(CoreCmsOrder listResult) + { + var printStr = new StringBuilder(); + printStr.Append("
--" + "支付" + "订单--
\r"); + printStr.Append("................................\r"); + printStr.Append("
-- -
\r"); + printStr.Append("下单时间:" + listResult.createTime + "\r"); + printStr.Append("订单编号:" + listResult.orderId + "\r"); + printStr.Append("**************商品**************\r"); + printStr.Append("
--购买明细--
\r"); + + //printStr.Append("
--其他消费--
\r"); + //printStr.Append("餐盒 1 2\r"); + printStr.Append("................................\r"); + printStr.Append("积分抵扣:¥" + listResult.pointMoney + "\r"); + printStr.Append("订单优惠:¥" + listResult.orderDiscountAmount + "\r"); + printStr.Append("商品优惠:¥" + listResult.goodsDiscountAmount + "\r"); + printStr.Append("优惠券:¥" + listResult.couponDiscountAmount + "\r"); + printStr.Append("总价:¥" + listResult.orderAmount + "\r"); + printStr.Append("*******************************\r"); + printStr.Append("区域:" + listResult.shipAreaName + "\r"); + printStr.Append("地址:" + listResult.shipAddress + "\r"); + printStr.Append("联系:" + listResult.shipName + " " + listResult.shipMobile + "\r"); + printStr.Append("***************完结*************\r"); + return printStr; + } + + } + + + +} diff --git a/CoreCms.Net.Model/ViewModels/YiLianYun/YiLianYunParam.cs b/CoreCms.Net.Model/ViewModels/YiLianYun/YiLianYunParam.cs new file mode 100644 index 00000000..516aeae3 --- /dev/null +++ b/CoreCms.Net.Model/ViewModels/YiLianYun/YiLianYunParam.cs @@ -0,0 +1,184 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreCms.Net.Model.ViewModels.YiLianYun +{ + /// + /// 易联云获取accessToken请求实体 + /// + public class YiLianYunParam + { + + /// + /// 易联云颁发给开发者的应用ID 非空值 + /// + public string client_id { get; set; } + + + + /// + /// 授与方式(固定为'client_credentials') + /// + public string grant_type { get; set; } = "client_credentials"; + + /// + /// 签名 详见API文档列表-接口签名 + /// + + public string sign { get; set; } + + /// + /// 授权权限,传all + /// + public string scope { get; set; } = "all"; + + /// + /// 当前服务器时间戳(10位) + /// + public int timestamp { get; set; } + + /// + /// 36位随机用来唯一标记此次调用,响应对象中会包含相同的id。UUID以36字节的字符串表示, + /// + public string id { get; set; } + + } + + /// + /// 使用Refresh token更新Access Token请求实体 + /// + public class RefreshYiLianYunToken + { + + /// + /// 易联云颁发给开发者的应用ID 非空值 + /// + public string client_id { get; set; } + + /// + /// 更新access_token所需 + /// + public string refresh_token { get; set; } + + /// + /// 授与方式(固定为'client_credentials') + /// + public string grant_type { get; set; } = "client_credentials"; + + /// + /// 签名 详见API文档列表-接口签名 + /// + + public string sign { get; set; } + + /// + /// 授权权限,传all + /// + public string scope { get; set; } = "all"; + + /// + /// 当前服务器时间戳(10位) + /// + public int timestamp { get; set; } + + /// + /// 36位随机用来唯一标记此次调用,响应对象中会包含相同的id。UUID以36字节的字符串表示, + /// + public string id { get; set; } + + } + + /// + /// 使用Refresh token更新Access Token请求实体 + /// + public class GetPrintStatusParam + { + + /// + /// 易联云颁发给开发者的应用ID 非空值 + /// + public string client_id { get; set; } + + /// + /// 授权的token 必要参数 + /// + public string access_token { get; set; } + + /// + /// 易联云打印机终端号 + /// + public string machine_code { get; set; } + + /// + /// 签名 详见API文档列表-接口签名 + /// + + public string sign { get; set; } + + /// + /// 当前服务器时间戳(10位) + /// + public int timestamp { get; set; } + + /// + /// 36位随机用来唯一标记此次调用,响应对象中会包含相同的id。UUID以36字节的字符串表示, + /// + public string id { get; set; } + + } + + /// + /// 打印提交数据 + /// + public class WordPrintRespone + { + /// + /// 开发者的应用ID,在开放平台创建应用时获得 + /// + public string client_id { get; set; } + + /// + /// 授权的token 必要参数 + /// + public string access_token { get; set; } + + /// + /// 易联云打印机终端号 + /// + public string machine_code { get; set; } + + /// + /// 打印内容(需要urlencode),排版指令详见打印机指令 + /// + public string content { get; set; } + + /// + /// 为 1 时,origin_id 进行幂等处理,请确定 origin_id 的唯一性 + /// + public int idempotence { get; set; } + + /// + /// 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母 ,且在同一个client_id下唯一。详见商户订单号 + /// + public string origin_id { get; set; } + + /// + /// int + /// + public int timestamp { get; set; } + + /// + /// 签名 详见API文档列表-接口签名 + /// + public string sign { get; set; } + + /// + /// idUUID4 详见API文档列表-uuid4 + /// + public string id { get; set; } + } + +} diff --git a/CoreCms.Net.Model/ViewModels/YiLianYun/YiLianYunResult.cs b/CoreCms.Net.Model/ViewModels/YiLianYun/YiLianYunResult.cs new file mode 100644 index 00000000..af2b950e --- /dev/null +++ b/CoreCms.Net.Model/ViewModels/YiLianYun/YiLianYunResult.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreCms.Net.Model.ViewModels.YiLianYun +{ + /// + /// 易联云授权返回数据 + /// + public class YiLianYunAuthResult + { + /// + /// 返回状态码 + /// + public string error { get; set; } + /// + /// 状态码说明 + /// + public string error_description { get; set; } + + /// + /// 结果集 + /// + public Body body { get; set; } + + /// + /// 结果集详情 + /// + public class Body + { + public string access_token { get; set; } + public string refresh_token { get; set; } + public object machine_code { get; set; } + public int expires_in { get; set; } + public string scope { get; set; } + } + } + + /// + /// 获取机器在线状态 + /// + public class YiLianYunGetPrintStatusResult + { + /// + /// 返回状态码 + /// + public string error { get; set; } + /// + /// 状态码说明 + /// + public string error_description { get; set; } + + /// + /// 结果集 + /// + public Body body { get; set; } + + /// + /// 结果集详情 + /// + public class Body + { + public string state { get; set; } + } + } + + /// + /// 文本打印返回结果集 + /// + public class YiLianYunGetPrintTextResult + { + /// + /// 返回状态码 + /// + public string error { get; set; } + /// + /// 状态码说明 + /// + public string error_description { get; set; } + + /// + /// 结果集 + /// + public Body body { get; set; } + + /// + /// 结果集详情 + /// + public class Body + { + /// + /// 订单号 + /// + public string id { get; set; } + public string origin_id { get; set; } + } + } + +} diff --git a/CoreCms.Net.RedisMQ/Subscribe/AfterSalesReviewForPointSubscribe.cs b/CoreCms.Net.RedisMQ/AfterSalesReviewForPointSubscribe.cs similarity index 99% rename from CoreCms.Net.RedisMQ/Subscribe/AfterSalesReviewForPointSubscribe.cs rename to CoreCms.Net.RedisMQ/AfterSalesReviewForPointSubscribe.cs index 61fd63f0..a9a41d0a 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/AfterSalesReviewForPointSubscribe.cs +++ b/CoreCms.Net.RedisMQ/AfterSalesReviewForPointSubscribe.cs @@ -12,7 +12,7 @@ using InitQ.Attributes; using Microsoft.Extensions.DependencyInjection; using SqlSugar; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 售后审核通过后对积分的返还处理 diff --git a/CoreCms.Net.RedisMQ/Subscribe/AfterSalesReviewSubscribe.cs b/CoreCms.Net.RedisMQ/AfterSalesReviewSubscribe.cs similarity index 98% rename from CoreCms.Net.RedisMQ/Subscribe/AfterSalesReviewSubscribe.cs rename to CoreCms.Net.RedisMQ/AfterSalesReviewSubscribe.cs index 8a3d1cfe..92683ca2 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/AfterSalesReviewSubscribe.cs +++ b/CoreCms.Net.RedisMQ/AfterSalesReviewSubscribe.cs @@ -13,7 +13,7 @@ using InitQ.Attributes; using Microsoft.Extensions.Logging; using Newtonsoft.Json; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 售后审核通过后处理 diff --git a/CoreCms.Net.RedisMQ/Subscribe/AliPayNoticeSubscribe.cs b/CoreCms.Net.RedisMQ/AliPayNoticeSubscribe.cs similarity index 98% rename from CoreCms.Net.RedisMQ/Subscribe/AliPayNoticeSubscribe.cs rename to CoreCms.Net.RedisMQ/AliPayNoticeSubscribe.cs index 4b9b5d12..5ff1b78c 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/AliPayNoticeSubscribe.cs +++ b/CoreCms.Net.RedisMQ/AliPayNoticeSubscribe.cs @@ -19,7 +19,7 @@ using InitQ.Abstractions; using InitQ.Attributes; using Newtonsoft.Json; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 支付宝支付成功后推送到接口进行数据处理 diff --git a/CoreCms.Net.RedisMQ/CoreCms.Net.RedisMQ.csproj b/CoreCms.Net.RedisMQ/CoreCms.Net.RedisMQ.csproj index fc0dd200..f4a31e55 100644 --- a/CoreCms.Net.RedisMQ/CoreCms.Net.RedisMQ.csproj +++ b/CoreCms.Net.RedisMQ/CoreCms.Net.RedisMQ.csproj @@ -8,7 +8,6 @@ - diff --git a/CoreCms.Net.RedisMQ/Subscribe/DemoSubscribe.cs b/CoreCms.Net.RedisMQ/DemoSubscribe.cs similarity index 95% rename from CoreCms.Net.RedisMQ/Subscribe/DemoSubscribe.cs rename to CoreCms.Net.RedisMQ/DemoSubscribe.cs index 2868e59d..8ab8e2df 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/DemoSubscribe.cs +++ b/CoreCms.Net.RedisMQ/DemoSubscribe.cs @@ -5,7 +5,7 @@ using InitQ.Abstractions; using InitQ.Attributes; using NLog; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { public class DemoSubscribe : IRedisSubscribe { diff --git a/CoreCms.Net.RedisMQ/Subscribe/MessagePushSubscribe.cs b/CoreCms.Net.RedisMQ/MessagePushSubscribe.cs similarity index 98% rename from CoreCms.Net.RedisMQ/Subscribe/MessagePushSubscribe.cs rename to CoreCms.Net.RedisMQ/MessagePushSubscribe.cs index 9cddb6b1..28096171 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/MessagePushSubscribe.cs +++ b/CoreCms.Net.RedisMQ/MessagePushSubscribe.cs @@ -22,7 +22,7 @@ using InitQ.Abstractions; using InitQ.Attributes; using Newtonsoft.Json; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 消息推送 diff --git a/CoreCms.Net.RedisMQ/Subscribe/OrderAgentOrDistributionSubscribe.cs b/CoreCms.Net.RedisMQ/OrderAgentOrDistributionSubscribe.cs similarity index 99% rename from CoreCms.Net.RedisMQ/Subscribe/OrderAgentOrDistributionSubscribe.cs rename to CoreCms.Net.RedisMQ/OrderAgentOrDistributionSubscribe.cs index 56bf8439..393e9d64 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/OrderAgentOrDistributionSubscribe.cs +++ b/CoreCms.Net.RedisMQ/OrderAgentOrDistributionSubscribe.cs @@ -14,7 +14,7 @@ using InitQ.Attributes; using Microsoft.Extensions.Logging; using Newtonsoft.Json; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 订单完结后走代理或分销商提成处理 diff --git a/CoreCms.Net.RedisMQ/Subscribe/OrderAutomaticDeliverySubscribe.cs b/CoreCms.Net.RedisMQ/OrderAutomaticDeliverySubscribe.cs similarity index 98% rename from CoreCms.Net.RedisMQ/Subscribe/OrderAutomaticDeliverySubscribe.cs rename to CoreCms.Net.RedisMQ/OrderAutomaticDeliverySubscribe.cs index 4f8260fc..285a5ae2 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/OrderAutomaticDeliverySubscribe.cs +++ b/CoreCms.Net.RedisMQ/OrderAutomaticDeliverySubscribe.cs @@ -16,7 +16,7 @@ using InitQ.Attributes; using Microsoft.Extensions.Logging; using Newtonsoft.Json; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 门店订单自动发货 diff --git a/CoreCms.Net.RedisMQ/Subscribe/OrderFinishCommandSubscribe.cs b/CoreCms.Net.RedisMQ/OrderFinishCommandSubscribe.cs similarity index 98% rename from CoreCms.Net.RedisMQ/Subscribe/OrderFinishCommandSubscribe.cs rename to CoreCms.Net.RedisMQ/OrderFinishCommandSubscribe.cs index 8555e406..7163dcd2 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/OrderFinishCommandSubscribe.cs +++ b/CoreCms.Net.RedisMQ/OrderFinishCommandSubscribe.cs @@ -13,7 +13,7 @@ using InitQ.Attributes; using Microsoft.Extensions.Logging; using Newtonsoft.Json; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 订单完成时,结算该订单 diff --git a/CoreCms.Net.RedisMQ/OrderPrintSubscribe.cs b/CoreCms.Net.RedisMQ/OrderPrintSubscribe.cs new file mode 100644 index 00000000..bd60ebb0 --- /dev/null +++ b/CoreCms.Net.RedisMQ/OrderPrintSubscribe.cs @@ -0,0 +1,266 @@ +using System; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CoreCms.Net.Configuration; +using CoreCms.Net.IServices; +using CoreCms.Net.Loging; +using CoreCms.Net.Model.Entities; +using CoreCms.Net.Model.ViewModels.YiLianYun; +using CoreCms.Net.Utility.Helper; +using Flurl.Http; +using InitQ.Abstractions; +using InitQ.Attributes; +using Newtonsoft.Json; + +namespace CoreCms.Net.RedisMQ +{ + public class OrderPrintSubscribe : IRedisSubscribe + { + private readonly ICoreCmsOrderItemServices _orderItemServices; + private readonly ICoreCmsAreaServices _areaServices; + private readonly ICoreCmsPrinterServices _coreCmsPrinterServices; + + + public OrderPrintSubscribe(ICoreCmsOrderItemServices orderItemServices, ICoreCmsAreaServices areaServices, ICoreCmsPrinterServices coreCmsPrinterServices) + { + _orderItemServices = orderItemServices; + _areaServices = areaServices; + _coreCmsPrinterServices = coreCmsPrinterServices; + } + + /// + /// 订单打印队列 + /// + /// + /// + [Subscribe(RedisMessageQueueKey.OrderPrint)] + private async Task OrderPrint(string msg) + { + try + { + var order = JsonConvert.DeserializeObject(msg); + if (order == null) + { + NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单打印队列", "订单获取失败"); + return; + } + CoreCmsPrinter model = null; + if (order.storeId > 0) + { + model = await _coreCmsPrinterServices.QueryByClauseAsync(p => p.storeId == order.storeId && p.isOpen == true, true, true); + } + model ??= await _coreCmsPrinterServices.QueryByClauseAsync(p => p.isDefault == true && p.isOpen == true, true, true); + + if (model == null) + { + NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单打印队列", "打印机获取失败"); + return; + } + + var isNeedToken = false; + if (string.IsNullOrEmpty(model.accessToken) || model.expiressEndTime == null) + { + isNeedToken = true; + } + else + { + //判断是否过期 + var dt = DateTime.Now; + if (dt >= model.expiressEndTime) + { + var ts = dt - Convert.ToDateTime(model.expiressEndTime); + if (ts.Days > 35) + { + isNeedToken = true; + } + else + { + RefreshYiLianYunToken refreshToken = new RefreshYiLianYunToken + { + client_id = model.clientId, + grant_type = "client_credentials", + timestamp = CommonHelper.GetDateTimeStamp(DateTime.Now), + scope = "all", + id = Guid.NewGuid().ToString() + }; + refreshToken.sign = CommonHelper.Md5For32((refreshToken.client_id + refreshToken.timestamp + model.clientSecret).ToLowerInvariant()).ToLowerInvariant(); + var resultData = await YiLianYunConfig.AuthUrl.PostJsonAsync(refreshToken).ReceiveJson(); + //将获取到的数据存入数据库 + if (resultData.error == "0") + { + model.accessToken = resultData.body.access_token; + model.refreshToken = resultData.body.refresh_token; + model.expiresIn = resultData.body.expires_in; + model.expiressEndTime = DateTime.Now.AddSeconds(resultData.body.expires_in); + + await _coreCmsPrinterServices.UpdateAsync( + p => new CoreCmsPrinter() + { + accessToken = resultData.body.access_token, + refreshToken = resultData.body.refresh_token, + expiresIn = resultData.body.expires_in, + expiressEndTime = model.expiressEndTime, + parameters = JsonConvert.SerializeObject(resultData.body) + }, p => p.clientId == model.clientId && p.clientSecret == model.clientSecret, true); + + } + else + { + NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单打印队列", "刷新AccessToken:" + resultData.error_description); + return; + } + } + } + } + + if (isNeedToken) + { + var getToken = new YiLianYunParam + { + client_id = model.clientId, + grant_type = "client_credentials", + timestamp = CommonHelper.GetDateTimeStamp(DateTime.Now), + scope = "all", + id = Guid.NewGuid().ToString() + }; + getToken.sign = CommonHelper.Md5For32((getToken.client_id + getToken.timestamp + model.clientSecret).ToLowerInvariant()).ToLowerInvariant(); + + var resultData = await YiLianYunConfig.AuthUrl.PostJsonAsync(getToken).ReceiveJson(); + //将获取到的数据存入数据库 + if (resultData.error == "0") + { + model.accessToken = resultData.body.access_token; + model.refreshToken = resultData.body.refresh_token; + model.expiresIn = resultData.body.expires_in; + model.expiressEndTime = DateTime.Now.AddSeconds(resultData.body.expires_in); + + await _coreCmsPrinterServices.UpdateAsync( + p => new CoreCmsPrinter() + { + accessToken = resultData.body.access_token, + refreshToken = resultData.body.refresh_token, + expiresIn = resultData.body.expires_in, + expiressEndTime = model.expiressEndTime, + parameters = JsonConvert.SerializeObject(resultData.body) + }, p => p.clientId == model.clientId && p.clientSecret == model.clientSecret, true); + + } + else + { + NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单打印队列", "获取AccessToken:" + resultData.error_description); + return; + } + } + + //获取打印机是否在线 + var statusParam = new GetPrintStatusParam + { + client_id = model.clientId, + access_token = model.accessToken, + machine_code = model.machineCode, + timestamp = CommonHelper.GetDateTimeStamp(DateTime.Now), + id = Guid.NewGuid().ToString() + }; + statusParam.sign = CommonHelper.Md5For32((statusParam.client_id + statusParam.timestamp + model.clientSecret).ToLowerInvariant()).ToLowerInvariant(); + + var getPrintStatusResult = await YiLianYunConfig.GetPrintStatusUrl.PostJsonAsync(statusParam).ReceiveJson(); + if (getPrintStatusResult.error != "0") + { + NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单打印队列", "获取打印机在线状态:" + getPrintStatusResult.error_description); + return; + } + else + { + switch (getPrintStatusResult.body.state) + { + case "0": + NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单打印队列", "获取打印机在线状态:机器未在线"); + return; + case "2": + NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单打印队列", "机器缺纸"); + return; + } + + var payStr = EnumHelper.GetEnumDescriptionByKey(order.paymentCode); + var items = await _orderItemServices.QueryListByClauseAsync(p => p.orderId == order.orderId); + var areas = await _areaServices.GetAreaFullName(order.shipAreaId); + order.shipAreaName = areas.status ? areas.data + "" : ""; + + var receiptType = order.receiptType switch + { + (int)GlobalEnumVars.OrderReceiptType.IntraCityService => "同城配送", + (int)GlobalEnumVars.OrderReceiptType.Logistics => "物流快递", + (int)GlobalEnumVars.OrderReceiptType.SelfDelivery => "门店自提", + _ => string.Empty + }; + + var printStr = new StringBuilder(); + printStr.Append("
--" + receiptType + "订单--
\r"); + printStr.Append("................................\r"); + printStr.Append("
--" + payStr + "--
\r"); + printStr.Append("下单时间:" + order.createTime.ToString("yyyy-MM-dd HH:mm:ss") + "\r"); + printStr.Append("订单编号:" + order.orderId + "\r"); + printStr.Append("**************商品**************\r"); + printStr.Append("
--购买明细--
\r"); + + if (items != null && items.Any()) + { + foreach (var item in items) + { + printStr.Append(item.name + "*" + item.nums + "\r"); + } + } + //printStr.Append("
--其他消费--
\r"); + //printStr.Append("餐盒 1 2\r"); + printStr.Append("................................\r"); + printStr.Append("积分抵扣:¥" + order.pointMoney + "\r"); + printStr.Append("订单优惠:¥" + order.orderDiscountAmount + "\r"); + printStr.Append("商品优惠:¥" + order.goodsDiscountAmount + "\r"); + printStr.Append("优惠券:¥" + order.couponDiscountAmount + "\r"); + printStr.Append("总价:¥" + order.orderAmount + "\r"); + printStr.Append("*******************************\r"); + printStr.Append("区域:" + order.shipAreaName + "\r"); + printStr.Append("地址:" + order.shipAddress + "\r"); + printStr.Append("联系:" + order.shipName + " " + order.shipMobile + "\r"); + printStr.Append("***************完结*************\r"); + + //小票打印 + WordPrintRespone wordPrintRespone = new WordPrintRespone + { + client_id = model.clientId, + access_token = model.accessToken, + machine_code = model.machineCode, + content = printStr.ToString(), + origin_id = order.orderId, + timestamp = CommonHelper.GetDateTimeStamp(DateTime.Now) + }; + wordPrintRespone.sign = CommonHelper + .Md5For32((wordPrintRespone.client_id + wordPrintRespone.timestamp + model.clientSecret) + .ToLowerInvariant()).ToLowerInvariant(); + wordPrintRespone.id = Guid.NewGuid().ToString(); + + //打印文本:缺少参数!请检查参数信息!!或更改下请求头:Content-Type:application/x-www-form-urlencoded + var resultData = await YiLianYunConfig.PrintTextUrl + .WithHeader("Content-Type", "application/x-www-form-urlencoded") + .PostUrlEncodedAsync(wordPrintRespone).ReceiveJson(); + //当token返回失败时 + if (resultData.error != "0") + { + NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单打印队列", "打印文本:" + resultData.error_description); + } + else + { + NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单打印队列", "打印文本:打印成功"); + } + } + } + catch (Exception ex) + { + NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "订单打印队列", msg, ex); + } + await Task.CompletedTask; + } + + } +} diff --git a/CoreCms.Net.RedisMQ/Subscribe/SendWxTemplateMessageSubscribe.cs b/CoreCms.Net.RedisMQ/SendWxTemplateMessageSubscribe.cs similarity index 99% rename from CoreCms.Net.RedisMQ/Subscribe/SendWxTemplateMessageSubscribe.cs rename to CoreCms.Net.RedisMQ/SendWxTemplateMessageSubscribe.cs index bb5fb543..ab59d229 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/SendWxTemplateMessageSubscribe.cs +++ b/CoreCms.Net.RedisMQ/SendWxTemplateMessageSubscribe.cs @@ -17,7 +17,7 @@ using Newtonsoft.Json.Linq; using SKIT.FlurlHttpClient.Wechat.Api; using SKIT.FlurlHttpClient.Wechat.Api.Models; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 微信模板消息【小程序,公众号都走这里】 diff --git a/CoreCms.Net.RedisMQ/Subscribe/OrderPrintSubscribe.cs b/CoreCms.Net.RedisMQ/Subscribe/OrderPrintSubscribe.cs deleted file mode 100644 index 5cf496c8..00000000 --- a/CoreCms.Net.RedisMQ/Subscribe/OrderPrintSubscribe.cs +++ /dev/null @@ -1,226 +0,0 @@ -using System; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using CoreCms.Net.Configuration; -using CoreCms.Net.IServices; -using CoreCms.Net.Loging; -using CoreCms.Net.Model.Entities; -using CoreCms.Net.Utility.Helper; -using InitQ.Abstractions; -using InitQ.Attributes; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Qc.YilianyunSdk; -using LogLevel = NLog.LogLevel; - -namespace CoreCms.Net.RedisMQ.Subscribe -{ - public class OrderPrintSubscribe : IRedisSubscribe - { - private readonly YilianyunService _yilianyunService; - private readonly ICoreCmsApiAccessTokenServices _accessTokenServices; - private readonly ICoreCmsOrderItemServices _orderItemServices; - private readonly ICoreCmsAreaServices _areaServices; - - private readonly string _machineCode = AppSettingsConstVars.YiLianYunConfigMachineCode; //设备号 - private readonly string _msign = AppSettingsConstVars.YiLianYunConfigMsign;// 终端密钥 - private readonly string _printerName = AppSettingsConstVars.YiLianYunConfigPrinterName; // 打印机名称 - private readonly string _phone = AppSettingsConstVars.YiLianYunConfigPhone; //手机卡号 - private readonly bool _enabled = AppSettingsConstVars.YiLianYunConfigEnabled; //是否开启 - - - public OrderPrintSubscribe(YilianyunService yilianyunService, ICoreCmsApiAccessTokenServices accessTokenServices, ICoreCmsOrderItemServices orderItemServices, ICoreCmsAreaServices areaServices) - { - _yilianyunService = yilianyunService; - _accessTokenServices = accessTokenServices; - _orderItemServices = orderItemServices; - _areaServices = areaServices; - } - - /// - /// 订单打印队列 - /// - /// - /// - [Subscribe(RedisMessageQueueKey.OrderPrint)] - private async Task OrderPrint(string msg) - { - try - { - if (_enabled == false) - { - NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单打印队列", "打印机未开启"); - return; - } - var order = JsonConvert.DeserializeObject(msg); - if (order == null) - { - NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单打印队列", "订单获取失败"); - return; - } - - var accessModel = await _accessTokenServices.QueryByClauseAsync(p => - p.code == GlobalEnumVars.ThirdPartyEquipment.YiLianYun.ToString() && p.machineCode == _machineCode); - string accessToken; - if (accessModel == null) - { - var onPostAuthTerminal = _yilianyunService.AuthTerminal(_machineCode, _msign, _phone, _printerName); - if (onPostAuthTerminal.IsSuccess()) - { - accessToken = onPostAuthTerminal.Body.Access_Token; - - accessModel = new CoreCmsApiAccessToken(); - accessModel.code = GlobalEnumVars.ThirdPartyEquipment.YiLianYun.ToString(); - accessModel.name = EnumHelper.GetEnumDescriptionByKey(GlobalEnumVars.ThirdPartyEquipment.YiLianYun.ToString()); - accessModel.machineCode = _machineCode; - accessModel.accessToken = onPostAuthTerminal.Body.Access_Token; - accessModel.refreshToken = onPostAuthTerminal.Body.Refresh_Token; - accessModel.expiresIn = onPostAuthTerminal.Body.Expires_In != null ? Convert.ToInt32(onPostAuthTerminal.Body.Expires_In) : 0; - accessModel.expiressEndTime = onPostAuthTerminal.Body.ExpiressEndTime; - accessModel.parameters = JsonConvert.SerializeObject(onPostAuthTerminal.Body); - accessModel.createTime = DateTime.Now; - - await _accessTokenServices.InsertAsync(accessModel); - } - else - { - NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "易联云重新获取Token失败", JsonConvert.SerializeObject(onPostAuthTerminal)); - return; - } - } - else - { - //判断是否过期 - var dt = DateTime.Now; - if (dt >= accessModel.expiressEndTime) - { - var ts = dt - Convert.ToDateTime(accessModel.expiressEndTime); - - if (ts.Days > 35) - { - - var onPostAuthTerminal = _yilianyunService.AuthTerminal(_machineCode, _msign, _phone, _printerName); - if (onPostAuthTerminal.IsSuccess()) - { - accessToken = onPostAuthTerminal.Body.Access_Token; - - accessModel.code = GlobalEnumVars.ThirdPartyEquipment.YiLianYun.ToString(); - accessModel.name = EnumHelper.GetEnumDescriptionByKey(GlobalEnumVars.ThirdPartyEquipment.YiLianYun.ToString()); - accessModel.machineCode = _machineCode; - accessModel.accessToken = onPostAuthTerminal.Body.Access_Token; - accessModel.refreshToken = onPostAuthTerminal.Body.Refresh_Token; - accessModel.expiresIn = onPostAuthTerminal.Body.Expires_In != null ? Convert.ToInt32(onPostAuthTerminal.Body.Expires_In) : 0; - accessModel.expiressEndTime = onPostAuthTerminal.Body.ExpiressEndTime; - accessModel.parameters = JsonConvert.SerializeObject(onPostAuthTerminal.Body); - accessModel.createTime = DateTime.Now; - - await _accessTokenServices.UpdateAsync(accessModel); - } - else - { - NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "易联云重新获取Token失败", JsonConvert.SerializeObject(onPostAuthTerminal)); - return; - } - } - else - { - var result = _yilianyunService.RefreshToken(accessModel.machineCode, accessModel.refreshToken); - if (result.IsSuccess()) - { - accessToken = result.Body.Access_Token; - - accessModel.accessToken = result.Body.Access_Token; - accessModel.refreshToken = result.Body.Refresh_Token; - accessModel.expiresIn = result.Body.Expires_In != null ? Convert.ToInt32(result.Body.Expires_In) : 0; - accessModel.expiressEndTime = result.Body.ExpiressEndTime; - await _accessTokenServices.UpdateAsync(accessModel); - } - else - { - NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "易联云更新Token失败", JsonConvert.SerializeObject(result)); - return; - } - } - } - else - { - accessToken = accessModel.accessToken; - } - } - //获取打印机是否在线 - var printerStatus = string.Empty; - var resultOnline = _yilianyunService.PrinterGetStatus(accessModel.accessToken, accessModel.machineCode); - if (resultOnline.IsSuccess()) - { - printerStatus = resultOnline.Body.State.ToString(); - } - if (printerStatus == "在线") - { - var payStr = EnumHelper.GetEnumDescriptionByKey(order.paymentCode); - var items = await _orderItemServices.QueryListByClauseAsync(p => p.orderId == order.orderId); - var areas = await _areaServices.GetAreaFullName(order.shipAreaId); - order.shipAreaName = areas.status ? areas.data + "" : ""; - - var receiptType = string.Empty; - if (order.receiptType == (int)GlobalEnumVars.OrderReceiptType.IntraCityService) - { - receiptType = "同城配送"; - } - else if (order.receiptType == (int)GlobalEnumVars.OrderReceiptType.Logistics) - { - receiptType = "物流快递"; - } - else if (order.receiptType == (int)GlobalEnumVars.OrderReceiptType.SelfDelivery) - { - receiptType = "门店自提"; - } - - var printStr = new StringBuilder(); - printStr.Append("
--" + receiptType + "订单--
\r"); - printStr.Append("................................\r"); - printStr.Append("
--" + payStr + "--
\r"); - printStr.Append("下单时间:" + order.createTime.ToString("yyyy-MM-dd HH:mm:ss") + "\r"); - printStr.Append("订单编号:" + order.orderId + "\r"); - printStr.Append("**************商品**************\r"); - printStr.Append("
--购买明细--
\r"); - - if (items != null && items.Any()) - { - foreach (var item in items) - { - printStr.Append(item.name + "*" + item.nums + "\r"); - } - } - //printStr.Append("
--其他消费--
\r"); - //printStr.Append("餐盒 1 2\r"); - printStr.Append("................................\r"); - printStr.Append("积分抵扣:¥" + order.pointMoney + "\r"); - printStr.Append("订单优惠:¥" + order.orderDiscountAmount + "\r"); - printStr.Append("商品优惠:¥" + order.goodsDiscountAmount + "\r"); - printStr.Append("优惠券:¥" + order.couponDiscountAmount + "\r"); - printStr.Append("总价:¥" + order.orderAmount + "\r"); - printStr.Append("*******************************\r"); - printStr.Append("区域:" + order.shipAreaName + "\r"); - printStr.Append("地址:" + order.shipAddress + "\r"); - printStr.Append("联系:" + order.shipName + " " + order.shipMobile + "\r"); - printStr.Append("***************完结*************\r"); - var onPostPrintText = _yilianyunService.PrintText(accessToken, _machineCode, printStr.ToString()); - - NLogUtil.WriteAll(NLog.LogLevel.Trace, LogType.RedisMessageQueue, "易联云打印结果", JsonConvert.SerializeObject(onPostPrintText)); - } - else - { - NLogUtil.WriteAll(LogLevel.Trace, LogType.RedisMessageQueue, "易联云机器离线", JsonConvert.SerializeObject(resultOnline)); - } - } - catch (Exception ex) - { - NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "订单打印队列", msg, ex); - throw; - } - await Task.CompletedTask; - } - - } -} diff --git a/CoreCms.Net.RedisMQ/Subscribe/TCOrderAfterSaleCreateSyncSubscribe.cs b/CoreCms.Net.RedisMQ/TCOrderAfterSaleCreateSyncSubscribe.cs similarity index 99% rename from CoreCms.Net.RedisMQ/Subscribe/TCOrderAfterSaleCreateSyncSubscribe.cs rename to CoreCms.Net.RedisMQ/TCOrderAfterSaleCreateSyncSubscribe.cs index 4567b336..e3bb91b4 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/TCOrderAfterSaleCreateSyncSubscribe.cs +++ b/CoreCms.Net.RedisMQ/TCOrderAfterSaleCreateSyncSubscribe.cs @@ -25,7 +25,7 @@ using Newtonsoft.Json; using SKIT.FlurlHttpClient.Wechat.Api; using SKIT.FlurlHttpClient.Wechat.Api.Models; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 自定义交易组件-同步创建售后单 diff --git a/CoreCms.Net.RedisMQ/Subscribe/TCOrderDeliveryRecieveSyncSubscribe.cs b/CoreCms.Net.RedisMQ/TCOrderDeliveryRecieveSyncSubscribe.cs similarity index 99% rename from CoreCms.Net.RedisMQ/Subscribe/TCOrderDeliveryRecieveSyncSubscribe.cs rename to CoreCms.Net.RedisMQ/TCOrderDeliveryRecieveSyncSubscribe.cs index 5979645e..c7c1b6aa 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/TCOrderDeliveryRecieveSyncSubscribe.cs +++ b/CoreCms.Net.RedisMQ/TCOrderDeliveryRecieveSyncSubscribe.cs @@ -24,7 +24,7 @@ using NLog; using SKIT.FlurlHttpClient.Wechat.Api; using SKIT.FlurlHttpClient.Wechat.Api.Models; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 自定义交易组件-同步订单确认收货 diff --git a/CoreCms.Net.RedisMQ/Subscribe/TCOrderShipSyncSubscribe.cs b/CoreCms.Net.RedisMQ/TCOrderShipSyncSubscribe.cs similarity index 99% rename from CoreCms.Net.RedisMQ/Subscribe/TCOrderShipSyncSubscribe.cs rename to CoreCms.Net.RedisMQ/TCOrderShipSyncSubscribe.cs index 4e9ec13b..79405761 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/TCOrderShipSyncSubscribe.cs +++ b/CoreCms.Net.RedisMQ/TCOrderShipSyncSubscribe.cs @@ -23,7 +23,7 @@ using Newtonsoft.Json; using SKIT.FlurlHttpClient.Wechat.Api; using SKIT.FlurlHttpClient.Wechat.Api.Models; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 自定义交易组件-同步发货信息 diff --git a/CoreCms.Net.RedisMQ/Subscribe/TCPayOrderSyncSubscribe.cs b/CoreCms.Net.RedisMQ/TCPayOrderSyncSubscribe.cs similarity index 99% rename from CoreCms.Net.RedisMQ/Subscribe/TCPayOrderSyncSubscribe.cs rename to CoreCms.Net.RedisMQ/TCPayOrderSyncSubscribe.cs index c240431b..01cb761e 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/TCPayOrderSyncSubscribe.cs +++ b/CoreCms.Net.RedisMQ/TCPayOrderSyncSubscribe.cs @@ -23,7 +23,7 @@ using Newtonsoft.Json; using SKIT.FlurlHttpClient.Wechat.Api; using SKIT.FlurlHttpClient.Wechat.Api.Models; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 自定义交易组件-同步订单状态(弃用,新版已经取消了同步) diff --git a/CoreCms.Net.RedisMQ/Subscribe/UserSubscribe.cs b/CoreCms.Net.RedisMQ/UserSubscribe.cs similarity index 99% rename from CoreCms.Net.RedisMQ/Subscribe/UserSubscribe.cs rename to CoreCms.Net.RedisMQ/UserSubscribe.cs index cd09e62c..e2939065 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/UserSubscribe.cs +++ b/CoreCms.Net.RedisMQ/UserSubscribe.cs @@ -21,7 +21,7 @@ using InitQ.Attributes; using Newtonsoft.Json; using SqlSugar; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 用户相关队列操作 diff --git a/CoreCms.Net.RedisMQ/Subscribe/WeChatPayNoticeSubscribe.cs b/CoreCms.Net.RedisMQ/WeChatPayNoticeSubscribe.cs similarity index 98% rename from CoreCms.Net.RedisMQ/Subscribe/WeChatPayNoticeSubscribe.cs rename to CoreCms.Net.RedisMQ/WeChatPayNoticeSubscribe.cs index 57b7056b..fb421254 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/WeChatPayNoticeSubscribe.cs +++ b/CoreCms.Net.RedisMQ/WeChatPayNoticeSubscribe.cs @@ -13,7 +13,7 @@ using InitQ.Attributes; using Microsoft.Extensions.Logging; using Newtonsoft.Json; -namespace CoreCms.Net.RedisMQ.Subscribe +namespace CoreCms.Net.RedisMQ { /// /// 微信支付成功后推送到接口进行数据处理 diff --git a/CoreCms.Net.Repository/Api/CoreCmsPrinterRepository.cs b/CoreCms.Net.Repository/Api/CoreCmsPrinterRepository.cs new file mode 100644 index 00000000..b51aff62 --- /dev/null +++ b/CoreCms.Net.Repository/Api/CoreCmsPrinterRepository.cs @@ -0,0 +1,209 @@ +/*********************************************************************** + * Project: CoreCms + * ProjectName: 核心内容管理系统 + * Web: https://www.corecms.net + * Author: 大灰灰 + * Email: jianweie@163.com + * CreateTime: 2022/9/16 20:41:09 + * Description: 暂无 + ***********************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; +using CoreCms.Net.Caching.Manual; +using CoreCms.Net.Configuration; +using CoreCms.Net.Model.Entities; +using CoreCms.Net.Model.ViewModels.Basics; +using CoreCms.Net.IRepository; +using CoreCms.Net.IRepository.UnitOfWork; +using CoreCms.Net.Model.ViewModels.UI; +using SqlSugar; + +namespace CoreCms.Net.Repository +{ + /// + /// 打印机列表 接口实现 + /// + public class CoreCmsPrinterRepository : BaseRepository, ICoreCmsPrinterRepository + { + private readonly IUnitOfWork _unitOfWork; + public CoreCmsPrinterRepository(IUnitOfWork unitOfWork) : base(unitOfWork) + { + _unitOfWork = unitOfWork; + } + + #region 实现重写增删改查操作========================================================== + + /// + /// 重写异步插入方法 + /// + /// 实体数据 + /// + public async Task InsertAsync(CoreCmsPrinter entity) + { + var jm = new AdminUiCallBack(); + entity.createTime = DateTime.Now; + var bl = await DbClient.Insertable(entity).RemoveDataCache().ExecuteReturnIdentityAsync() > 0; + jm.code = bl ? 0 : 1; + jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure; + + return jm; + } + + /// + /// 重写异步更新方法 + /// + /// + /// + public async Task UpdateAsync(CoreCmsPrinter entity) + { + var jm = new AdminUiCallBack(); + + var oldModel = await DbClient.Queryable().In(entity.id).SingleAsync(); + if (oldModel == null) + { + jm.msg = "不存在此信息"; + return jm; + } + //事物处理过程开始 + //oldModel.id = entity.id; + oldModel.name = entity.name; + oldModel.code = entity.code; + oldModel.clientId = entity.clientId; + oldModel.clientSecret = entity.clientSecret; + oldModel.machineCode = entity.machineCode; + oldModel.msign = entity.msign; + oldModel.printerName = entity.printerName; + oldModel.phone = entity.phone; + //oldModel.accessToken = entity.accessToken; + //oldModel.refreshToken = entity.refreshToken; + //oldModel.expiresIn = entity.expiresIn; + //oldModel.expiressEndTime = entity.expiressEndTime; + //oldModel.parameters = entity.parameters; + //oldModel.createTime = entity.createTime; + oldModel.isDefault = entity.isDefault; + oldModel.isOpen = entity.isOpen; + oldModel.storeId = entity.storeId; + + //事物处理过程结束 + var bl = await DbClient.Updateable(oldModel).RemoveDataCache().ExecuteCommandHasChangeAsync(); + jm.code = bl ? 0 : 1; + jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure; + + return jm; + } + + /// + /// 重写删除指定ID的数据 + /// + /// + /// + public async Task DeleteByIdAsync(object id) + { + var jm = new AdminUiCallBack(); + + var bl = await DbClient.Deleteable(id).RemoveDataCache().ExecuteCommandHasChangeAsync(); + jm.code = bl ? 0 : 1; + jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure; + + return jm; + } + + #endregion + + #region 获取缓存的所有数据========================================================== + + /// + /// 获取缓存的所有数据 + /// + /// + public async Task> GetCaChe() + { + var cache = await DbClient.Queryable().With(SqlWith.NoLock).WithCache().ToListAsync(); + return cache; + } + + #endregion + + + #region 重写根据条件查询分页数据 + /// + /// 重写根据条件查询分页数据 + /// + /// 判断集合 + /// 排序方式 + /// 当前页面索引 + /// 分布大小 + /// + /// 是否使用WITH(NOLOCK) + /// + public async Task> QueryPageAsync(Expression> predicate, + Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1, + int pageSize = 20, bool blUseNoLock = false) + { + RefAsync totalCount = 0; + List page; + if (blUseNoLock) + { + page = await DbClient.Queryable() + .OrderByIF(orderByExpression != null, orderByExpression, orderByType) + .WhereIF(predicate != null, predicate).Select(p => new CoreCmsPrinter + { + id = p.id, + name = p.name, + code = p.code, + clientId = p.clientId, + clientSecret = p.clientSecret, + machineCode = p.machineCode, + msign = p.msign, + printerName = p.printerName, + phone = p.phone, + accessToken = p.accessToken, + refreshToken = p.refreshToken, + expiresIn = p.expiresIn, + expiressEndTime = p.expiressEndTime, + parameters = p.parameters, + createTime = p.createTime, + isDefault = p.isDefault, + isOpen = p.isOpen, + storeId = p.storeId, + + }).With(SqlWith.NoLock).ToPageListAsync(pageIndex, pageSize, totalCount); + } + else + { + page = await DbClient.Queryable() + .OrderByIF(orderByExpression != null, orderByExpression, orderByType) + .WhereIF(predicate != null, predicate).Select(p => new CoreCmsPrinter + { + id = p.id, + name = p.name, + code = p.code, + clientId = p.clientId, + clientSecret = p.clientSecret, + machineCode = p.machineCode, + msign = p.msign, + printerName = p.printerName, + phone = p.phone, + accessToken = p.accessToken, + refreshToken = p.refreshToken, + expiresIn = p.expiresIn, + expiressEndTime = p.expiressEndTime, + parameters = p.parameters, + createTime = p.createTime, + isDefault = p.isDefault, + isOpen = p.isOpen, + storeId = p.storeId, + + }).ToPageListAsync(pageIndex, pageSize, totalCount); + } + var list = new PageList(page, pageIndex, pageSize, totalCount); + return list; + } + + #endregion + + } +} diff --git a/CoreCms.Net.Services/Api/CoreCmsPrinterServices.cs b/CoreCms.Net.Services/Api/CoreCmsPrinterServices.cs new file mode 100644 index 00000000..831aa447 --- /dev/null +++ b/CoreCms.Net.Services/Api/CoreCmsPrinterServices.cs @@ -0,0 +1,97 @@ +/*********************************************************************** + * Project: CoreCms + * ProjectName: 核心内容管理系统 + * Web: https://www.corecms.net + * Author: 大灰灰 + * Email: jianweie@163.com + * CreateTime: 2022/9/16 20:41:09 + * Description: 暂无 + ***********************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; +using CoreCms.Net.Configuration; +using CoreCms.Net.IRepository; +using CoreCms.Net.IRepository.UnitOfWork; +using CoreCms.Net.IServices; +using CoreCms.Net.Model.Entities; +using CoreCms.Net.Model.ViewModels.Basics; +using CoreCms.Net.Model.ViewModels.UI; +using SqlSugar; + + +namespace CoreCms.Net.Services +{ + /// + /// 打印机列表 接口实现 + /// + public class CoreCmsPrinterServices : BaseServices, ICoreCmsPrinterServices + { + private readonly ICoreCmsPrinterRepository _dal; + private readonly IUnitOfWork _unitOfWork; + + public CoreCmsPrinterServices(IUnitOfWork unitOfWork, ICoreCmsPrinterRepository dal) + { + this._dal = dal; + base.BaseDal = dal; + _unitOfWork = unitOfWork; + } + + #region 实现重写增删改查操作========================================================== + + /// + /// 重写异步插入方法 + /// + /// 实体数据 + /// + public async Task InsertAsync(CoreCmsPrinter entity) + { + return await _dal.InsertAsync(entity); + } + + /// + /// 重写异步更新方法方法 + /// + /// + /// + public async Task UpdateAsync(CoreCmsPrinter entity) + { + return await _dal.UpdateAsync(entity); + } + + /// + /// 重写删除指定ID的数据 + /// + /// + /// + public async Task DeleteByIdAsync(object id) + { + return await _dal.DeleteByIdAsync(id); + } + + #endregion + + + #region 重写根据条件查询分页数据 + /// + /// 重写根据条件查询分页数据 + /// + /// 判断集合 + /// 排序方式 + /// 当前页面索引 + /// 分布大小 + /// + /// 是否使用WITH(NOLOCK) + /// + public async Task> QueryPageAsync(Expression> predicate, + Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1, + int pageSize = 20, bool blUseNoLock = false) + { + return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock); + } + #endregion + + } +} diff --git a/CoreCms.Net.Services/CoreCms.Net.Services.csproj b/CoreCms.Net.Services/CoreCms.Net.Services.csproj index 87f32de3..d6076e65 100644 --- a/CoreCms.Net.Services/CoreCms.Net.Services.csproj +++ b/CoreCms.Net.Services/CoreCms.Net.Services.csproj @@ -12,7 +12,6 @@ - diff --git a/CoreCms.Net.Utility/Helper/CommonHelper.cs b/CoreCms.Net.Utility/Helper/CommonHelper.cs index 7cf62086..7d436212 100644 --- a/CoreCms.Net.Utility/Helper/CommonHelper.cs +++ b/CoreCms.Net.Utility/Helper/CommonHelper.cs @@ -169,6 +169,30 @@ namespace CoreCms.Net.Utility.Helper } #endregion + + /// + /// 转MD5 + /// + /// + /// + public static string ToMd5(string str) + { + MD5 md5 = MD5.Create(); + // 将字符串转换成字节数组 + byte[] byteOld = Encoding.UTF8.GetBytes(str); + // 调用加密方法 + byte[] byteNew = md5.ComputeHash(byteOld); + // 将加密结果转换为字符串 + StringBuilder sb = new StringBuilder(); + foreach (byte b in byteNew) + { + // 将字节转换成16进制表示的字符串, + sb.Append(b.ToString("x2")); + } + // 返回加密的字符串 + return sb.ToString(); + } + #region 获取32位md5加密 /// /// 通过创建哈希字符串适用于任何 MD5 哈希函数 (在任何平台) 上创建 32 个字符的十六进制格式哈希字符串 @@ -597,6 +621,19 @@ namespace CoreCms.Net.Utility.Helper TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); return Convert.ToInt64(ts.TotalMilliseconds); } + + /// + /// 获取时间戳 + /// + /// + /// + public static int GetDateTimeStamp(DateTime dt) + { + DateTime dateStart = new DateTime(1970, 1, 1, 0, 0, 0); + int timeStamp = Convert.ToInt32((dt.ToUniversalTime() - dateStart).TotalSeconds); + return timeStamp; + } + #endregion } diff --git a/CoreCms.Net.Web.Admin/Controllers/Api/CoreCmsPrinterController.cs b/CoreCms.Net.Web.Admin/Controllers/Api/CoreCmsPrinterController.cs new file mode 100644 index 00000000..1c6b4c89 --- /dev/null +++ b/CoreCms.Net.Web.Admin/Controllers/Api/CoreCmsPrinterController.cs @@ -0,0 +1,805 @@ +/*********************************************************************** + * Project: CoreCms + * ProjectName: 核心内容管理系统 + * Web: https://www.corecms.net + * Author: 大灰灰 + * Email: jianweie@163.com + * CreateTime: 2022/9/16 20:41:09 + * Description: 暂无 + ***********************************************************************/ + + +using System; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; +using CoreCms.Net.Configuration; +using CoreCms.Net.Model.Entities; +using CoreCms.Net.Model.Entities.Expression; +using CoreCms.Net.Model.FromBody; +using CoreCms.Net.Model.ViewModels.UI; +using CoreCms.Net.Filter; +using CoreCms.Net.IServices; +using CoreCms.Net.Utility.Helper; +using CoreCms.Net.Utility.Extensions; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Newtonsoft.Json; +using CoreCms.Net.Model.ViewModels.YiLianYun; +using Flurl.Http; + +namespace CoreCms.Net.Web.Admin.Controllers +{ + /// + /// 打印机列表 + /// + [Description("打印机列表")] + [Route("api/[controller]/[action]")] + [ApiController] + [RequiredErrorForAdmin] + [Authorize] + public class CoreCmsPrinterController : ControllerBase + { + private readonly IWebHostEnvironment _webHostEnvironment; + private readonly ICoreCmsPrinterServices _coreCmsPrinterServices; + private readonly ICoreCmsStoreServices _storeServices; + + + /// + /// 构造函数 + /// + public CoreCmsPrinterController(IWebHostEnvironment webHostEnvironment + , ICoreCmsPrinterServices coreCmsPrinterServices, ICoreCmsStoreServices storeServices) + { + _webHostEnvironment = webHostEnvironment; + _coreCmsPrinterServices = coreCmsPrinterServices; + _storeServices = storeServices; + } + + #region 获取列表============================================================ + // POST: Api/CoreCmsPrinter/GetPageList + /// + /// 获取列表 + /// + /// + [HttpPost] + [Description("获取列表")] + public async Task GetPageList() + { + var jm = new AdminUiCallBack(); + var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1); + var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30); + var where = PredicateBuilder.True(); + //获取排序字段 + var orderField = Request.Form["orderField"].FirstOrDefault(); + + Expression> orderEx = orderField switch + { + "id" => p => p.id, + "name" => p => p.name, + "code" => p => p.code, + "clientId" => p => p.clientId, + "clientSecret" => p => p.clientSecret, + "machineCode" => p => p.machineCode, + "msign" => p => p.msign, + "printerName" => p => p.printerName, + "phone" => p => p.phone, + "accessToken" => p => p.accessToken, + "refreshToken" => p => p.refreshToken, + "expiresIn" => p => p.expiresIn, + "expiressEndTime" => p => p.expiressEndTime, + "parameters" => p => p.parameters, + "createTime" => p => p.createTime, + "isDefault" => p => p.isDefault, + "isOpen" => p => p.isOpen, + "storeId" => p => p.storeId, + _ => p => p.id + }; + + //设置排序方式 + var orderDirection = Request.Form["orderDirection"].FirstOrDefault(); + var orderBy = orderDirection switch + { + "asc" => OrderByType.Asc, + "desc" => OrderByType.Desc, + _ => OrderByType.Desc + }; + //查询筛选 + + //序列 int + var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0); + if (id > 0) + { + where = where.And(p => p.id == id); + } + //应用名称 nvarchar + var name = Request.Form["name"].FirstOrDefault(); + if (!string.IsNullOrEmpty(name)) + { + where = where.And(p => p.name.Contains(name)); + } + //应用编码 nvarchar + var code = Request.Form["code"].FirstOrDefault(); + if (!string.IsNullOrEmpty(code)) + { + where = where.And(p => p.code.Contains(code)); + } + //易联云应用id nvarchar + var clientId = Request.Form["clientId"].FirstOrDefault(); + if (!string.IsNullOrEmpty(clientId)) + { + where = where.And(p => p.clientId.Contains(clientId)); + } + //易联云应用密钥 nvarchar + var clientSecret = Request.Form["clientSecret"].FirstOrDefault(); + if (!string.IsNullOrEmpty(clientSecret)) + { + where = where.And(p => p.clientSecret.Contains(clientSecret)); + } + //易联云终端号 nvarchar + var machineCode = Request.Form["machineCode"].FirstOrDefault(); + if (!string.IsNullOrEmpty(machineCode)) + { + where = where.And(p => p.machineCode.Contains(machineCode)); + } + //易联云终端密钥 nvarchar + var msign = Request.Form["msign"].FirstOrDefault(); + if (!string.IsNullOrEmpty(msign)) + { + where = where.And(p => p.msign.Contains(msign)); + } + //打印机名称 nvarchar + var printerName = Request.Form["printerName"].FirstOrDefault(); + if (!string.IsNullOrEmpty(printerName)) + { + where = where.And(p => p.printerName.Contains(printerName)); + } + //联系电话 nvarchar + var phone = Request.Form["phone"].FirstOrDefault(); + if (!string.IsNullOrEmpty(phone)) + { + where = where.And(p => p.phone.Contains(phone)); + } + //访问令牌,API调用时需要,令牌可以重复使用无失效时间,请开发者全局保存 nvarchar + var accessToken = Request.Form["accessToken"].FirstOrDefault(); + if (!string.IsNullOrEmpty(accessToken)) + { + where = where.And(p => p.accessToken.Contains(accessToken)); + } + //更新access_token所需,有效时间35天 nvarchar + var refreshToken = Request.Form["refreshToken"].FirstOrDefault(); + if (!string.IsNullOrEmpty(refreshToken)) + { + where = where.And(p => p.refreshToken.Contains(refreshToken)); + } + //令牌的有效时间,单位秒 (30天),注:该模式下可忽略此参数 int + var expiresIn = Request.Form["expiresIn"].FirstOrDefault().ObjectToInt(0); + if (expiresIn > 0) + { + where = where.And(p => p.expiresIn == expiresIn); + } + //有效期截止时间 datetime + var expiressEndTime = Request.Form["expiressEndTime"].FirstOrDefault(); + if (!string.IsNullOrEmpty(expiressEndTime)) + { + if (expiressEndTime.Contains("到")) + { + var dts = expiressEndTime.Split("到"); + var dtStart = dts[0].Trim().ObjectToDate(); + where = where.And(p => p.expiressEndTime > dtStart); + var dtEnd = dts[1].Trim().ObjectToDate(); + where = where.And(p => p.expiressEndTime < dtEnd); + } + else + { + var dt = expiressEndTime.ObjectToDate(); + where = where.And(p => p.expiressEndTime > dt); + } + } + //其他参数 nvarchar + var parameters = Request.Form["parameters"].FirstOrDefault(); + if (!string.IsNullOrEmpty(parameters)) + { + where = where.And(p => p.parameters.Contains(parameters)); + } + //创建时间 datetime + var createTime = Request.Form["createTime"].FirstOrDefault(); + if (!string.IsNullOrEmpty(createTime)) + { + if (createTime.Contains("到")) + { + var dts = createTime.Split("到"); + var dtStart = dts[0].Trim().ObjectToDate(); + where = where.And(p => p.createTime > dtStart); + var dtEnd = dts[1].Trim().ObjectToDate(); + where = where.And(p => p.createTime < dtEnd); + } + else + { + var dt = createTime.ObjectToDate(); + where = where.And(p => p.createTime > dt); + } + } + //是否默认 bit + var isDefault = Request.Form["isDefault"].FirstOrDefault(); + if (!string.IsNullOrEmpty(isDefault) && isDefault.ToLowerInvariant() == "true") + { + where = where.And(p => p.isDefault == true); + } + else if (!string.IsNullOrEmpty(isDefault) && isDefault.ToLowerInvariant() == "false") + { + where = where.And(p => p.isDefault == false); + } + //是否开启 bit + var isOpen = Request.Form["isOpen"].FirstOrDefault(); + if (!string.IsNullOrEmpty(isOpen) && isOpen.ToLowerInvariant() == "true") + { + where = where.And(p => p.isOpen == true); + } + else if (!string.IsNullOrEmpty(isOpen) && isOpen.ToLowerInvariant() == "false") + { + where = where.And(p => p.isOpen == false); + } + //绑定门店 int + var storeId = Request.Form["storeId"].FirstOrDefault().ObjectToInt(0); + if (storeId > 0) + { + where = where.And(p => p.storeId == storeId); + } + //获取数据 + var list = await _coreCmsPrinterServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize, true); + //返回数据 + jm.data = list; + jm.code = 0; + jm.count = list.TotalCount; + jm.msg = "数据调用成功!"; + return jm; + } + #endregion + + #region 首页数据============================================================ + // POST: Api/CoreCmsPrinter/GetIndex + /// + /// 首页数据 + /// + /// + [HttpPost] + [Description("首页数据")] + public async Task GetIndex() + { + //返回数据 + var jm = new AdminUiCallBack { code = 0 }; + + var stores = await _storeServices.QueryAsync(true, true); + var thirdPartyEquipment = EnumHelper.EnumToList(); + jm.data = new + { + stores, + thirdPartyEquipment + }; + + return jm; + } + #endregion + + #region 创建数据============================================================ + // POST: Api/CoreCmsPrinter/GetCreate + /// + /// 创建数据 + /// + /// + [HttpPost] + [Description("创建数据")] + public async Task GetCreate() + { + //返回数据 + var jm = new AdminUiCallBack { code = 0 }; + + var stores = await _storeServices.QueryAsync(true, true); + var thirdPartyEquipment = EnumHelper.EnumToList(); + jm.data = new + { + stores, + thirdPartyEquipment + }; + + return jm; + } + #endregion + + #region 创建提交============================================================ + // POST: Api/CoreCmsPrinter/DoCreate + /// + /// 创建提交 + /// + /// + /// + [HttpPost] + [Description("创建提交")] + public async Task DoCreate([FromBody] CoreCmsPrinter entity) + { + var jm = await _coreCmsPrinterServices.InsertAsync(entity); + return jm; + } + #endregion + + #region 编辑数据============================================================ + // POST: Api/CoreCmsPrinter/GetEdit + /// + /// 编辑数据 + /// + /// + /// + [HttpPost] + [Description("编辑数据")] + public async Task GetEdit([FromBody] FMIntId entity) + { + var jm = new AdminUiCallBack(); + + var model = await _coreCmsPrinterServices.QueryByIdAsync(entity.id, false); + if (model == null) + { + jm.msg = "不存在此信息"; + return jm; + } + jm.code = 0; + + var stores = await _storeServices.QueryAsync(true, true); + var thirdPartyEquipment = EnumHelper.EnumToList(); + jm.data = new + { + model, + stores, + thirdPartyEquipment + }; + + + return jm; + } + #endregion + + #region 编辑提交============================================================ + // POST: Api/CoreCmsPrinter/Edit + /// + /// 编辑提交 + /// + /// + /// + [HttpPost] + [Description("编辑提交")] + public async Task DoEdit([FromBody] CoreCmsPrinter entity) + { + var jm = await _coreCmsPrinterServices.UpdateAsync(entity); + return jm; + } + #endregion + + #region 删除数据============================================================ + // POST: Api/CoreCmsPrinter/DoDelete/10 + /// + /// 单选删除 + /// + /// + /// + [HttpPost] + [Description("单选删除")] + public async Task DoDelete([FromBody] FMIntId entity) + { + var jm = new AdminUiCallBack(); + + var model = await _coreCmsPrinterServices.ExistsAsync(p => p.id == entity.id); + if (!model) + { + jm.msg = GlobalConstVars.DataisNo; + return jm; + } + jm = await _coreCmsPrinterServices.DeleteByIdAsync(entity.id); + + return jm; + } + #endregion + + #region 刷新Token============================================================ + // POST: Api/CoreCmsPrinter/DoRefreshToken/10 + /// + /// 刷新Token + /// + /// + /// + [HttpPost] + [Description("刷新Token")] + public async Task DoRefreshToken([FromBody] FMIntId entity) + { + var jm = new AdminUiCallBack(); + + var model = await _coreCmsPrinterServices.QueryByClauseAsync(p => p.id == entity.id); + if (model == null) + { + jm.msg = GlobalConstVars.DataisNo; + return jm; + } + + RefreshYiLianYunToken refreshToken = new RefreshYiLianYunToken + { + client_id = model.clientId, + grant_type = "client_credentials", + timestamp = CommonHelper.GetDateTimeStamp(DateTime.Now), + scope = "all", + id = Guid.NewGuid().ToString() + }; + refreshToken.sign = CommonHelper.Md5For32((refreshToken.client_id + refreshToken.timestamp + model.clientSecret).ToLowerInvariant()).ToLowerInvariant(); + var resultData = await YiLianYunConfig.AuthUrl.PostJsonAsync(refreshToken).ReceiveJson(); + //将获取到的数据存入数据库 + if (resultData.error == "0") + { + model.accessToken = resultData.body.access_token; + model.refreshToken = resultData.body.refresh_token; + model.expiresIn = resultData.body.expires_in; + model.expiressEndTime = DateTime.Now.AddSeconds(resultData.body.expires_in); + + await _coreCmsPrinterServices.UpdateAsync( + p => new CoreCmsPrinter() + { + accessToken = resultData.body.access_token, + refreshToken = resultData.body.refresh_token, + expiresIn = resultData.body.expires_in, + expiressEndTime = model.expiressEndTime, + parameters = JsonConvert.SerializeObject(resultData.body) + }, p => p.clientId == model.clientId && p.clientSecret == model.clientSecret, true); + + //await _coreCmsPrinterServices.UpdateAsync( + // p => new CoreCmsPrinter() + // { + // accessToken = resultData.body.access_token, + // refreshToken = resultData.body.refresh_token, + // expiresIn = resultData.body.expires_in, + // expiressEndTime = model.expiressEndTime, + // parameters = JsonConvert.SerializeObject(resultData.body) + // }, p => p.id == model.id, true); + + jm.code = 1; + jm.msg = "刷新成功"; + + } + else + { + jm.msg = "刷新AccessToken:" + resultData.error_description; + return jm; + } + + return jm; + } + #endregion + + #region 打印测试页============================================================ + // POST: Api/CoreCmsPrinter/DoPrintTest/10 + /// + /// 打印测试页 + /// + /// + /// + [HttpPost] + [Description("打印测试页")] + public async Task DoPrintTest([FromBody] FMIntId entity) + { + var jm = new AdminUiCallBack(); + + var model = await _coreCmsPrinterServices.QueryByClauseAsync(p => p.id == entity.id); + if (model == null) + { + jm.msg = GlobalConstVars.DataisNo; + return jm; + } + + var isNeedToken = false; + if (string.IsNullOrEmpty(model.accessToken) || model.expiressEndTime == null) + { + isNeedToken = true; + } + else + { + //判断是否过期 + var dt = DateTime.Now; + if (dt >= model.expiressEndTime) + { + var ts = dt - Convert.ToDateTime(model.expiressEndTime); + if (ts.Days > 35) + { + isNeedToken = true; + } + else + { + RefreshYiLianYunToken refreshToken = new RefreshYiLianYunToken + { + client_id = model.clientId, + grant_type = "client_credentials", + timestamp = CommonHelper.GetDateTimeStamp(DateTime.Now), + scope = "all", + id = Guid.NewGuid().ToString() + }; + refreshToken.sign = CommonHelper.Md5For32((refreshToken.client_id + refreshToken.timestamp + model.clientSecret).ToLowerInvariant()).ToLowerInvariant(); + var resultData = await YiLianYunConfig.AuthUrl.PostJsonAsync(refreshToken).ReceiveJson(); + //将获取到的数据存入数据库 + if (resultData.error == "0") + { + model.accessToken = resultData.body.access_token; + model.refreshToken = resultData.body.refresh_token; + model.expiresIn = resultData.body.expires_in; + model.expiressEndTime = DateTime.Now.AddSeconds(resultData.body.expires_in); + + //await _coreCmsPrinterServices.UpdateAsync( + // p => new CoreCmsPrinter() + // { + // accessToken = resultData.body.access_token, + // refreshToken = resultData.body.refresh_token, + // expiresIn = resultData.body.expires_in, + // expiressEndTime = model.expiressEndTime, + // parameters = JsonConvert.SerializeObject(resultData.body) + // }, p => p.id == model.id, true); + + await _coreCmsPrinterServices.UpdateAsync( + p => new CoreCmsPrinter() + { + accessToken = resultData.body.access_token, + refreshToken = resultData.body.refresh_token, + expiresIn = resultData.body.expires_in, + expiressEndTime = model.expiressEndTime, + parameters = JsonConvert.SerializeObject(resultData.body) + }, p => p.clientId == model.clientId && p.clientSecret == model.clientSecret, true); + + } + else + { + jm.msg = "刷新AccessToken:" + resultData.error_description; + return jm; + } + } + } + } + + if (isNeedToken) + { + var getToken = new YiLianYunParam + { + client_id = model.clientId, + grant_type = "client_credentials", + timestamp = CommonHelper.GetDateTimeStamp(DateTime.Now), + scope = "all", + id = Guid.NewGuid().ToString() + }; + getToken.sign = CommonHelper.Md5For32((getToken.client_id + getToken.timestamp + model.clientSecret).ToLowerInvariant()).ToLowerInvariant(); + + var resultData = await YiLianYunConfig.AuthUrl.PostJsonAsync(getToken).ReceiveJson(); + //将获取到的数据存入数据库 + if (resultData.error == "0") + { + model.accessToken = resultData.body.access_token; + model.refreshToken = resultData.body.refresh_token; + model.expiresIn = resultData.body.expires_in; + model.expiressEndTime = DateTime.Now.AddSeconds(resultData.body.expires_in); + + //await _coreCmsPrinterServices.UpdateAsync( + // p => new CoreCmsPrinter() + // { + // accessToken = resultData.body.access_token, + // refreshToken = resultData.body.refresh_token, + // expiresIn = resultData.body.expires_in, + // expiressEndTime = model.expiressEndTime, + // parameters = JsonConvert.SerializeObject(resultData.body) + // }, p => p.id == model.id, true); + + await _coreCmsPrinterServices.UpdateAsync( + p => new CoreCmsPrinter() + { + accessToken = resultData.body.access_token, + refreshToken = resultData.body.refresh_token, + expiresIn = resultData.body.expires_in, + expiressEndTime = model.expiressEndTime, + parameters = JsonConvert.SerializeObject(resultData.body) + }, p => p.clientId == model.clientId && p.clientSecret == model.clientSecret, true); + + } + else + { + jm.msg = "获取AccessToken:" + resultData.error_description; + return jm; + } + } + + //获取打印机是否在线 + var statusParam = new GetPrintStatusParam + { + client_id = model.clientId, + access_token = model.accessToken, + machine_code = model.machineCode, + timestamp = CommonHelper.GetDateTimeStamp(DateTime.Now), + id = Guid.NewGuid().ToString() + }; + statusParam.sign = CommonHelper.Md5For32((statusParam.client_id + statusParam.timestamp + model.clientSecret).ToLowerInvariant()).ToLowerInvariant(); + + var getPrintStatusResult = await YiLianYunConfig.GetPrintStatusUrl.PostJsonAsync(statusParam).ReceiveJson(); + if (getPrintStatusResult.error != "0") + { + jm.msg = "获取打印机在线状态:" + getPrintStatusResult.error_description; + return jm; + } + else + { + switch (getPrintStatusResult.body.state) + { + case "0": + jm.msg = "机器未在线"; + return jm; + case "2": + jm.msg = "机器缺纸"; + return jm; + default: + { + var order = new CoreCmsOrder() + { + createTime = DateTime.Now, + orderId = DateTime.Now.ToLongDateString(), + pointMoney = 10, + orderDiscountAmount = 0, + goodsDiscountAmount = 0, + couponDiscountAmount = 0, + orderAmount = 199, + shipAreaName = "湖南省", + shipAddress = "怀化市鹤城区迎丰中路佳慧中央商厦A栋1513-1514(南山田舍)", + shipName = "大灰灰", + shipMobile = "19145919666" + }; + var printStr = YiLianYunConfig.PrintTmpModel(order); + + //小票打印 + WordPrintRespone wordPrintRespone = new WordPrintRespone + { + client_id = model.clientId, + access_token = model.accessToken, + machine_code = model.machineCode, + content = printStr.ToString(), + origin_id = order.orderId, + timestamp = CommonHelper.GetDateTimeStamp(DateTime.Now) + }; + wordPrintRespone.sign = CommonHelper.Md5For32((wordPrintRespone.client_id + wordPrintRespone.timestamp + model.clientSecret).ToLowerInvariant()).ToLowerInvariant(); + wordPrintRespone.id = Guid.NewGuid().ToString(); + + //打印文本:缺少参数!请检查参数信息!!或更改下请求头:Content-Type:application/x-www-form-urlencoded + var resultData = await YiLianYunConfig.PrintTextUrl.WithHeader("Content-Type", "application/x-www-form-urlencoded").PostUrlEncodedAsync(wordPrintRespone).ReceiveJson(); + //当token返回失败时 + if (resultData.error != "0") + { + jm.msg = "打印文本:" + resultData.error_description; + return jm; + } + else + { + jm.code = 1; + jm.msg = "打印成功"; + } + + break; + } + } + } + return jm; + } + + + + #endregion + + #region 预览数据============================================================ + // POST: Api/CoreCmsPrinter/GetDetails/10 + /// + /// 预览数据 + /// + /// + /// + [HttpPost] + [Description("预览数据")] + public async Task GetDetails([FromBody] FMIntId entity) + { + var jm = new AdminUiCallBack(); + + var model = await _coreCmsPrinterServices.QueryByIdAsync(entity.id, false); + if (model == null) + { + jm.msg = "不存在此信息"; + return jm; + } + jm.code = 0; + + var stores = await _storeServices.QueryAsync(true, true); + var thirdPartyEquipment = EnumHelper.EnumToList(); + jm.data = new + { + model, + stores, + thirdPartyEquipment + }; + + return jm; + } + #endregion + + #region 设置是否默认============================================================ + // POST: Api/CoreCmsPrinter/DoSetisDefault/10 + /// + /// 设置是否默认 + /// + /// + /// + [HttpPost] + [Description("设置是否默认")] + public async Task DoSetIsDefault([FromBody] FMUpdateBoolDataByIntId entity) + { + var jm = new AdminUiCallBack(); + + var oldModel = await _coreCmsPrinterServices.QueryByIdAsync(entity.id, false); + if (oldModel == null) + { + jm.msg = "不存在此信息"; + return jm; + } + oldModel.isDefault = (bool)entity.data; + + //判断是否除了自己其他都不是默认 + var haveOtherDefault = await _coreCmsPrinterServices.ExistsAsync(p => p.isDefault == true && p.id != entity.id); + if (haveOtherDefault == false && oldModel.isDefault == false) + { + jm.msg = "至少有一个要是默认打印机"; + return jm; + } + + var bl = await _coreCmsPrinterServices.UpdateAsync(p => new CoreCmsPrinter() { isDefault = oldModel.isDefault }, p => p.id == oldModel.id, true); + + //将其他打印机设置为非默认 + if (bl && oldModel.isDefault == true) + { + await _coreCmsPrinterServices.UpdateAsync(p => new CoreCmsPrinter() { isDefault = false }, p => p.id != oldModel.id, true); + } + + jm.code = bl ? 0 : 1; + jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure; + + return jm; + } + #endregion + + #region 设置是否开启============================================================ + // POST: Api/CoreCmsPrinter/DoSetisOpen/10 + /// + /// 设置是否开启 + /// + /// + /// + [HttpPost] + [Description("设置是否开启")] + public async Task DoSetIsOpen([FromBody] FMUpdateBoolDataByIntId entity) + { + var jm = new AdminUiCallBack(); + + var oldModel = await _coreCmsPrinterServices.QueryByIdAsync(entity.id, false); + if (oldModel == null) + { + jm.msg = "不存在此信息"; + return jm; + } + oldModel.isOpen = (bool)entity.data; + + var bl = await _coreCmsPrinterServices.UpdateAsync(p => new CoreCmsPrinter() { isOpen = oldModel.isOpen }, p => p.id == oldModel.id); + jm.code = bl ? 0 : 1; + jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure; + + return jm; + } + #endregion + + + } +} diff --git a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj index 3cb182a7..9db71402 100644 --- a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj +++ b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.csproj @@ -61,7 +61,6 @@ - diff --git a/CoreCms.Net.Web.Admin/Startup.cs b/CoreCms.Net.Web.Admin/Startup.cs index 2302a155..826c79ec 100644 --- a/CoreCms.Net.Web.Admin/Startup.cs +++ b/CoreCms.Net.Web.Admin/Startup.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; + using System.Linq; using Autofac; using CoreCms.Net.Auth; @@ -10,16 +9,15 @@ using CoreCms.Net.Filter; using CoreCms.Net.Loging; using CoreCms.Net.Mapping; using CoreCms.Net.Middlewares; +using CoreCms.Net.Model.ViewModels.Options; using CoreCms.Net.Swagger; using Essensoft.Paylink.Alipay; using Essensoft.Paylink.WeChatPay; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpOverrides; -using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; -using Microsoft.DotNet.PlatformAbstractions; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -89,10 +87,10 @@ namespace CoreCms.Net.Web.Admin services.AddWeChatPay(); // appsettings.json ѡ + //עԶ֧ļ潫ȡʹPaylinkֱ߽ӿԶ崦 services.Configure(Configuration.GetSection("WeChatPay")); services.Configure(Configuration.GetSection("Alipay")); - //עԶ΢Žӿļ services.Configure(Configuration.GetSection(nameof(WeChat.Service.Options.WeChatOptions))); @@ -106,9 +104,6 @@ namespace CoreCms.Net.Web.Admin //Swaggerӿĵע services.AddAdminSwaggerSetup(); - //ƴӡ - services.AddYiLianYunSetup(); - //jwtȨ֧ע services.AddAuthorizationSetupForAdmin(); //ע @@ -141,6 +136,7 @@ namespace CoreCms.Net.Web.Admin p.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; }); + // ѩƯ㷨 // IdGeneratorOptions ڹ캯 WorkerId var options = new IdGeneratorOptions(1); @@ -178,14 +174,13 @@ namespace CoreCms.Net.Web.Admin /// public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - #region Ubuntu Nginx ܻȡIP⣨ + #region Ubuntu Nginx ܻȡIP app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }); #endregion - // Ip app.UseIpLimitMiddle(); // ¼뷵 (ע⿪ȨޣȻ޷д) diff --git a/CoreCms.Net.Web.Admin/appsettings.json b/CoreCms.Net.Web.Admin/appsettings.json index 26c82390..d2181152 100644 --- a/CoreCms.Net.Web.Admin/appsettings.json +++ b/CoreCms.Net.Web.Admin/appsettings.json @@ -130,23 +130,6 @@ } }, "AllowedHosts": "*", - //易联云打印机设置【很不错的一个网络打印机,价格也很便宜https://www.yilianyun.net/】 - "YiLianYunConfig": { - //是否开启 - "Enabled": false, - //应用id - "ClientId": "", - //应用密钥 string - "ClientSecret": "", - //打印机设备号 - "MachineCode": "", - //打印机终端密钥 - "Msign": "", - //打印机名称 - "PrinterName": "", - //打印机设置联系电话 - "Phone": "" - }, // 微信支付 // 更多配置,请查看WeChatPayOptions类 "WeChatPay": { diff --git a/CoreCms.Net.Web.Admin/wwwroot/lib/layuiAdmin/config.js b/CoreCms.Net.Web.Admin/wwwroot/lib/layuiAdmin/config.js index c6da0b94..9968cc24 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/lib/layuiAdmin/config.js +++ b/CoreCms.Net.Web.Admin/wwwroot/lib/layuiAdmin/config.js @@ -12,7 +12,7 @@ layui.define(['laytpl', 'layer', 'element', 'util'], function (exports) { , pageTabs: false //是否开启页面选项卡功能。单页版不推荐开启 , name: '核心商城系统' - , version: 'CoreShopProfessional v0.5.5' + , version: 'CoreShopProfessional v0.6.0' , tableName: 'CoreCms' //本地存储表名 , MOD_NAME: 'admin' //模块事件名 diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/create.html b/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/create.html new file mode 100644 index 00000000..6ecaec94 --- /dev/null +++ b/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/create.html @@ -0,0 +1,163 @@ + + diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/details.html b/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/details.html new file mode 100644 index 00000000..56c3f4ea --- /dev/null +++ b/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/details.html @@ -0,0 +1,189 @@ + + \ No newline at end of file diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/edit.html b/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/edit.html new file mode 100644 index 00000000..bfea2003 --- /dev/null +++ b/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/edit.html @@ -0,0 +1,162 @@ + + diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/index.html b/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/index.html new file mode 100644 index 00000000..b00c584d --- /dev/null +++ b/CoreCms.Net.Web.Admin/wwwroot/views/shop/printer/index.html @@ -0,0 +1,392 @@ +打印机列表 + +
+
+ +
+
+ + + +
+
+
+ + + + + + + + + + + + + + + diff --git a/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj b/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj index 1212ef86..cffc3564 100644 --- a/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj +++ b/CoreCms.Net.Web.WebApi/CoreCms.Net.Web.WebApi.csproj @@ -64,7 +64,6 @@ - diff --git a/CoreCms.Net.Web.WebApi/Startup.cs b/CoreCms.Net.Web.WebApi/Startup.cs index c82e955d..9f63ab18 100644 --- a/CoreCms.Net.Web.WebApi/Startup.cs +++ b/CoreCms.Net.Web.WebApi/Startup.cs @@ -1,5 +1,4 @@ using Autofac; -using AutoMapper; using CoreCms.Net.Auth; using CoreCms.Net.Configuration; using CoreCms.Net.Core.AutoFac; @@ -12,7 +11,6 @@ using CoreCms.Net.Swagger; using CoreCms.Net.Task; using Hangfire; using Hangfire.Dashboard.BasicAuthorization; -using InitQ; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; @@ -24,12 +22,8 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -using Qc.YilianyunSdk; using System; -using System.Collections.Generic; using System.Linq; -using CoreCms.Net.RedisMQ.Subscribe; -using CoreCms.Net.Utility.Extensions; using CoreCms.Net.WeChat.Service.Mediator; using Essensoft.Paylink.Alipay; using Essensoft.Paylink.WeChatPay; @@ -80,12 +74,12 @@ namespace CoreCms.Net.Web.WebApi //ÿCORS services.AddCorsSetup(); - //session֧(sessioncacheд洢) services.AddSession(); // AutoMapper֧ services.AddAutoMapper(typeof(AutoMapperConfiguration)); + //MediatRֻҪעһ,ͬĿ¾ͲҪע services.AddMediatR(typeof(TextMessageEventCommand).Assembly); @@ -104,6 +98,7 @@ namespace CoreCms.Net.Web.WebApi services.Configure(Configuration.GetSection("Alipay")); + //עԶ΢Žӿļ services.Configure(Configuration.GetSection(nameof(WeChat.Service.Options.WeChatOptions))); @@ -117,13 +112,9 @@ namespace CoreCms.Net.Web.WebApi //Swaggerӿĵע services.AddClientSwaggerSetup(); - //ƴӡ - services.AddYiLianYunSetup(); - //עHangfireʱ services.AddHangFireSetup(); - //Ȩ֧ע services.AddAuthorizationSetupForClient(); //ע @@ -144,7 +135,7 @@ namespace CoreCms.Net.Web.WebApi }) .AddNewtonsoftJson(p => { - //ݸʽĸСд ʹշ + //ݸʽĸСд ʹôշ p.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); //ʹշʽkey //p.SerializerSettings.ContractResolver = new DefaultContractResolver(); @@ -154,6 +145,7 @@ namespace CoreCms.Net.Web.WebApi p.SerializerSettings.DateFormatString = "yyyy/MM/dd HH:mm:ss"; }); + // ѩƯ㷨 // IdGeneratorOptions ڹ캯 WorkerId var options = new IdGeneratorOptions(1); @@ -193,7 +185,7 @@ namespace CoreCms.Net.Web.WebApi /// public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - #region Ubuntu Nginx ܻȡIP⣨ + #region Ubuntu Nginx ܻȡIP app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto @@ -256,10 +248,7 @@ namespace CoreCms.Net.Web.WebApi { filter }, - IsReadOnlyFunc = Context => - { - return false;//Ƿֻ - } + IsReadOnlyFunc = _ => false }; app.UseHangfireDashboard("/job", options); //ԸıDashboardurl @@ -267,9 +256,6 @@ namespace CoreCms.Net.Web.WebApi #endregion - - - //ʹ Session app.UseSession(); diff --git a/CoreCms.Net.Web.WebApi/appsettings.json b/CoreCms.Net.Web.WebApi/appsettings.json index 26c82390..d2181152 100644 --- a/CoreCms.Net.Web.WebApi/appsettings.json +++ b/CoreCms.Net.Web.WebApi/appsettings.json @@ -130,23 +130,6 @@ } }, "AllowedHosts": "*", - //易联云打印机设置【很不错的一个网络打印机,价格也很便宜https://www.yilianyun.net/】 - "YiLianYunConfig": { - //是否开启 - "Enabled": false, - //应用id - "ClientId": "", - //应用密钥 string - "ClientSecret": "", - //打印机设备号 - "MachineCode": "", - //打印机终端密钥 - "Msign": "", - //打印机名称 - "PrinterName": "", - //打印机设置联系电话 - "Phone": "" - }, // 微信支付 // 更多配置,请查看WeChatPayOptions类 "WeChatPay": { diff --git a/数据库/MySql/20220917/升级脚本/1、修改签到字段类型.sql b/数据库/MySql/20220917/升级脚本/1、修改签到字段类型.sql new file mode 100644 index 00000000..30e4448c --- /dev/null +++ b/数据库/MySql/20220917/升级脚本/1、修改签到字段类型.sql @@ -0,0 +1 @@ +alter table CoreCmsUserCheckInDetails modify column checkInData date comment '打卡日期'; \ No newline at end of file diff --git a/数据库/MySql/20220917/升级脚本/2、创建表CoreCmsPrinter.sql b/数据库/MySql/20220917/升级脚本/2、创建表CoreCmsPrinter.sql new file mode 100644 index 00000000..4b141a9a --- /dev/null +++ b/数据库/MySql/20220917/升级脚本/2、创建表CoreCmsPrinter.sql @@ -0,0 +1,36 @@ + + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for CoreCmsPrinter +-- ---------------------------- +DROP TABLE IF EXISTS `CoreCmsPrinter`; +CREATE TABLE `CoreCmsPrinter` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '序列', + `name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '应用名称', + `code` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '应用编码', + `clientId` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '易联云应用id', + `clientSecret` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '易联云应用密钥', + `machineCode` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '易联云终端号', + `msign` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '易联云终端密钥', + `printerName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '打印机名称', + `phone` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '联系电话', + `accessToken` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '访问令牌,API调用时需要,令牌可以重复使用无失效时间,请开发者全局保存', + `refreshToken` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '更新access_token所需,有效时间35天', + `expiresIn` int(11) NULL DEFAULT NULL COMMENT '令牌的有效时间,单位秒 (30天),注:该模式下可忽略此参数', + `expiressEndTime` datetime(0) NULL DEFAULT NULL COMMENT '有效期截止时间', + `parameters` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '其他参数', + `createTime` datetime(0) NOT NULL COMMENT '创建时间', + `isDefault` bit(4) NOT NULL COMMENT '是否默认', + `isOpen` bit(4) NOT NULL COMMENT '是否开启', + `storeId` int(11) NOT NULL COMMENT '绑定门店', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '打印机列表' ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of CoreCmsPrinter +-- ---------------------------- + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/数据库/MySql/20220917/完整脚本/Navicat导出脚本.rar b/数据库/MySql/20220917/完整脚本/Navicat导出脚本.rar new file mode 100644 index 00000000..a7f0c8cf Binary files /dev/null and b/数据库/MySql/20220917/完整脚本/Navicat导出脚本.rar differ diff --git a/数据库/MySql/数据库更新日志.txt b/数据库/MySql/数据库更新日志.txt index 3e088774..fd800f23 100644 --- a/数据库/MySql/数据库更新日志.txt +++ b/数据库/MySql/数据库更新日志.txt @@ -1,3 +1,7 @@ +2022-09-19 +【新增】表【CoreCmsPrinter】打印机列表表。 +【调整】表【CoreCmsUserCheckInDetails】字段【checkInData】数据类型为date。 + 2022-08-19 【调整】表【CoreCmsSms】调整【mobile】字段长度。 diff --git a/数据库/SqlServer/20220917/升级脚本/升级脚本-创建表CoreCmsPrinter.sql b/数据库/SqlServer/20220917/升级脚本/升级脚本-创建表CoreCmsPrinter.sql new file mode 100644 index 00000000..60e84aab --- /dev/null +++ b/数据库/SqlServer/20220917/升级脚本/升级脚本-创建表CoreCmsPrinter.sql @@ -0,0 +1,104 @@ + +/****** Object: Table [dbo].[CoreCmsPrinter] Script Date: 2022/9/17 2:15:13 ******/ +SET ANSI_NULLS ON +GO + +SET QUOTED_IDENTIFIER ON +GO + +CREATE TABLE [dbo].[CoreCmsPrinter]( + [id] [int] IDENTITY(1,1) NOT NULL, + [name] [nvarchar](50) NOT NULL, + [code] [nvarchar](50) NOT NULL, + [clientId] [nvarchar](50) NOT NULL, + [clientSecret] [nvarchar](50) NOT NULL, + [machineCode] [nvarchar](50) NOT NULL, + [msign] [nvarchar](50) NOT NULL, + [printerName] [nvarchar](50) NOT NULL, + [phone] [nvarchar](50) NOT NULL, + [accessToken] [nvarchar](50) NULL, + [refreshToken] [nvarchar](50) NULL, + [expiresIn] [int] NULL, + [expiressEndTime] [datetime] NULL, + [parameters] [nvarchar](max) NULL, + [createTime] [datetime] NOT NULL, + [isDefault] [bit] NOT NULL, + [isOpen] [bit] NOT NULL, + [storeId] [int] NOT NULL, + CONSTRAINT [PK_CoreCmsPrinter] PRIMARY KEY CLUSTERED +( + [id] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] +GO + +ALTER TABLE [dbo].[CoreCmsPrinter] ADD CONSTRAINT [DF_CoreCmsPrinter_expiresIn] DEFAULT ((0)) FOR [expiresIn] +GO + +ALTER TABLE [dbo].[CoreCmsPrinter] ADD CONSTRAINT [DF_CoreCmsPrinter_isDefault] DEFAULT ((0)) FOR [isDefault] +GO + +ALTER TABLE [dbo].[CoreCmsPrinter] ADD CONSTRAINT [DF_CoreCmsPrinter_isOpen] DEFAULT ((0)) FOR [isOpen] +GO + +ALTER TABLE [dbo].[CoreCmsPrinter] ADD CONSTRAINT [DF_CoreCmsPrinter_storeId] DEFAULT ((0)) FOR [storeId] +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'id' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Ӧ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'name' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Ӧñ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'code' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Ӧid' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'clientId' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ӦԿ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'clientSecret' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ն˺' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'machineCode' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'նԿ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'msign' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ӡ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'printerName' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ϵ绰' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'phone' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ƣAPIʱҪƿظʹʧЧʱ䣬뿪ȫֱ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'accessToken' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'access_token裬Чʱ35' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'refreshToken' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ƵЧʱ䣬λ (30),עģʽ¿ɺԴ˲' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'expiresIn' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Чڽֹʱ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'expiressEndTime' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'parameters' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ʱ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'createTime' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ǷĬ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'isDefault' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Ƿ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'isOpen' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ŵ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter', @level2type=N'COLUMN',@level2name=N'storeId' +GO + +EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ӡб' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CoreCmsPrinter' +GO + + diff --git a/数据库/SqlServer/20220917/完整数据库/完整bak文件.rar b/数据库/SqlServer/20220917/完整数据库/完整bak文件.rar new file mode 100644 index 00000000..addfa655 Binary files /dev/null and b/数据库/SqlServer/20220917/完整数据库/完整bak文件.rar differ diff --git a/数据库/SqlServer/20220917/完整数据库/完整脚本.rar b/数据库/SqlServer/20220917/完整数据库/完整脚本.rar new file mode 100644 index 00000000..44fc4246 Binary files /dev/null and b/数据库/SqlServer/20220917/完整数据库/完整脚本.rar differ diff --git a/数据库/SqlServer/数据库更新日志.txt b/数据库/SqlServer/数据库更新日志.txt index aa29d09e..cdbb713f 100644 --- a/数据库/SqlServer/数据库更新日志.txt +++ b/数据库/SqlServer/数据库更新日志.txt @@ -1,3 +1,6 @@ +2022-09-19 +【新增】表【CoreCmsPrinter】打印机列表表 + 2022-08-19 【调整】表【CoreCmsSms】调整【mobile】字段长度。