Bläddra i källkod

Merge branch 'DuGuYang' into develop

lcl 3 år sedan
förälder
incheckning
eb6af15790

+ 75 - 0
AppStart/Helper/TimeOutPosChargeReturnService.cs

@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Threading;
+using MySystem.Models;
+using Library;
+
+namespace MySystem
+{
+    /// <summary>
+    /// 过期购买机具循环截止时间超过15天激活扣费退还
+    /// </summary>
+    public class TimeOutPosChargeReturnService
+    {
+        public readonly static TimeOutPosChargeReturnService Instance = new TimeOutPosChargeReturnService();
+        private TimeOutPosChargeReturnService()
+        { }
+
+        public void Start()
+        {
+            Thread th = new Thread(doSomething);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void doSomething()
+        {
+            while (true)
+            {
+                if (DateTime.Now.Hour < 18)
+                {
+                    try
+                    {
+                        string check = function.ReadInstance("/TimeOutPosChargeReturn/check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
+                        if (string.IsNullOrEmpty(check))
+                        {
+                            function.WritePage("/TimeOutPosChargeReturn/", "check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
+                            WebCMSEntities db = new WebCMSEntities();
+                            DataTable dt = CustomerSqlConn.dtable("SELECT a.Id Id FROM ToChargeBackRecord a LEFT JOIN PosMachinesTwo b ON a.Remark=b.PosSn WHERE a.`Status`=1 AND b.PosSnType=0  AND b.BindingState=1 AND b.ActivationState=1", MysqlConn.connstr);//循环过期超过15天激活机具退费创客
+                            foreach (DataRow item in dt.Rows)
+                            {
+                                int Id = int.Parse(item["Id"].ToString());
+                                var toChargeBackRecord = db.ToChargeBackRecord.FirstOrDefault(m => m.Id == Id && m.Status == 1) ?? new ToChargeBackRecord();
+                                if (toChargeBackRecord.Id > 0)
+                                {
+                                    var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == toChargeBackRecord.UserId) ?? new UserAccount();
+                                    var userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord
+                                    {
+                                        CreateDate = DateTime.Now,
+                                        UserId = toChargeBackRecord.UserId,
+                                        BeforeBalanceAmount = userAccount.BalanceAmount,
+                                        AfterBalanceAmount = userAccount.BalanceAmount + toChargeBackRecord.ChargeAmount,
+                                        ChangeAmount = toChargeBackRecord.ChargeAmount,
+                                        ChangeType = 126,//过期购买机具超过15天激活扣费退还
+                                        Remark = "机具货款退还",
+
+                                    }).Entity;
+                                    toChargeBackRecord.Status = 2;//过期购买机具循环截止时间超过15天激活扣费退还标识
+                                    userAccount.BalanceAmount += toChargeBackRecord.ChargeAmount;
+                                    db.SaveChanges();
+                                }
+                            }
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "过期购买机具超过15天激活扣费退还");
+                    }
+                }
+                Thread.Sleep(1000);
+            }
+        }
+    }
+}

+ 127 - 0
AppStart/Helper/TimeOutPosChargeService.cs

@@ -0,0 +1,127 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Threading;
+using MySystem.Models;
+using Library;
+
+namespace MySystem
+{
+    /// <summary>
+    /// 过期机具执行扣费
+    /// </summary>
+    public class TimeOutPosChargeService
+    {
+        public readonly static TimeOutPosChargeService Instance = new TimeOutPosChargeService();
+        private TimeOutPosChargeService()
+        { }
+
+        public void Start()
+        {
+            Thread th = new Thread(doSomething);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void doSomething()
+        {
+            while (true)
+            {
+                if (DateTime.Now.Hour < 20)
+                {
+                    try
+                    {
+                        string check = function.ReadInstance("/TimeOutPosCharge/check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
+                        if (string.IsNullOrEmpty(check))
+                        {
+                            function.WritePage("/TimeOutPosCharge/", "check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
+                            WebCMSEntities db = new WebCMSEntities();
+                            var date = DateTime.Now.AddDays(-60).ToString("yyyy-MM-dd 00:00:00");//过期限制时间
+                            var time = DateTime.Parse(date);//过期限制时间
+
+                            DataTable dt = CustomerSqlConn.dtable("SELECT BuyUserId FROM PosMachinesTwo WHERE `Status`>-1 AND BuyUserId>0 AND BindingState=0 AND ActivationState=0 AND ScanQrTrade=0 AND RecycEndDate <'" + date + "' GROUP BY BuyUserId", MysqlConn.connstr);//扣费创客
+                            var query = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId > 0 && m.BindingState == 0 && m.ActivationState == 0 && m.ScanQrTrade == 0 && m.RecycEndDate < time).ToList();//循环过期超过60天机具
+                            var brandInfo = db.KqProducts.ToList();
+                            foreach (DataRow item in dt.Rows)
+                            {
+                                int BuyUserId = int.Parse(item["BuyUserId"].ToString());
+                                var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == BuyUserId);
+                                if (userAccount == null)
+                                {
+                                    userAccount = db.UserAccount.Add(new UserAccount()
+                                    {
+                                        Id = BuyUserId,
+                                        UserId = BuyUserId,
+                                    }).Entity;
+                                    db.SaveChanges();
+                                }
+                                var posInfo = query.Where(m => m.BuyUserId == BuyUserId);
+                                var amount = 0;
+                                foreach (var pos in posInfo)
+                                {
+                                    var poss = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.Id) ?? new PosMachinesTwo();
+                                    poss.ScanQrTrade = 999;
+                                    var Brand = brandInfo.FirstOrDefault(m => m.Id == pos.BrandId);
+                                    if (Brand.Name.Contains("电签"))
+                                    {
+                                        amount = 200;
+                                    }
+                                    if (Brand.Name.Contains("大POS"))
+                                    {
+                                        amount = 300;
+                                    }
+                                    userAccount.ToChargeAmount += amount;//增加预扣款
+                                    var toChargeBackRecord = db.ToChargeBackRecord.Add(new ToChargeBackRecord
+                                    {
+                                        CreateDate = DateTime.Now,
+                                        UserId = BuyUserId,
+                                        ChargeAmount = amount,
+                                        ChargeType = 124,//过期机具货款扣费
+                                        Remark = pos.PosSn,
+
+                                    }).Entity;
+                                }
+                            }
+                            db.SaveChanges();
+
+                            var info = db.ToChargeBackRecord.Where(m => m.Status == 0).ToList();//过期机具扣费记录
+                            foreach (var items in info)
+                            {
+                                var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == items.UserId) ?? new UserAccount();
+                                var record = info.FirstOrDefault(m => m.Id == items.Id);
+                                if (userAccount.BalanceAmount >= record.ChargeAmount)
+                                {
+                                    var userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord
+                                    {
+                                        CreateDate = DateTime.Now,
+                                        UserId = items.UserId,
+                                        BeforeBalanceAmount = userAccount.BalanceAmount,
+                                        AfterBalanceAmount = userAccount.BalanceAmount - record.ChargeAmount,
+                                        ChangeAmount = record.ChargeAmount,
+                                        ChangeType = 124,//过期机具货款扣费
+                                        Remark = "扣机具货款",
+
+                                    }).Entity;
+                                    record.Status = 1;
+                                    if (userAccount.ToChargeAmount >= record.ChargeAmount)
+                                    {
+                                        userAccount.ToChargeAmount -= record.ChargeAmount;//扣减预扣款
+                                    }
+                                    userAccount.BalanceAmount -= record.ChargeAmount;//扣减余额
+                                }
+                            }
+                            db.SaveChanges();
+
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "过期机具执行扣费异常");
+                    }
+                }
+                Thread.Sleep(1000);
+            }
+        }
+    }
+}

