浏览代码

调整接口

lcl 1 年之前
父节点
当前提交
70146be957

+ 69 - 37
AppStart/PublicFunction.cs

@@ -83,61 +83,93 @@ namespace MySystem
 
         public static void StatUserMachineData(int UserId, int BrandId, int Count)
         {
-            using (WebCMSEntities db = new WebCMSEntities())
+            WebCMSEntities db = new WebCMSEntities();
+            string IdBrand = UserId + "_" + BrandId;
+            UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+            if (MachineData == null)
             {
-                string IdBrand = UserId + "_" + BrandId;
-                UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
-                if (MachineData == null)
+                MachineData = db.UserMachineData.Add(new UserMachineData()
                 {
-                    MachineData = db.UserMachineData.Add(new UserMachineData()
-                    {
-                        IdBrand = IdBrand,
-                    }).Entity;
-                    db.SaveChanges();
-                }
-                if(Count < 0)
-                {
-                    MachineData.TotalMachineCount -= Math.Abs(Count);
-                    MachineData.UnBindCount -= Math.Abs(Count);
-                }
-                else
-                {
-                    MachineData.TotalMachineCount += Count;
-                    MachineData.UnBindCount += Count;
-                }
+                    IdBrand = IdBrand,
+                }).Entity;
                 db.SaveChanges();
             }
+            if(Count < 0)
+            {
+                MachineData.TotalMachineCount -= Math.Abs(Count);
+                MachineData.UnBindCount -= Math.Abs(Count);
+            }
+            else
+            {
+                MachineData.TotalMachineCount += Count;
+                MachineData.UnBindCount += Count;
+            }
+            db.SaveChanges();
+            db.Dispose();
         }
 
         #endregion
 
-        #region 设置押金添加记录公共方法
-        public static void MerchantDepositSet(int BrandId, int UserId, int SnId, string SnNo, int BeforeDeposit, decimal DepositAmount, string ReturnNote)
+        #region 绑定
+
+        public static void BindUserMachineData(WebCMSEntities db, int UserId, int BrandId, int Count, string PosSn)
         {
-            try
+            PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
+            pos.BindingState = 1;
+            pos.BindingTime = DateTime.Now;
+            string IdBrand = UserId + "_" + BrandId;
+            UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+            if (MachineData == null)
             {
-                WebCMSEntities maindb = new WebCMSEntities();
-                MerchantDepositSet query = maindb.MerchantDepositSet.Add(new MerchantDepositSet()
+                MachineData = db.UserMachineData.Add(new UserMachineData()
                 {
-                    CreateDate = DateTime.Now, //创建时间
-                    Sort = BrandId,//品牌
-                    SeoTitle = BeforeDeposit.ToString(),//变更前押金
-                    DepositAmount = DepositAmount,//押金
-                    ReturnNote = ReturnNote,//返回信息
-                    SnNo = SnNo,//机具Sn
-                    UserId = UserId,//创客Id
+                    IdBrand = IdBrand,
                 }).Entity;
-                maindb.SaveChanges();
-
+                db.SaveChanges();
             }
-            catch (Exception ex)
+            MachineData.UnBindCount -= Count;
+            MachineData.BindCount += Count;
+            db.SaveChanges();
+        }
+
+        #endregion
+
+        #region 划拨记录
+
+        public static void SendRecord(WebCMSEntities db, int UserId, int ToUserId, int StoreId, string[] PosSnList)
+        {
+            string ChangeRecordNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
+            for (int i = 0; i < PosSnList.Length; i++)
             {
+                string PosSn = PosSnList[i];
+                PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
+                pos.StoreId = StoreId;
+                pos.TransferTime = DateTime.Now;
+                pos.BuyUserId = ToUserId;
+                pos.UserId = ToUserId;
 
-                function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + ex.ToString(), "设置押金队列异常");
+                db.PosCouponRecord.Add(new PosCouponRecord()
+                {
+                    CreateDate = DateTime.Now,
+                    OrderNo = ChangeRecordNo,
+                    ToUserId = ToUserId,
+                    FromUserId = UserId,
+                    PosCouponId = pos.Id,
+                });
             }
+            int SnCount = PosSnList.Length;
+            db.PosCouponOrders.Add(new PosCouponOrders()
+            {
+                CreateDate = DateTime.Now,
+                ChangeCount = SnCount,
+                OrderNo = ChangeRecordNo,
+                ToUserId = ToUserId,
+                FromUserId = UserId,
+            });
+            db.SaveChanges();
         }
