Browse Source

划拨记录和详情

DuGuYang 1 year ago
parent
commit
8b6a374afe

+ 1 - 1
AppStart/Redis/MySql/UserMachineDataDbconn.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using Library;
 using System.Linq;
-using MySystem.Models.Main;
+using MySystem.Models.Main1;
 
 namespace MySystem
 {

+ 3 - 3
Areas/Api/Controllers/Main/KqProductsController.cs

@@ -70,8 +70,8 @@ namespace MySystem.Areas.Api.Controllers.v1
             List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
             Dictionary<string, object> Obj = new Dictionary<string, object>();
 
-            Models.Main.UserMachineData MachineData = UserMachineDataDbconn.Instance.Get(UserId + "_0") ?? new Models.Main.UserMachineData();
-            Models.Main.UserMachineData MachineData2 = UserMachineDataDbconn.Instance.Get(UserId + "_1") ?? new Models.Main.UserMachineData();
+            Models.Main1.UserMachineData MachineData = UserMachineDataDbconn.Instance.Get(UserId + "_0") ?? new Models.Main1.UserMachineData();
+            Models.Main1.UserMachineData MachineData2 = UserMachineDataDbconn.Instance.Get(UserId + "_1") ?? new Models.Main1.UserMachineData();
             Dictionary<string, object> Machine = new Dictionary<string, object>();
             Dictionary<string, object> Machine2 = new Dictionary<string, object>();
             Machine.Add("TotalMachineCount", MachineData.TotalMachineCount);  //总机具数
@@ -82,7 +82,7 @@ namespace MySystem.Areas.Api.Controllers.v1
             Machine2.Add("TotalMachineCount2", MachineData2.TotalMachineCount);  //总机具数
             Machine2.Add("UnBindCount2", MachineData2.UnBindCount); //未绑定机具数
             Machine2.Add("BindCount2", MachineData2.BindCount); //已绑定机具数
-            Obj.Add("Machine", Machine2); //机具管理数据
+            Obj.Add("Machine2", Machine2); //机具管理数据
 
             Dictionary<string, object> Profit = new Dictionary<string, object>();
             Profit.Add("TradeProfit", MachineData.TradeProfit); //交易分润

+ 11 - 2
Areas/Api/Controllers/Main/MerchantQrCodeController.cs

@@ -99,15 +99,24 @@ namespace MySystem.Areas.Api.Controllers.v1
             Dictionary<string, object> Obj = new Dictionary<string, object>();
             Models.Main1.MerchantQrCode query = MerchantQrCodeService.Query(" SnNo='" + SnNo + "'");
             Models.Main1.PosMachinesTwo pos = PosMachinesTwoService.Query(" PosSn='" + SnNo + "'");
+            Models.Main1.PosMachines machines = PosMachinesService.Query(" PosSn='" + SnNo + "'");
             Models.Main.MerchantInfo merchant = MerchantInfoService.Query(MerchantId);
-            if (pos.Id == 0)
+            if (pos.Id == 0 && SnNo == MachineNo)
             {
                 return new AppResultJson() { Status = "-1", Info = "绑定失败" };
             }
-            if (pos.BuyUserId == 0)
+            if (machines.Id == 0 && SnNo != MachineNo)
+            {
+                return new AppResultJson() { Status = "-1", Info = "绑定失败" };
+            }
+            if (pos.BuyUserId == 0 && SnNo == MachineNo)
             {
                 return new AppResultJson() { Status = "-1", Info = "码牌未授权" };
             }
+            if (machines.BuyUserId == 0 && SnNo != MachineNo)
+            {
+                return new AppResultJson() { Status = "-1", Info = "音响未授权" };
+            }
             if (query.Id > 0)
             {
                 if (query.MerchantId > 0)

+ 147 - 2
Areas/Api/Controllers/Main/PosCouponOrdersController.cs

@@ -43,7 +43,7 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
             int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
             int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
             List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
-            IQueryable<PosCouponOrders> query = maindb.PosCouponOrders;
+            IQueryable<PosCouponOrders> query = maindb.PosCouponOrders.Where(m=> m.ChangeKind == 1);
             if(ChangeKind == 1)
             {
                 query = query.Where(m => m.ToUserId == UserId);
@@ -98,7 +98,7 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
             other = new Dictionary<string, object>();
             if(PageNum == 1)
             {
-                DataTable dt = CustomerSqlConn.dtable("select (select count(Id) from PosCouponOrders where FromUserId=" + UserId + "),(select count(Id) from PosCouponOrders where ToUserId=" + 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 + " and ChangeKind=1)", AppConfig.Base.SqlConnStr);
                 if(dt.Rows.Count > 0)
                 {
                     other.Add("FromTotalCount", dt.Rows[0][1].ToString());
@@ -170,6 +170,151 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
 
 
 
+        #region 创客-首页-客小爽产品-音响管理-划拨记录
+        // [Authorize]
+        public JsonResult List2(string value)
+        {
+            value = DesDecrypt(value);
+            JsonData data = JsonMapper.ToObject(value);
+            Dictionary<string, object> other = new Dictionary<string, object>();
+            List<Dictionary<string, object>> dataList = List2Do(value, out other);
+            return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = other });
+        }
+        public List<Dictionary<string, object>> List2Do(string value, out Dictionary<string, object> other)
+        {
+            JsonData data = JsonMapper.ToObject(value);
+            int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
+            int ChangeKind = int.Parse(function.CheckInt(data["ChangeKind"].ToString())); // 1-拨入,2-拨出
+            int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
+            int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
+            List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
+            IQueryable<PosCouponOrders> query = maindb.PosCouponOrders.Where(m=> m.ChangeKind == 2);
+            if(ChangeKind == 1)
+            {
+                query = query.Where(m => m.ToUserId == UserId);
+            }
+            else
+            {
+                query = query.Where(m => m.FromUserId == UserId);
+            }
+            query = query.OrderByDescending(m => m.Id);
+            if (PageNum == 1)
+            {
+                query = query.Take(PageSize);
+            }
+            else
+            {
+                int skipNum = PageSize * (PageNum - 1);
+                query = query.Skip(skipNum).Take(PageSize);
+            }
+            foreach (var subdata in query.ToList())
+            {
+                Dictionary<string, object> curData = new Dictionary<string, object>();
+                curData.Add("Id", subdata.Id);
+                string RealName = "";
+                string MakerCode = "";
+                if(ChangeKind == 1)
+                {
+                    Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.FromUserId) ?? new Models.KxsMainModels.Users();
+                    RealName = function.CheckNull(user.RealName);
+                    MakerCode = function.CheckNull(user.MakerCode);
+                    if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓";
+                }
+                else
+                {
+                    Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.ToUserId) ?? new Models.KxsMainModels.Users();
+                    RealName = function.CheckNull(user.RealName);
+                    MakerCode = function.CheckNull(user.MakerCode);
+                }
+                if (RealName.Length > 2 && RealName != "成都总仓")
+                {
+                    RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1);
+                }
+                else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓")
+                { 
+                    RealName = RealName.Substring(0, 1) + "*";
+                }
+                curData.Add("RealName", RealName); //真实姓名
+                curData.Add("MakerCode", MakerCode); //创客编号
+                curData.Add("ChangeCount", subdata.ChangeCount); //变更数量
+                curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
+                dataList.Add(curData);
+            }
+            other = new Dictionary<string, object>();
+            if(PageNum == 1)
+            {
+                DataTable dt = CustomerSqlConn.dtable("select (select count(Id) from PosCouponOrders where FromUserId=" + UserId + "),(select count(Id) from PosCouponOrders where ToUserId=" + UserId + " and ChangeKind=2)", AppConfig.Base.SqlConnStr);
+                if(dt.Rows.Count > 0)
+                {
+                    other.Add("FromTotalCount", dt.Rows[0][1].ToString());
+                    other.Add("ToTotalCount", dt.Rows[0][0].ToString());
+                }
+            }
+            return dataList;
+        }
+        #endregion
+
+
+
+        #region 创客-首页-客小爽产品-音响管理-划拨记录-详情
+        // [Authorize]
+        public JsonResult Detail2(string value)
+        {
+            value = DesDecrypt(value);
+            JsonData data = JsonMapper.ToObject(value);
+            Dictionary<string, object> Obj = Detail2Do(value);
+            return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
+        }
+        public Dictionary<string, object> Detail2Do(string value)
+        {
+            JsonData data = JsonMapper.ToObject(value);
+            Dictionary<string, object> Obj = new Dictionary<string, object>();
+            int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));
+            int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
+            PosCouponOrders query = maindb.PosCouponOrders.FirstOrDefault(m => m.Id == Id) ?? new PosCouponOrders();
+            string OrderNo = query.OrderNo;
+            Dictionary<string, object> UserInfo = new Dictionary<string, object>();
+            string RealName = "";
+            string MakerCode = "";
+            string Mobile = "";
+            if(query.ToUserId == UserId)
+            {
+                Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.FromUserId) ?? new Models.KxsMainModels.Users();
+                RealName = function.CheckNull(user.RealName);
+                MakerCode = function.CheckNull(user.MakerCode);
+                Mobile = function.CheckNull(user.Mobile);
+                if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓";
+            }
+            else
+            {
+                Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.ToUserId) ?? new Models.KxsMainModels.Users();
+                RealName = function.CheckNull(user.RealName);
+                MakerCode = function.CheckNull(user.MakerCode);
+                Mobile = function.CheckNull(user.Mobile);
+            }
+            if (RealName.Length > 2 && RealName != "成都总仓")
+            {
+                RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1);
+            }
+            else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓")
+            { 
+                RealName = RealName.Substring(0, 1) + "*";
+            }
+            Obj.Add("RealName", RealName); //真实姓名
+            Obj.Add("MakerCode", MakerCode); //创客编号
+            Obj.Add("Mobile", Mobile); //手机号
+            Obj.Add("ChangeCount", query.ChangeCount); //变更数量
+            Obj.Add("ChangeKind", query.ChangeKind); //变更类型
+            Obj.Add("CreateDate", query.CreateDate); //创建时间
+            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;
+        }
+        #endregion
+
+
+
         #region 检查签名是否合法,合法返回1,不合法返回提示信息
 
         /// <summary>

