浏览代码

逻辑写完

lcl 1 年之前
父节点
当前提交
0489fa1f0f

+ 2 - 2
AppStart/RabbitMQClient.cs

@@ -139,12 +139,12 @@ namespace MySystem
                 CreateConn();
             }
             var channel = _connection.CreateModel();
-            channel.QueueDeclare(QueueName, true, false, false);
+            channel.QueueBind(QueueName, "kxs_dead_ranch", "DEAD_QUEUE_GD_ACT_DIVISION");
             EventingBasicConsumer consumer = new EventingBasicConsumer(channel);
             consumer.Received += (a, e) =>
             {
                 string MsgContent = Encoding.Default.GetString(e.Body.ToArray());
-                
+                function.WriteLog(MsgContent);
                 channel.BasicAck(e.DeliveryTag, true); //收到回复后,RabbitMQ会直接在队列中删除这条消息
             };
             channel.BasicConsume(QueueName, false, consumer);

+ 182 - 0
AppStart/Service/SycnSpBindService.cs

@@ -0,0 +1,182 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using MySystem.SpModels;
+using Library;
+using LitJson;
+using System.Threading;
+
+namespace MySystem
+{
+    public class SycnSpBindService
+    {
+        public readonly static SycnSpBindService Instance = new SycnSpBindService();
+        private SycnSpBindService()
+        { }
+
+        public void SimDo(RadioCardItem Bind)
+        {
+            try
+            {
+                WebCMSEntities spdb = new WebCMSEntities();
+                PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
+                DateTime start = DateTime.Now.AddDays(-60);
+                PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.iccId) ?? new PxcModels.MachineForSnNo();
+                PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
+                if (pos != null)
+                {
+                    string KindName = Bind.productTypeName; //商品类型名称
+                    string Name = Bind.productName; //商品名称
+                    pos.BindingState = 1;
+                    pos.BindingTime = DateTime.Parse(Bind.orderCreateTime);
+                    pos.Status = 0;
+                    pos.IsFirst = 1;
+                    if(Name == "激活后补卡")
+                    {
+                        PxcModels.MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.phoneNo);
+                        if(forMerNo != null)
+                        {
+                            PxcModels.PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forMerNo.SnId);
+                            if(oldpos != null)
+                            {
+                                oldpos.IsFirst = 0;
+                                pos.BindingState = oldpos.BindingState;
+                                pos.BindingTime = oldpos.BindingTime;
+                                pos.ActivationState = oldpos.ActivationState;
+                                pos.ActivationTime = oldpos.ActivationTime;
+                            }
+                        }
+                    }
+
+                    decimal ActualAmount = Bind.paidInAmount; //实付金额
+                    string ActStatus = Bind.activationStatusName; //激活状态名称
+                    if (KindName == "基础套餐" && Name == "双百套餐" && ActStatus == "已激活" && ActualAmount >= 100)
+                    {
+                        pos.Detail = "0";
+                    }
+                    else
+                    {
+                        pos.Detail = "1";
+                    }
+
+                    PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.phoneNo);
+                    if (merFor == null)
+                    {
+                        merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
+                        {
+                            MerNo = Bind.phoneNo,
+                            SnId = pos.Id,
+                        }).Entity;
+                    }
+                    else
+                    {
+                        merFor.SnId = pos.Id;
+                    }
+
+                    PxcModels.PosMerchantInfo add = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.phoneNo && m.KqSnNo == Bind.iccId);
+                    if (add == null)
+                    {
+                        add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
+                        {
+                            CreateDate = DateTime.Parse(Bind.orderCreateTime),
+                            KqMerNo = Bind.phoneNo,
+                            KqSnNo = Bind.iccId,
+                            MerchantNo = Bind.phoneNo.Length > 16 ? Bind.phoneNo.Substring(0, 16) : Bind.phoneNo,
+                        }).Entity;
+                        db.SaveChanges();
+                    }
+                    string json = Newtonsoft.Json.JsonConvert.SerializeObject(Bind);
+                    string ProductName = ""; //商品名称
+                    string ActivityName = ""; //促销活动名称
+                    string ProductTypeName = ""; //商品类型名称
+                    string ActStatusName = ""; //激活状态名称
+                    string ActAmount = ""; //实付金额
+                    string EmployeeNo = ""; //员工工号
+                    string EmployeeName = ""; //员工姓名
+                    if(!string.IsNullOrEmpty(json))
+                    {
+                        JsonData jsonObj = JsonMapper.ToObject(json);
+                        ProductName = jsonObj["productName"].ToString();
+                        ProductTypeName = jsonObj["productTypeName"].ToString();
+                        ActAmount = jsonObj["paidInAmount"].ToString();
+                        ActStatusName = jsonObj["activationStatusName"].ToString();
+                        EmployeeNo = jsonObj["jobId"].ToString();
+                    }
+                    PxcModels.SimposMerchantInfo sim = db.SimposMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.phoneNo);
+                    if (sim == null)
+                    {                                    
+                        sim = db.SimposMerchantInfo.Add(new PxcModels.SimposMerchantInfo()
+                        {
+                            Id = add.Id,
+                            CreateDate = DateTime.Parse(Bind.orderCreateTime),
+                            KqMerNo = Bind.phoneNo,
+                            MerchantNo = Bind.phoneNo.Length > 16 ? Bind.phoneNo.Substring(0, 16) : Bind.phoneNo,
+                        }).Entity;
+                        db.SaveChanges();
+                    }
+                    sim.KqSnNo = Bind.iccId;
+                    sim.ProductName = ProductName;
+                    sim.ActivityName = ActivityName;
+                    sim.ProductTypeName = ProductTypeName;
+                    sim.ActStatusName = ActStatusName;
+                    sim.ActAmount = decimal.Parse(ActAmount);
+                    sim.EmployeeNo = EmployeeNo;
+                    sim.EmployeeName = EmployeeName;
+                    pos.BindMerchantId = add.Id;
+                    pos.LastMerchantId = add.Id;
+                    if(pos.CardType < 2)
+                    {
+                        pos.IsPurchase = 1;
+                    }
+
+                    // sim.UpdateDate = Bind.UpdateTime;
+                    sim.TopUserId = 1;
+                    sim.BrandId = pos.BrandId;
+                    sim.SnStoreId = pos.StoreId;
+                    if(ActStatus == "已激活")
+                    {
+                        sim.MerStandardDate = DateTime.Now;
+                        sim.ActiveStatus = 1;
+                    }
+                    sim.UserId = pos.UserId;
+                    // sim.MgrName = Bind.MerName;
+                    sim.MerStatus = 1;
+                    sim.KqSnNo = pos.PosSn;
+                    // sim.MerRealName = Bind.MerName;
+                    sim.MerchantMobile = Bind.phoneNo;
+                    sim.MerchantName = Bind.phoneNo;
+                    sim.Type = pos.CardType + 1;
+                    db.SaveChanges();
+
+                    string IdBrand = pos.UserId + "_" + pos.BrandId;
+                    PxcModels.UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+                    if (MachineData == null)
+                    {
+                        MachineData = db.UserMachineData.Add(new PxcModels.UserMachineData()
+                        {
+                            IdBrand = IdBrand,
+                        }).Entity;
+                        db.SaveChanges();
+                    }
+                    MachineData.BindCount += 1;
+                    MachineData.UnBindCount -= 1;
+
+                    if(Bind.activationStatusName == "已激活")
+                    {
+                        bool PrizeFlag = pos.CardType > 0;
+                        SycnSpTradeService.Instance.ActPos(db, pos, 0, 30, PrizeFlag, Bind.activationTime);
+                    }
+                    db.SaveChanges();
+                }
+                spdb.SaveChanges();
+                spdb.Dispose();
+                db.SaveChanges();
+                db.Dispose();
+            }
+            catch (Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP绑定数据到MAIN异常");
+            }
+        }
+    }
+}