-        #endregion
 
+        #endregion
 
 
         #region 获取jwt的token

+ 29 - 35
Areas/Api/Controllers/v1/MainServer/KqProductsController.cs

@@ -68,43 +68,37 @@ namespace MySystem.Areas.Api.Controllers.v1
             string UserId = data["UserId"].ToString(); //创客Id
             
             List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
-            List<KqProducts> querys = KqProductsDbconn.Instance.GetList();
-            foreach (KqProducts query in querys)
+            Dictionary<string, object> Obj = new Dictionary<string, object>();
+
+            UserMachineData MachineData = UserMachineDataDbconn.Instance.Get(UserId + "_0") ?? new UserMachineData();
+            Dictionary<string, object> Machine = new Dictionary<string, object>();
+            Machine.Add("TotalMachineCount", MachineData.TotalMachineCount);  //总机具数
+            Machine.Add("UnBindCount", MachineData.UnBindCount); //未绑定机具数
+            Machine.Add("BindCount", MachineData.BindCount); //已绑定机具数
+            Obj.Add("Machine", Machine); //机具管理数据
+
+            Dictionary<string, object> Profit = new Dictionary<string, object>();
+            Profit.Add("TradeProfit", MachineData.TradeProfit); //交易分润
+            Profit.Add("ActProfit", MachineData.ActProfit); //激活奖励
+            Profit.Add("OpenProfit", MachineData.OpenProfit); //开机奖励
+            Profit.Add("DividendsProfit", MachineData.DividendsProfit); //分红奖励
+            Profit.Add("OtherProfit", MachineData.OtherProfit); //分润补贴
+            Profit.Add("FluxProfit", MachineData.FluxProfit); //流量卡分佣
+            Obj.Add("Profit", Profit); //收益查看数据
+
+            List<Dictionary<string, object>> Advertisment = new List<Dictionary<string, object>>();
+            string ColId = "";
+            List<Models.Advertisment> ads = AdvertismentDbconn.Instance.GetList(ColId);
+            foreach (Models.Advertisment ad in ads)
             {
-                Dictionary<string, object> Obj = new Dictionary<string, object>();
-                Obj.Add("Id", query.Id);
-                Obj.Add("Name", query.Name); //名称
-
-                UserMachineData MachineData = UserMachineDataDbconn.Instance.Get(UserId + "_" + query.Id) ?? new UserMachineData();
-                Dictionary<string, object> Machine = new Dictionary<string, object>();
-                Machine.Add("TotalMachineCount", MachineData.TotalMachineCount);  //总机具数
-                Machine.Add("UnBindCount", MachineData.UnBindCount); //未绑定机具数
-                Machine.Add("BindCount", MachineData.BindCount); //已绑定机具数
-                Obj.Add("Machine", Machine); //机具管理数据
-
-                Dictionary<string, object> Profit = new Dictionary<string, object>();
-                Profit.Add("TradeProfit", MachineData.TradeProfit); //交易分润
-                Profit.Add("ActProfit", MachineData.ActProfit); //激活奖励
-                Profit.Add("OpenProfit", MachineData.OpenProfit); //开机奖励
-                Profit.Add("DividendsProfit", MachineData.DividendsProfit); //分红奖励
-                Profit.Add("OtherProfit", MachineData.OtherProfit); //分润补贴
-                Profit.Add("FluxProfit", MachineData.FluxProfit); //流量卡分佣
-                Obj.Add("Profit", Profit); //收益查看数据
-
-                List<Dictionary<string, object>> Advertisment = new List<Dictionary<string, object>>();
-                string ColId = "";
-                List<Models.Advertisment> ads = AdvertismentDbconn.Instance.GetList(ColId);
-                foreach (Models.Advertisment ad in ads)
-                {
-                    Dictionary<string, object> item = new Dictionary<string, object>();
-                    item.Add("Url", ad.Url); //跳转地址
-                    item.Add("BannerPic", DefaultPic(ad.PicPath)); //广告图片
-                    item.Add("Id", ad.Id); //Id
-                    Advertisment.Add(item);
-                }
-                Obj.Add("Advertisment", Advertisment);
-                list.Add(Obj);
+                Dictionary<string, object> item = new Dictionary<string, object>();
+                item.Add("Url", ad.Url); //跳转地址
+                item.Add("BannerPic", DefaultPic(ad.PicPath)); //广告图片
+                item.Add("Id", ad.Id); //Id
+                Advertisment.Add(item);
             }