+ 83 - 0
AppStart/Helper/TimeOutPosSendMessageService.cs

@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Threading;
+using MySystem.Models;
+using Library;
+
+namespace MySystem
+{
+    /// <summary>
+    /// 过期机具预扣费消息推送
+    /// </summary>
+    public class TimeOutPosSendMessageService
+    {
+        public readonly static TimeOutPosSendMessageService Instance = new TimeOutPosSendMessageService();
+        private TimeOutPosSendMessageService()
+        { }
+
+        public void Start()
+        {
+            Thread th = new Thread(doSomething);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void doSomething()
+        {
+            while (true)
+            {
+                if (DateTime.Now.Hour < 20)
+                {
+                    try
+                    {
+                        string check = function.ReadInstance("/TimeOutPosSendMessage/check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
+                        if (string.IsNullOrEmpty(check))
+                        {
+                            function.WritePage("/TimeOutPosSendMessage/", "check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
+                            WebCMSEntities db = new WebCMSEntities();
+                            var date = DateTime.Now.AddDays(-55).ToString("yyyy-MM-dd 00:00:00");//过期限制时间
+                            var time = DateTime.Parse(date);//过期限制时间
+
+                            DataTable dt = CustomerSqlConn.dtable("SELECT BuyUserId FROM PosMachinesTwo WHERE `Status`>-1 AND BuyUserId>0 AND BindingState=0 AND ActivationState=0 AND ScanQrTrade=0 AND RecycEndDate <'" + date + "' GROUP BY BuyUserId", MysqlConn.connstr);//消息推送创客
+                            var query = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId > 0 && m.BindingState == 0 && m.ActivationState == 0 && m.ScanQrTrade == 0 && m.RecycEndDate < time).ToList();//循环过期超过55天机具
+                            var brandInfo = db.KqProducts.ToList();
+                            foreach (DataRow item in dt.Rows)
+                            {
+                                int BuyUserId = int.Parse(item["BuyUserId"].ToString());
+                                var BrandName = "";
+                                var PosSn = "";
+                                var SendInfo = "";
+                                foreach (var items in brandInfo)
+                                {
+                                    int BrandId = int.Parse(items.Id.ToString());
+                                    BrandName = items.Name.ToString();
+                                    var posInfo = query.Where(m => m.BuyUserId == BuyUserId && m.BrandId == BrandId);
+                                    foreach (var pos in posInfo)
+                                    {
+                                        PosSn += BrandName +":"+pos.PosSn + "," + "<br/>";
+                                    }
+                                }
+                                SendInfo = PosSn.TrimEnd(',') + "<br/>";
+                                RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
+                                {
+                                    UserId = BuyUserId, //创客
+                                    Title = "机具循环过期提醒", //标题
+                                    Content = "<div class='f16'>尊敬的创客您好:<br/>您的" + SendInfo + "循环已过期五十五天以上,请在五日内完成激活或通过机具回收回寄该机具。</ div > ",//内容
+                                    Summary = "系统检测到您的部分机具可回收,请打开我的-回收机具及时处理!",
+                                    CreateDate = DateTime.Now,
+                                }));
+                            }
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "过期机具预扣费消息推送异常");
+                    }
+                }
+                Thread.Sleep(1000);
+            }
+        }
+    }
+}

