DuGuYang 3 лет назад
Родитель
Сommit
39eb17c28d

+ 259 - 1
Areas/Admin/Controllers/MainServer/SysToolsController.cs

@@ -1700,7 +1700,6 @@ namespace MySystem.Areas.Admin.Controllers
                     newpos.BindMerchantId = oldpos.BindMerchantId;
 
                     newpos.StoreId = oldpos.StoreId;
-                    newpos.UserId = oldpos.UserId;
                     newpos.PreUserId = oldpos.PreUserId;
 
                     if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
@@ -2024,6 +2023,265 @@ namespace MySystem.Areas.Admin.Controllers
         #endregion
 
 
+        #region 创客跨品牌换机
+
+        public IActionResult ChangePosCrossBrand(string right)
+        {
+            ViewBag.RightInfo = RightInfo;
+            ViewBag.right = right;
+
+            return View();
+        }
+
+        [HttpPost]
+        public string ChangePosCrossBrandDo(string MakerCode, string OldSn, string BackStoreNo, string NewSn, string FromStoreNo, int IsSend = 0)
+        {
+            string[] OldSnList;
+            string[] NewSnList;
+            decimal amount = 0;
+            List<string> opData = new List<string>();
+            if (string.IsNullOrEmpty(MakerCode))
+            {
+                return "请输入创客编号";
+            }
+            if (string.IsNullOrEmpty(OldSn))
+            {
+                return "请输入旧机SN";
+            }
+            if (string.IsNullOrEmpty(BackStoreNo))
+            {
+                return "请输入旧机退回仓库编号";
+            }
+            if (string.IsNullOrEmpty(NewSn))
+            {
+                return "请输入新机SN";
+            }
+            if (string.IsNullOrEmpty(FromStoreNo))
+            {
+                return "请输入新机发货仓库编号";
+            }
+            OldSnList = OldSn.Split('\n');
+            NewSnList = NewSn.Split('\n');
+            if (OldSnList.Length != NewSnList.Length)
+            {
+                return "原机具SN数量和新机具SN数量不一致";
+            }
+
+            for (int i = 0; i < OldSnList.Length; i++)
+            {
+                string OldSnNum = OldSnList[i];
+                string NewSnNum = NewSnList[i];
+                UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
+                StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
+                if (storeForCodeFrom.StoreId == 0)
+                {
+                    return "您输入的新机发货仓库编号不存在";
+                }
+                StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
+                if (storeForCodeBack.StoreId == 0)
+                {
+                    return "您输入的旧机退回仓库编号不存在";
+                }
+                MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
+                MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
+                PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.ActivationState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
+                if (oldpos.Id == 0)
+                {
+                    return "您输入的旧机SN不存在或者不在" + MakerCode + "名下";
+                }
+                PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.ActivationState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
+                if (newpos.Id == 0)
+                {
+                    return "您输入的新机SN不存在或不满足条件";
+                }
+                StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
+                if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
+                {
+                    return "您输入的新机发货仓库不符新机机具对应品牌";
+                }
+                if (newpos.StoreId != storeFrom.Id)
+                {
+                    return "您输入的新机SN不在新机发货仓库";
+                }
+                StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
+                if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
+                {
+                    return "您输入的旧机退回仓库不符旧机机具对应品牌";
+                }
+                if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(storeFrom.BrandId))
+                {
+                    return "您输入的新机发货仓库和坏机退回仓库品牌类型不同";
+                }
+                var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
+                if (brandInfo.Name.Contains("大POS"))
+                {
+                    amount = 300;
+                }
+                if (brandInfo.Name.Contains("电签"))
+                {
+                    amount = 200;
+                }
+                var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
+                var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
+                storeFromUserAcount.ValidAmount += amount;
+                storeBackUserAcount.ValidAmount -= amount;
+
+                if (oldpos.OpId > 0)
+                {
+                    if (newpos.OpId > 0)
+                    {
+                        var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
+                        decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
+                        opUserAccount.ValidAmount += oldpos.OpReserve3;
+                        opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
+                        opUserAccount.TotalAmt += oldpos.OpReserve1;
+
+                        var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
+                        {
+                            CreateDate = DateTime.Now,
+                            UserId = oldpos.OpId,
+                            SeoDescription = "创客跨品牌换机",
+                            OperateType = 1,
+                            UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
+                            BeforeAmount = TotalAmount,
+                            AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
+                        }).Entity;
+                    }
+                    if (newpos.OpId == 0)
+                    {
+                        newpos.OpReserve1 = oldpos.OpReserve1;
+                        newpos.OpReserve2 = oldpos.OpReserve3;
+                        newpos.OpReserve3 = oldpos.OpReserve1;
+                        newpos.OpId = oldpos.OpId;
+                    }
+                }
+
+                newpos.BuyUserId = oldpos.BuyUserId;
+                newpos.UserId = oldpos.UserId;
+                newpos.RecycEndDate = oldpos.RecycEndDate;
+                newpos.ScanQrTrade = oldpos.ScanQrTrade;
+                newpos.DebitCardTrade = oldpos.DebitCardTrade;
+                newpos.CreditTrade = oldpos.CreditTrade;
+                newpos.PosSnType = oldpos.PosSnType;
+                newpos.TransferTime = oldpos.TransferTime;
+                newpos.IsPurchase = oldpos.IsPurchase;
+                newpos.BindingState = oldpos.BindingState;
+                newpos.ActivationState = oldpos.ActivationState;
+                newpos.BindingTime = oldpos.BindingTime;
+                newpos.ActivationTime = oldpos.ActivationTime;
+                newpos.IsFirst = oldpos.IsFirst;
+                newpos.SeoKeyword = oldpos.SeoKeyword;
+                newpos.PrizeParams = oldpos.PrizeParams;
+                newpos.LeaderUserId = oldpos.LeaderUserId;
+                newpos.BindMerchantId = oldpos.BindMerchantId;
+
+                newpos.StoreId = oldpos.StoreId;
+                newpos.PreUserId = oldpos.PreUserId;
+
+                if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
+                {
+                    opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
+                }
+
+                oldpos.StoreId = storeBack.Id;
+                oldpos.QueryCount = 0;
+                oldpos.UpdateDate = null;
+                oldpos.ActivityList = null;
+                oldpos.SeoKeyword = null;
+                oldpos.SeoDescription = null;
+                oldpos.OrderId = 0;
+                oldpos.RecycEndDate = null;
+                oldpos.RecycBackCount = 0;
+                oldpos.PrizeParams = null;
+                oldpos.ScanQrTrade = 0;
+                oldpos.BindMerchantId = 0;
+                oldpos.CreditTrade = 0;
+                oldpos.DebitCardTrade = 0;
+                oldpos.IsVip = 0;
+                oldpos.UserNav = null;
+                oldpos.TransferTime = null;
+                oldpos.IsPurchase = 0;
+                oldpos.Detail = null;
+                oldpos.BindingTime = null;
+                oldpos.BindingState = 0;
+                oldpos.ActivationTime = null;
+                oldpos.ActivationState = 0;
+                oldpos.LeaderUserId = 0;
+                oldpos.PreUserId = 0;
+                oldpos.IsFirst = 0;
+                oldpos.DownFeeMan = null;
+                oldpos.DownFeeFlag = 0;
+                oldpos.DownFeeDate = null;
+                oldpos.UpFeeMan = null;
+                oldpos.UpFeeFlag = 0;
+                oldpos.UpFeeDate = null;
+                oldpos.OpReserve1 = 0;
+                oldpos.OpReserve2 = 0;
+                oldpos.OpReserve3 = 0;
+                oldpos.OpId = 0;
+                oldpos.RecycStartDate = null;
+                oldpos.SourcePosSn = null;
+                oldpos.BuyUserId = 0;
+                oldpos.UserId = 0;
+                PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
+                db.SaveChanges();
+                opdb.SaveChanges();
+
+                PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == newpos.BindMerchantId);
+                if (merchant != null)
+                {
+                    merchant.KqSnNo = newpos.PosSn;
+                    merchant.ActiveStatus = newpos.ActivationState;
+                }
+                db.SaveChanges();
+
+                BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
+                {
+                    CreateDate = DateTime.Now,
+                    CreateMan = SysUserName + "-" + SysRealName,
+                    ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
+                    OutStoreId = storeFrom.Id,
+                    BackStoreId = storeBack.Id,
+                    OutProductType = newpos.BrandId,
+                    BackProductType = oldpos.BrandId,
+                    UserId = userForMakerCode.UserId, //创客
+                }).Entity;
+                db.SaveChanges();
+                BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
+                {
+                    CreateDate = DateTime.Now,
+                    CreateMan = SysUserName + "-" + SysRealName,
+                    OutSnNo = OldSnNum,
+                    BackSnNo = NewSnNum,
+                    ChangeNo = add.ChangeNo, //转换单号
+                    ChangeId = add.Id, //转换记录Id
+                    UserId = add.UserId, //创客
+                }).Entity;
+                db.SaveChanges();
+                var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
+                if (IsSend == 1)
+                {
+                    RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
+                    {
+                        UserId = userForMakerCode.UserId, //接收创客
+                        MsgType = 2,
+                        Title = "创客跨品牌换机", //标题
+                        Summary = "您的旧机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
+                        CreateDate = DateTime.Now,
+
+                    }));
+                }
+            }
+            foreach (string sub in opData)
+            {
+                string[] datalist = sub.Split(":");
+                PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
+            }
+            return "success";
+        }
+        #endregion
+
+
 
         #region 机具解绑
 