+ 84 - 2
Areas/Api/Controllers/Main/PosCouponRecordController.cs

@@ -67,7 +67,7 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
                     {
                         return new AppResultJson() { Status = "-1", Info = pos.PosSn + "已划拨,请勿重复划拨", Data = Obj };
                     }
-                    if(pos.BindingState == 1)
+                    if (pos.BindingState == 1)
                     {
                         return new AppResultJson() { Status = "-1", Info = pos.PosSn + "已绑定,无法划拨", Data = Obj };
                     }
@@ -78,6 +78,7 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
                         ToUserId = ToUserId,
                         FromUserId = UserId,
                         PosCouponId = SnIdNum,
+                        ChangeKind = 1,
                     }).Entity;
                     pos.BuyUserId = ToUserId;
                     pos.UserId = ToUserId;
@@ -91,8 +92,9 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
                     OrderNo = ChangeRecordNo,
                     ToUserId = ToUserId,
                     FromUserId = UserId,
+                    ChangeKind = 1,
                 }).Entity;
-                
+
                 PublicFunction.StatUserMachineData(UserId, 0, -SnCount);
                 PublicFunction.StatUserMachineData(ToUserId, 0, SnCount);
 
@@ -103,6 +105,86 @@ namespace MySystem.Areas.Api.Controllers.v1.pos
         #endregion
 
 