+ 1 - 1
Areas/Admin/Controllers/MainServer/PosMachinesTwoController.cs

@@ -923,7 +923,7 @@ namespace MySystem.Areas.Admin.Controllers
 
                 //实际押金
                 string SeoKeyword = dic["SeoKeyword"].ToString();
-                if (SeoKeyword.Length > 3)
+                if (SeoKeyword.Length > 2)
                 {
                     SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
                 }

+ 1 - 1
Areas/Admin/Controllers/MainServer/PosMerchantInfoListController.cs

@@ -263,11 +263,11 @@ namespace MySystem.Areas.Admin.Controllers
                 var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == KqSnNo) ?? new PosMachinesTwo();
                 //实际押金
                 string SeoKeyword = pos.SeoKeyword.ToString();
-                ReturnAmounts += decimal.Parse(function.CheckNum(SeoKeyword));
                 if (SeoKeyword.Length > 3)
                 {
                     SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
                 }
+                ReturnAmounts += decimal.Parse(SeoKeyword);
                 dic["SeoKeyword"] = SeoKeyword;
 
                 //设置押金

+ 5 - 1
Areas/Admin/Controllers/MainServer/ToChargeBackRecordController.cs

@@ -51,7 +51,7 @@ namespace MySystem.Areas.Admin.Controllers
         /// 待扣款明细列表
         /// </summary>
         /// <returns></returns>
-        public JsonResult IndexData(ToChargeBackRecord data, string UserIdMakerCode, string CreateDateData, string ChargeTypeSelect, string StatusSelect, int page = 1, int limit = 30)
+        public JsonResult IndexData(ToChargeBackRecord data, string UserIdMakerCode, string PosSn, string CreateDateData, string ChargeTypeSelect, string StatusSelect, int page = 1, int limit = 30)
         {
 
             Dictionary<string, string> Fields = new Dictionary<string, string>();
@@ -72,6 +72,10 @@ namespace MySystem.Areas.Admin.Controllers
             {
                 condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
             }
+            if (!string.IsNullOrEmpty(PosSn))
+            {
+                condition += " and Remark=" + PosSn;
+            }
             //待扣类型
             if (!string.IsNullOrEmpty(ChargeTypeSelect))
             {

+ 1 - 1
Areas/Admin/Views/MainServer/PosMerchantInfoList/Indexrg.cshtml

@@ -86,7 +86,7 @@
                         }
                     </div>
                     <blockquote class="layui-elem-quote layui-text">
-                        退押总金额:<span style="color: #f00;" id="ReturnAmounts">0.00</span> | 实际总金额:<span style="color: #f00;" id="ReturnAmount">0.00</span>
+                        退押总金额:<span style="color: #f00;" id="ReturnAmount">0.00</span> | 实际总金额:<span style="color: #f00;" id="ReturnAmounts">0.00</span>
                     </blockquote>
                 </div>
             </div>

+ 6 - 0
Areas/Admin/Views/MainServer/ToChargeBackRecord/Index.cshtml

@@ -57,6 +57,12 @@
                                 placeholder="" autocomplete="off">
                         </div>
                     </div>
+                    <div class="layui-inline">
+                        <label class="layui-form-label">机具SN</label>
+                        <div class="layui-input-inline">
+                            <input class="layui-input" type="text" name="PosSn" autocomplete="off">
+                        </div>
+                    </div>
                     <div class="layui-inline">
                         <label class="layui-form-label">状态</label>
                         <div class="layui-input-inline">

BIN
wwwroot/.DS_Store