+ 287 - 0
Areas/Admin/Views/MainServer/SysTools/ChangePosCrossBrand.cshtml

@@ -0,0 +1,287 @@
+@{
+    string RightInfo = ViewBag.RightInfo as string;
+    string right = ViewBag.right as string;
+
+}
+<!DOCTYPE html>
+<html>
+
+<head>
+    <meta charset="utf-8">
+    <title>创客跨品牌换机</title>
+    <meta name="renderer" content="webkit">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="viewport"
+        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
+    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
+    <script src="/admin/js/jquery-1.10.1.min.js"></script>
+    <script src="/admin/js/LAreaData2.js"></script>
+</head>
+
+<body>
+
+    <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin">
+        <form class="layui-form" id="confirmFrm">
+            <div class="layui-card">
+                <div class="layui-card-body">
+                    <div class="layui-tab" lay-filter="mytabbar">
+                        <ul class="layui-tab-title">
+                            <li class="layui-this" lay-id="1">基本信息</li>
+                        </ul>
+                        <div class="layui-tab-content mt20">
+                            <div class="layui-tab-item layui-show">
+                                <div class="layui-form-item" id="MakerCodeSelect">
+                                    <label class="layui-form-label">创客编号</label>
+                                    <div class="layui-input-inline">
+                                        <input class="layui-input" type="text" id="MakerCode" name="MakerCode"
+                                            maxlength="50" lay-verify="required|" autocomplete="off"
+                                            placeholder="请输入创客编号">
+                                    </div>
+                                </div>
+                                <div class="layui-form-item">
+                                    <label class="layui-form-label">旧机SN</label>
+                                    <div class="layui-input-block">
+                                        <textarea class="layui-textarea" lay-verify="required|" name="OldSn" id="OldSn"
+                                            placeholder="请输入旧机SN"></textarea>
+                                    </div>
+                                </div>
+                                <div class="layui-form-item" id="StoreCodeSelect" style="display: none;">
+                                    <label class="layui-form-label">旧机退回仓库编号</label>
+                                    <div class="layui-input-inline">
+                                        <input class="layui-input" type="text" id="BackStoreNo" name="BackStoreNo"
+                                            maxlength="50" lay-verify="required|" autocomplete="off"
+                                            placeholder="请输入旧机退回仓库编号">
+                                    </div>
+                                </div>
+                                <div class="layui-form-item">
+                                    <label class="layui-form-label">新机SN</label>
+                                    <div class="layui-input-block">
+                                        <textarea class="layui-textarea" lay-verify="required|" name="NewSn" id="NewSn"
+                                            placeholder="请输入新机SN"></textarea>
+                                    </div>
+                                </div>
+                                <div class="layui-form-item">
+                                    <label class="layui-form-label">新机发货仓库编号</label>
+                                    <div class="layui-input-inline">
+                                        <input class="layui-input" type="text" id="FromStoreNo" name="FromStoreNo"
+                                            maxlength="50" lay-verify="required|" autocomplete="off"
+                                            placeholder="请输入新机发货仓库编号">
+                                    </div>
+                                </div>
+                                <div class="layui-form-item">
+                                    <label class="layui-form-label">是否推送消息</label>
+                                    <div class="layui-input-block">
+                                        <input type="checkbox" id="IsSend" name="IsSend" value="1" lay-skin="switch"
+                                            lay-filter="switchTest" title="开关">
+                                    </div>
+                                </div>
+                            </div>
+
+                        </div>
+                    </div>
+                    <div class="layui-form-item ml10">
+                        <div class="layui-input-block">
+                            <button type="button" class="layui-btn" onclick="save()">提交</button>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </form>
+    </div>
+
+    <script src="/layuiadmin/layui/layui.js"></script>
+    <script
+        src="/other/oss/upload-min@(MySystem.OssHelper.Instance.OssStatus ? "-oss" : "").js?r=@DateTime.Now.ToString("yyyyMMddHHmmss")"></script>
+    <script src="/other/mybjq/kindeditor-min.js"></script>
+    <script src="/other/mybjq/lang/zh_CN.js"></script>
+    <script>
+        function save() {
+            var index = layer.load(1, {
+                shade: [0.5, '#000']
+            });
+            var userdata = $("#confirmFrm").serialize();
+            $.ajax({
+                type: "POST",
+                url: "/Admin/SysTools/ChangePosCrossBrandDo?r=" + Math.random(1),
+                data: userdata,
+                dataType: "text",
+                success: function (data) {
+                    layer.close(index); //关闭弹层
+                    if (data == "success") {
+                        layer.msg("更换成功");
+                        window.location.reload();
+                    } else {
+                        layer.msg(data);
+                    }
+                }
+            });
+        }
+
+
+        //编辑器
+        KindEditor.ready(function (K) {
+
+        });
+
+        var ids = "";
+        function getChildren(obj) {
+            $.each(obj, function (index, value) {
+                var id = obj[index].id;
+                ids += id + ",";
+                var children = obj[index].children;
+                if (children) {
+                    getChildren(children);
+                }
+            });
+        }
+
+        function AreasProvinceInit(tagId, areasVal, form) {
+            for (var i = 0; i < provs_data.length; i++) {
+                var sel = "";
+                if (areasVal.indexOf(provs_data[i].text) > -1) {
+                    sel = " selected=selected";
+                }
+                $("#" + tagId + "Province").append('<option value="' + provs_data[i].value + '"' + sel + '>' + provs_data[i].text + '</option>');
+            }
+            form.render();
+        }
+
+        function AreasProvinceSelected(tagId, areasVal, form, value) {
+            $("#" + tagId + "City").html('<option value="">市</option>');
+            var list = citys_data[value];
+            for (var i = 0; i < list.length; i++) {
+                var sel = "";
+                if (areasVal.indexOf(list[i].text) > -1) {
+                    sel = " selected=selected";
+                }
+                $("#" + tagId + "City").append('<option value="' + list[i].value + '"' + sel + '>' + list[i].text + '</option>');
+            }
+            $("#" + tagId + "Area").html('<option value="">县/区</option>');
+            form.render();
+            $("#" + tagId + "").val($("#" + tagId + "Province option:selected").text() + "," + $("#" + tagId + "City option:selected").text() + "," + $("#" + tagId + "Area option:selected").text());
+        }
+
+        function AreasCitySelected(tagId, areasVal, form, value) {
+            $("#" + tagId + "Area").html('<option value="">县/区</option>');
+            var list = dists_data[value];
+            for (var i = 0; i < list.length; i++) {
+                var sel = "";
+                if (areasVal.indexOf(list[i].text) > -1) {
+                    sel = " selected=selected";
+                }
+                $("#" + tagId + "Area").append('<option value="' + list[i].value + '"' + sel + '>' + list[i].text + '</option>');
+            }
+            form.render();
+            $("#" + tagId + "").val($("#" + tagId + "Province option:selected").text() + "," + $("#" + tagId + "City option:selected").text() + "," + $("#" + tagId + "Area option:selected").text());
+        }
+
+        function AreasAreaSelected(tagId, form) {
+            form.render();
+            $("#" + tagId + "").val($("#" + tagId + "Province option:selected").text() + "," + $("#" + tagId + "City option:selected").text() + "," + $("#" + tagId + "Area option:selected").text());
+        }
+        function movePrev(obj, tagId) {
+            $(obj).parent().prev().insertAfter($(obj).parent());
+            checkPics(tagId);
+        }
+        function moveNext(obj, tagId) {
+            $(obj).parent().next().insertBefore($(obj).parent());
+            checkPics(tagId);
+        }
+        function deletePic(obj, tagId) {
+            $(obj).parent().remove();
+            checkPics(tagId);
+        }
+        function checkPics(tagId) {
+            var pics = "";
+            var texts = "";
+            $("#" + tagId + "Image div img").each(function (i) {
+                pics += $(this).attr("src").replace(osshost, '') + "|";
+            });
+            $("#" + tagId + "Image div input").each(function (i) {
+                texts += $(this).val() + "|";
+            });
+            if (pics == "") {
+                $("#" + tagId).val("");
+            } else {
+                pics = pics.substring(0, pics.length - 1);
+                texts = texts.substring(0, pics.length - 1);
+                $("#" + tagId).val(pics + "#cut#" + texts);
+            }
+        }
+        function checkBox(tagId) {
+            var text = "";
+            $("input[type=checkbox][name=" + tagId + "List]:checked").each(function (i) {
+                text += $(this).val() + ",";
+            });
+            $("#" + tagId).val(text);
+        }
+        function showBigPic(picpath) {
+            parent.layer.open({
+                type: 1,
+                title: false,
+                closeBtn: 0,
+                shadeClose: true,
+                area: ['auto', 'auto'],
+                content: '<img src="' + picpath + '" style="max-width:800px; max-height:800px;" />'
+            });
+        }
+
+
+        var tree;
+        var element;
+        var upload;
+        layui.config({
+            base: '/layuiadmin/' //静态资源所在路径
+        }).extend({
+            index: 'lib/index' //主入口模块
+        }).use(['index', 'form', 'upload', 'layedit', 'laydate', 'element', 'croppers', 'transfer', 'tree', 'util'], function () {
+            var $ = layui.$
+                , form = layui.form
+                , layer = layui.layer
+                , layedit = layui.layedit
+                , laydate = layui.laydate
+                , croppers = layui.croppers
+                , transfer = layui.transfer
+                , util = layui.util;
+            tree = layui.tree;
+            element = layui.element;
+            upload = layui.upload;
+
+            //Hash地址的定位
+            var layid = location.hash.replace(/^#test=/, '');
+            element.tabChange('test', layid);
+            element.on('tab(test)', function (elem) {
+                location.hash = 'test=' + $(this).attr('lay-id');
+            });
+
+            form.on('select(ChangeType)', function (data) {
+                if(data.value == '0') {
+                    $('#MakerCodeSelect').show();
+                    $('#StoreCodeSelect').hide();
+                } else if(data.value == '1') {
+                    $('#MakerCodeSelect').hide();
+                    $('#StoreCodeSelect').show();
+                }
+                form.render();
+            });
+
+            //日期
+
+
+            //上传文件
+
+
+            //穿梭框
+
+
+            //TreeView,比如权限管理
+
+
+            //省市区
+
+        })
+
+    </script>
+</body>
+
+</html>