+ 105 - 0
AppStart/Service/SycnSpTradeService.cs

@@ -0,0 +1,105 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using MySystem.SpModels;
+using Library;
+using LitJson;
+using System.Threading;
+
+namespace MySystem
+{
+    public class SycnSpTradeService
+    {
+        public readonly static SycnSpTradeService Instance = new SycnSpTradeService();
+        private SycnSpTradeService()
+        { }
+
+        
+        //激活逻辑
+        public void ActPos(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, decimal CheckMoney, int CheckDays, bool PrizeFlag = true, string ActivationTime = "")
+        {
+            DateTime now = DateTime.Now;
+            if(!string.IsNullOrEmpty(ActivationTime))
+            {
+                now = DateTime.Parse(ActivationTime);
+            }
+            DateTime TransferTime = pos.TransferTime == null ? DateTime.Now : pos.TransferTime.Value;
+            int minute = 30;
+            if (pos.CreditTrade >= CheckMoney && pos.BuyUserId > 0 && pos.ActivationState == 0 && TransferTime.AddMinutes(-minute) < pos.BindingTime)
+            {
+                pos.ActivationState = 1;
+                pos.ActivationTime = now;
+                if(pos.CardType == 101)
+                {
+                    pos.IsPurchase = 1;
+                }
+                function.WriteLog("机具" + pos.PosSn, "开机奖励在激活中监控");
+                function.WriteLog("PrizeFlag:" + PrizeFlag, "开机奖励在激活中监控");
+                PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
+                if (merchant != null)
+                {
+                    function.WriteLog("查询到商户", "开机奖励在激活中监控");
+                    merchant.ActiveStatus = 1;
+                    merchant.MerStandardDate = now;
+                    db.SaveChanges();
+
+                    function.WriteLog("商户" + merchant.KqMerNo, "开机奖励在激活中监控");
+
+                    //发放开机奖励
+                    function.WriteLog("首台" + pos.IsFirst, "开机奖励在激活中监控");
+                    if(pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
+                    {
+                        function.WriteLog("开机奖发放", "开机奖励在激活中监控");
+                        RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
+                        if(pos.BrandId == 14)
+                        {
+                            if(pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now))
+                            {
+                                RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
+                            }
+                            RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
+                        }
+                    }
+                }
+                //发放大盟主奖励
+                function.WriteLog("大盟主---PrizeFlag:" + PrizeFlag + ";LeaderUserId:" + pos.LeaderUserId + ";pos.IsFirst:" + pos.IsFirst + ";pos.BindingTime:" + pos.BindingTime + ";now.AddDays(-CheckDays):" + now.AddDays(-CheckDays) + ";", "开机奖励在激活中监控");
+                decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
+                if (Deposit > 0 && pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
+                {
+                    function.WriteLog("大盟主奖发放", "开机奖励在激活中监控");
+                    RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
+                }
+                //发放运营中心奖励
+                if (Deposit > 0 && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
+                {
+                    function.WriteLog("运营中心奖发放", "开机奖励在激活中监控");
+                    RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
+                }
+                if(pos.CardType < 100)
+                {
+                    // AlipayPayBack2Service.Instance.ActReserveBack(pos.OpId, pos.OpReserve1, pos.OpReserve2, pos.OpReserve3);
+                    //统计激活数
+                    RedisDbconn.Instance.AddList("StatActQueue", "{\"TradeDate\":\"" + now.ToString("yyyyMMdd") + "\",\"UserId\":\"" + pos.BuyUserId + "\",\"BrandId\":\"" + pos.BrandId + "\"}");
+                    //运营中心额度变更
+                    OpAmountItem item = new OpAmountItem()
+                    {
+                        UserId = pos.OpId,
+                        OperateType = 1,
+                        ChangeType = 9,
+                        Remark = "机具激活",
+                        UseAmount = pos.OpReserve1 + pos.OpReserve2 + pos.OpReserve3,
+                        UseValidForGetAmount = pos.OpReserve2,
+                        UseTotalAmt = pos.OpReserve1,
+                        UseValidAmount = pos.OpReserve3,
+                        DataType = 2,
+                        DataId = pos.Id,
+                    };
+                    RedisDbconn.Instance.AddList("OperateAmountRecordServiceQueue", item);
+                }
+                //清理预扣款
+                RedisDbconn.Instance.AddList("PosWithholdQueue", "{\"UserId\":\"" + pos.BuyUserId + "\",\"SnNo\":\"" + pos.PosSn + "\"}");
+                
+            }
+        }
+    }
+}

+ 49 - 0
AppStart/Tables/OpAmountItem.cs

@@ -0,0 +1,49 @@
+using System;
+namespace MySystem
+{
+    public class OpAmountItem
+    {
+        //创客Id
+        public int UserId { get; set; }
+
+
+        //操作类型(1增加,2减少)
+        public int OperateType { get; set; }
+
+
+        //类别
+        public int ChangeType { get; set; }
+
+
+        //备注
+        public string Remark { get; set; }
+
+
+        //变更总额度
+        public decimal UseAmount { get; set; }
+
+
+        //变更可提现额度
+        public decimal UseValidForGetAmount { get; set; }
+
+
+        //变更未使用额度
+        public decimal UseTotalAmt { get; set; }
+
+
+        //变更关联分仓额度
+        public decimal UseValidAmount { get; set; }
+
+
+        //来源类型,区分表(1订单,2机具,3申请记录,4购买运营中心,5预扣款,6机具券,7兑换大盟主,8仓库)
+        public int DataType { get; set; }
+
+
+        //来源Id,表的主键Id
+        public int DataId { get; set; }
+
+
+        //是否入账
+        public int NoAccount { get; set; }
+    }
+}

+ 74 - 0
AppStart/Tables/RadioCardItem.cs

@@ -0,0 +1,74 @@
+using System;
+
+namespace MySystem
+{
+    public class RadioCardItem
+    {
+        /**
+         * 订单号
+         */
+        public string orderNo;
+        /**
+         * 订单创建时间
+         */
+        public string orderCreateTime;
+        /**
+         * 用户选择号码
+         */
+        public string phoneNo;
+        /**
+         * 是否首充(中文):是,否
+         */
+        public string firstCharge;
+        /**
+         * 首充金额(元)
+         */
+        public decimal initialChargeAmount;
+        /**
+         * 省
+         */
+        public string province;
+        /**
+         * 城市
+         */
+        public string city;
+        /**
+         * 商品名称
+         */
+        public string productName;
+        /**
+         * 促销活动名称
+         */
+        public string promotionName;
+        /**
+         * 商品类型名称
+         */
+        public string productTypeName;
+        /**
+         * 实付金额(元)
+         */
+        public decimal paidInAmount;
+        /**
+         * 订单状态(中文):待
+         * 激活、已完成、退款
+         * 中、未知
+         */
+        public string orderStatus;
+        /**
+         * 激活状态(中文):待激活、已激活、未知
+         */
+        public string activationStatusName;
+        /**
+         * 激活时间
+         */
+        public string activationTime;
+        /**
+         * 开卡人工号
+         */
+        public string jobId;
+        /**
+         * SIM 卡号
+         */
+        public string iccId;
+    }
+}

+ 1 - 1
Startup.cs

@@ -133,7 +133,7 @@ namespace MySystem
             });
 
             //必须打开的