+            Obj.Add("Advertisment", Advertisment);
+            list.Add(Obj);
             return list;
         }
         #endregion

+ 27 - 41
Areas/Api/Controllers/v1/MainServer/MerchantQrCodeController.cs

@@ -92,6 +92,10 @@ namespace MySystem.Areas.Api.Controllers.v1
             {
                 return new AppResultJson() { Status = "-1", Info = "绑定失败" };
             }
+            if(pos.BuyUserId == 0)
+            {
+                return new AppResultJson() { Status = "-1", Info = "码牌未授权" };
+            }
             if (query.Id > 0)
             {
                 if (query.MerchantId > 0)
@@ -106,53 +110,35 @@ namespace MySystem.Areas.Api.Controllers.v1
                 SnNo = SnNo,
             }).Entity;
             maindb.SaveChanges();
-            // PosMachines machine = maindb.PosMachines.FirstOrDefault(m => m.PosSn == MachineNo);
-            // if (machine != null)
-            // {
-            //     if (machine.BindMerchantId > 0)
-            //     { 
-            //         return new AppResultJson() { Status = "-1", Info = "音箱码已被绑定,请勿重复绑定" };
-            //     }
-            //     return new AppResultJson() { Status = "1", Info = "绑定成功,收款码暂未关联音箱", Data = Obj };
-            // }
-            // else if (!string.IsNullOrEmpty(MachineNo))
-            // {
-                // machine = maindb.PosMachines.Add(new PosMachines(){
-                //     PosSn = MachineNo,
-                //     BindMerchantId = MerchantId,
-                //     BindingState = 1,
-                //     BindingTime = DateTime.Now,
-                // }).Entity;
-                // maindb.SaveChanges();
-
-                // string DataId = query.Id + "_" + machine.Id;
-                string DataId = query.Id + "_0";
-                MachineForQrCode forQrCode = maindb.MachineForQrCode.FirstOrDefault(m => m.DataId == DataId);
-                if (forQrCode == null)
-                {
-                    forQrCode = maindb.MachineForQrCode.Add(new MachineForQrCode(){
-                        DataId = DataId,
-                        SnNo = SnNo,
-                        MachineSnNo = MachineNo,
-                        BindDate = DateTime.Now,
-                        MerchantId = MerchantId,
-                    }).Entity;
-                }
-                else
-                { 
-                    forQrCode.SnNo = SnNo;
-                    forQrCode.MachineSnNo = MachineNo;
-                    forQrCode.BindDate = DateTime.Now;
-                    forQrCode.MerchantId = MerchantId;
-                }
-                maindb.SaveChanges();
-            // }
+            string DataId = query.Id + "_0";
+            MachineForQrCode forQrCode = maindb.MachineForQrCode.FirstOrDefault(m => m.DataId == DataId);
+            if (forQrCode == null)
+            {
+                forQrCode = maindb.MachineForQrCode.Add(new MachineForQrCode(){
+                    DataId = DataId,
+                    SnNo = SnNo,
+                    MachineSnNo = MachineNo,
+                    BindDate = DateTime.Now,
+                    MerchantId = MerchantId,
+                }).Entity;
+            }
+            else
+            { 
+                forQrCode.SnNo = SnNo;
+                forQrCode.MachineSnNo = MachineNo;
+                forQrCode.BindDate = DateTime.Now;
+                forQrCode.MerchantId = MerchantId;
+            }
+            maindb.SaveChanges();
             pos.BuyUserId = merchant.UserId;
             pos.UserId = merchant.UserId;
             pos.BindingTime = DateTime.Now;
             pos.BindingState = 1;
             pos.BindMerchantId = MerchantId;
             maindb.SaveChanges();
+
+            PublicFunction.BindUserMachineData(maindb, merchant.UserId, 0, 1, SnNo);
+            
             return new AppResultJson() { Status = "1", Info = "绑定成功" };
         }
         #endregion

+ 20 - 17
Areas/Api/Controllers/v1/MainServer/PosCouponOrdersController.cs

@@ -71,20 +71,21 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
                 if(ChangeKind == 1)
                 {
                     KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.FromUserId) ?? new KxsMainModels.Users();