+        #region 创客-首页-客小爽产品-音响管理-划拨
+        // [Authorize]
+        public JsonResult Add2(string value)
+        {
+            value = DesDecrypt(value);
+            JsonData data = JsonMapper.ToObject(value);
+            AppResultJson result = Add2Do(value);
+            return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
+        }
+        public AppResultJson Add2Do(string value)
+        {
+            JsonData data = JsonMapper.ToObject(value);
+            int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //目标创客
+            int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
+            string SnIds = data["SnIds"].ToString(); //码牌列表返回的Id集合
+            Dictionary<string, object> Obj = new Dictionary<string, object>();
+            bool checkUser = kxsdb.Users.Any(m => m.Id == ToUserId);
+            if (!checkUser)
+            {
+                return new AppResultJson() { Status = "-1", Info = "请输入正确的创客编号", Data = Obj };
+            }
+            Models.KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Models.KxsMainModels.Users();
+            Models.KxsMainModels.Users touser = kxsdb.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Models.KxsMainModels.Users();
+            if (!ToUserIds.Contains(UserId))
+            {
+                if (!function.CheckNull(touser.ParentNav).Contains("," + UserId + ",") || function.CheckNull(user.ParentNav).Contains("," + ToUserId + ","))
+                {
+                    return new AppResultJson() { Status = "-1", Info = "划拨对象不在您的权限范围", Data = Obj };
+                }
+            }
+            if (!string.IsNullOrEmpty(SnIds))
+            {
+                string ChangeRecordNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
+                string[] SnIdList = SnIds.Split(',');
+                foreach (string SnId in SnIdList)
+                {
+                    int SnIdNum = int.Parse(SnId);
+                    PosMachines pos = maindb.PosMachines.FirstOrDefault(m => m.Id == SnIdNum) ?? new PosMachines();
+                    if (pos.BuyUserId != UserId)
+                    {
+                        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,
+                        OrderNo = ChangeRecordNo,
+                        ToUserId = ToUserId,
+                        FromUserId = UserId,
+                        PosCouponId = SnIdNum,
+                        ChangeKind = 2,
+                    }).Entity;
+                    pos.BuyUserId = ToUserId;
+                    pos.UserId = ToUserId;
+                }
+                maindb.SaveChanges();
+                int SnCount = SnIdList.Length;
+                PosCouponOrders tostat = maindb.PosCouponOrders.Add(new PosCouponOrders()
+                {
+                    CreateDate = DateTime.Now,
+                    ChangeCount = SnCount,
+                    OrderNo = ChangeRecordNo,
+                    ToUserId = ToUserId,
+                    FromUserId = UserId,
+                    ChangeKind = 2,
+                }).Entity;
+
+                PublicFunction.StatUserMachineData(UserId, 1, -SnCount);
+                PublicFunction.StatUserMachineData(ToUserId, 1, SnCount);
+
+                maindb.SaveChanges();
+            }
+            return new AppResultJson() { Status = "1", Info = "", Data = Obj };
+        }
+        #endregion
+
+
 
         #region 检查签名是否合法,合法返回1,不合法返回提示信息