-            
+            RabbitMQClient.Instance.StartReceive("QUEUE_GD_ACT_DIVISION");
         }
     }
 }

+ 4 - 4
appsettings.Development.json

@@ -17,10 +17,10 @@
     "Host": "http://localhost:5346/",
     "SourceHost": "http://oss.kexiaoshuang.com/",
     "Database": "KxsMainServer",
-    "SqlConnStr": "server=rm-2vcu953x4yx7z454who.rwlb.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;database=KxsProfitServer;charset=utf8;ConnectionTimeout=600;DefaultCommandTimeout=600;",
-    "Pxc1SqlConnStr": "server=rm-2vcu953x4yx7z454who.rwlb.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;database=KxsProfitServer;charset=utf8;ConnectionTimeout=600;DefaultCommandTimeout=600;",
-    "ReadSqlConnStr": "server=rm-2vcu953x4yx7z454who.rwlb.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;database=KxsProfitServer;charset=utf8;",
-    "MainSqlConnStr": "server=rm-2vcu953x4yx7z454who.rwlb.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;database=KxsStatServer;charset=utf8;",
+    "SqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsProfitServer;charset=utf8;ConnectionTimeout=600;DefaultCommandTimeout=600;",
+    "Pxc1SqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsProfitServer;charset=utf8;ConnectionTimeout=600;DefaultCommandTimeout=600;",
+    "ReadSqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsProfitServer;charset=utf8;",
+    "MainSqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsStatServer;charset=utf8;",
     "SpSqlConnStr": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsSpServer;charset=utf8;",
     "OpSqlConnStr": "server=rm-2vcu953x4yx7z454who.rwlb.cn-chengdu.rds.aliyuncs.com;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;port=3306;database=KxsOpServer;charset=utf8;",
     "MpSqlConnStr": "server=47.109.31.237;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer;charset=utf8;",