-                    RealName = user.RealName;
-                    MakerCode = user.MakerCode;
+                    RealName = function.CheckNull(user.RealName);
+                    MakerCode = function.CheckNull(user.MakerCode);
+                    if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓";
                 }
                 else
                 {
                     KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.ToUserId) ?? new KxsMainModels.Users();
-                    RealName = user.RealName;
-                    MakerCode = user.MakerCode;
+                    RealName = function.CheckNull(user.RealName);
+                    MakerCode = function.CheckNull(user.MakerCode);
                 }
-                if (RealName.Length > 2)
+                if (RealName.Length > 2 && RealName != "成都总仓")
                 {
                     RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1);
                 }
-                else
+                else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓")
                 { 
                     RealName = RealName.Substring(0, 1) + "*";
                 }
@@ -97,10 +98,10 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
             other = new Dictionary<string, object>();
             if(PageNum == 1)
             {
-                DataTable dt = CustomerSqlConn.dtable("select count(if(ChangeKind=1, Id, 0)),count(if(ChangeKind=2, Id, 0)) from PosCouponOrders where ToUserId=" + UserId + " or FromUserId=" + UserId + "", AppConfig.Base.SqlConnStr);
+                DataTable dt = CustomerSqlConn.dtable("select (select count(Id) from PosCouponOrders where FromUserId=" + UserId + "),(select count(Id) from PosCouponOrders where ToUserId=" + UserId + ")", AppConfig.Base.SqlConnStr);
                 if(dt.Rows.Count > 0)
                 {
-                    other.Add("FromTotalCount", dt.Rows[0][0].ToString());
+                    other.Add("FromTotalCount", dt.Rows[0][1].ToString());
                     other.Add("ToTotalCount", dt.Rows[0][0].ToString());
                 }
             }
@@ -134,22 +135,23 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
             if(query.ToUserId == UserId)
             {
                 KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.FromUserId) ?? new KxsMainModels.Users();
-                RealName = user.RealName;
-                MakerCode = user.MakerCode;
-                Mobile = user.Mobile;
+                RealName = function.CheckNull(user.RealName);
+                MakerCode = function.CheckNull(user.MakerCode);
+                Mobile = function.CheckNull(user.Mobile);
+                if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓";
             }
             else
             {
                 KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.ToUserId) ?? new KxsMainModels.Users();
-                RealName = user.RealName;
-                MakerCode = user.MakerCode;
-                Mobile = user.Mobile;
+                RealName = function.CheckNull(user.RealName);
+                MakerCode = function.CheckNull(user.MakerCode);
+                Mobile = function.CheckNull(user.Mobile);
             }
-            if (RealName.Length > 2)
+            if (RealName.Length > 2 && RealName != "成都总仓")
             {
                 RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1);
             }
-            else
+            else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓")
             { 
                 RealName = RealName.Substring(0, 1) + "*";
             }
@@ -159,7 +161,8 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
             Obj.Add("ChangeCount", query.ChangeCount); //变更数量
             Obj.Add("ChangeKind", query.ChangeKind); //变更类型
             Obj.Add("CreateDate", query.CreateDate); //创建时间
-            List<string> list = maindb.PosCouponRecord.Where(m => m.OpId == query.Id).ToList().Select(m => m.OrderNo).ToList();
+            List<int> posids = maindb.PosCouponRecord.Where(m => m.OrderNo == query.OrderNo).ToList().Select(m => m.PosCouponId).ToList();
+            List<string> list = maindb.PosMachinesTwo.Where(m => posids.Contains(m.Id)).ToList().Select(m => m.PosSn).ToList();
             Obj.Add("SnNoList", list); //机具券列表
             return Obj;
         }

+ 11 - 44
Areas/Api/Controllers/v1/MainServer/PosCouponRecordController.cs

@@ -67,6 +67,10 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
                     {
                         return new AppResultJson() { Status = "-1", Info = pos.PosSn + "已划拨,请勿重复划拨", Data = Obj };
                     }
+                    if(pos.BindingState == 1)
+                    {
+                        return new AppResultJson() { Status = "-1", Info = pos.PosSn + "已绑定,无法划拨", Data = Obj };
+                    }
                     PosCouponRecord query = maindb.PosCouponRecord.Add(new PosCouponRecord()
                     {
                         CreateDate = DateTime.Now,
@@ -77,58 +81,21 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
                     }).Entity;
                     pos.BuyUserId = ToUserId;
                     pos.UserId = ToUserId;
-                    maindb.SaveChanges();
-                }
-                int SnCount = SnIdList.Length;
-                PosCouponForUser forUser = maindb.PosCouponForUser.FirstOrDefault(m => m.Id == UserId);
-                if (forUser == null)
-                {
-                    forUser = maindb.PosCouponForUser.Add(new PosCouponForUser()
-                    {
-                        Id = UserId,
-                    }).Entity;
-                    maindb.SaveChanges();
                 }
-                int BeforeOut = forUser.OutNum;
-                int BeforeTotal = forUser.TotalNum;
-                int BeforeStock = forUser.StockNum;
-                forUser.OutNum += SnCount;
-                forUser.StockNum -= SnCount;
-                int AfterOut = forUser.OutNum;
-                int AfterTotal = forUser.TotalNum;
-                int AfterStock = forUser.StockNum;
                 maindb.SaveChanges();
-                PosCouponForUser forToUser = maindb.PosCouponForUser.FirstOrDefault(m => m.Id == ToUserId);
-                if (forToUser == null)
-                {
-                    forToUser = maindb.PosCouponForUser.Add(new PosCouponForUser()
-                    {
-                        Id = ToUserId,
-                    }).Entity;
-                    maindb.SaveChanges();
-                }
-                BeforeOut = forToUser.OutNum;
-                BeforeTotal = forToUser.TotalNum;
-                BeforeStock = forToUser.StockNum;
-                forToUser.TotalNum += SnCount;
-                forToUser.StockNum += SnCount;
-                AfterOut = forToUser.OutNum;
-                AfterTotal = forToUser.TotalNum;
-                AfterStock = forToUser.StockNum;
+                int SnCount = SnIdList.Length;
                 PosCouponOrders tostat = maindb.PosCouponOrders.Add(new PosCouponOrders()
                 {
                     CreateDate = DateTime.Now,
                     ChangeCount = SnCount,
-                    AfterOut = AfterOut,
-                    AfterTotal = AfterTotal,
-                    AfterStock = AfterStock,
-                    BeforeOut = BeforeOut,
-                    BeforeTotal = BeforeTotal,
-                    BeforeStock = BeforeStock,
                     OrderNo = ChangeRecordNo,
-                    ToUserId = UserId,
-                    FromUserId = ToUserId,
+                    ToUserId = ToUserId,
+                    FromUserId = UserId,
                 }).Entity;
+                
+                PublicFunction.StatUserMachineData(UserId, 0, -SnCount);
+                PublicFunction.StatUserMachineData(ToUserId, 0, SnCount);
+
                 maindb.SaveChanges();
             }
             return new AppResultJson() { Status = "1", Info = "", Data = Obj };

+ 2 - 2
Areas/Api/Controllers/v1/MainServer/PosMachinesController.cs

@@ -298,7 +298,7 @@ namespace MySystem.Areas.Api.Controllers.v1
             {
                 PageSize = 100000;
             }
-            IQueryable<PosMachinesTwo> query = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId && m.BindingState == 1);
+            IQueryable<PosMachinesTwo> query = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BindingState == 1);
             if (!string.IsNullOrEmpty(SnNo))
             {
                 query = query.Where(m => m.PosSn == SnNo);
@@ -445,7 +445,7 @@ namespace MySystem.Areas.Api.Controllers.v1
             {
                 PageSize = 100000;
             }
-            IQueryable<PosMachinesTwo> query = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId && m.BindingState == 0);
+            IQueryable<PosMachinesTwo> query = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BindingState == 0);
             if (!string.IsNullOrEmpty(SnNo))
             {
                 query = query.Where(m => m.PosSn == SnNo && m.PosSnType == 0);

+ 4 - 1
Controllers/HomeController.cs

@@ -69,7 +69,10 @@ namespace MySystem.Controllers
 
             // result = new WeChatFunction().AddReceive("1645266943", "PERSONAL_OPENID", "ooDpv5LkCKEguE-LMZO-rSV4TDpk", "", "USER");
             // result = new WeChatFunction().QueryProfitShare("1645266943", "4200001815202306025662773463", "2023060213335030713572885");
-            result = new WeChatFunction().Unfreeze("1645266943", "4200001846202306021274142861", "2023060214014405449699901", "结算");
+            // result = new WeChatFunction().Unfreeze("1645266943", "4200001846202306021274142861", "2023060214014405449699901", "结算");
+
+            
+
             return result;
         }
     }