예제 #1
0
        public object get()
        {
            SetCacheEnable(false);
            var ou_id = ComFunc.nvl(QueryStringD.ou_id);
            var up    = DB.NewDBUnitParameter();

            var s = from t in DB.LamdaTable("ecs_user_wallet", "a")
                    join t2 in DB.LamdaTable("ecs_users", "b").RightJoin() on t.user_id equals t2.user_id
                    select new
            {
                t2.user_id,
                t2.user_name,
                t2.customer_num,
                t2.company_name,
                t.memo,
                t.total_amount,
                t.freeze_amount,
                t.used_amount
            };

            var result = DB.LamdaQueryByPage(up, s, "user_name");

            if (result.QueryTable.RowLength > 0)
            {
                var ss = from t in DB.LamdaTable("ecs_user_wallet_line", "a")
                         where t.notnull(ou_id, t.ebs_ou_id == ou_id)
                         select t;
                var totalamount  = DecimalStd.IsNotDecimalThen(DB.Sum(up, ss, "total_amount"));
                var freezeamount = DecimalStd.IsNotDecimalThen(DB.Sum(up, ss, "freeze_amount"));
                var usedamount   = DecimalStd.IsNotDecimalThen(DB.Sum(up, ss, "used_amount"));
                var available    = totalamount - freezeamount - usedamount;
                return(new
                {
                    code = "success",

                    data = (from t in result.QueryData <FrameDLRObject>()
                            select new
                    {
                        t.user_id,
                        t.user_name,
                        t.customer_num,
                        t.company_name,
                        t.memo,
                        total_amount = totalamount,
                        freeze_amount = freezeamount,
                        used_amount = usedamount,
                        available_amount = available
                    }).ElementAt(0)
                });
            }
            else
            {
                return(new
                {
                    code = "failed",
                    msg = "no data"
                });
            }
        }
예제 #2
0
        object Search()
        {
            SetCacheEnable(false);
            var no         = ComFunc.nvl(QueryStringD.no);
            var userno     = ComFunc.nvl(QueryStringD.userno);
            var status     = ComFunc.nvl(QueryStringD.status);
            var start_time = DateTimeStd.IsDateTimeThen(QueryStringD.start_time, "yyyy-MM-dd HH:mm:ss");
            var end_time   = DateTimeStd.IsDateTimeThen(QueryStringD.end_time, "yyyy-MM-dd HH:mm:ss");
            var sortcolumn = ComFunc.nvl(QueryStringD.sortcolumn);
            var sort       = ComFunc.nvl(QueryStringD.sort);

            //当前页超过末页时,自动显示最后一页的资料
            DB.Is_Auto_To_Last_Page = true;
            var up = DB.NewDBUnitParameter();
            var s  = from t in DB.LamdaTable("ecs_forpay", "a")
                     join t2 in DB.LamdaTable("ecs_users", "b") on t.user_id equals t2.user_id
                     where t.notnull(no, t.forpay_no.contains(no)) &&
                     t2.notnull(userno, (t2.user_name.contains(userno) || t2.company_name.contains(userno) || t2.customer_num.contains(userno))) &&
                     t.notnull(status, t.status == status) &&
                     t.notnull(start_time, t.add_time >= start_time) &&
                     t.notnull(end_time, t.add_time <= end_time)
                     select new
            {
                t.uid,
                t.forpay_no,
                t2.company_name,
                t.foruse,
                t.charge_amount,
                t.charge_type,
                t.bank_name,
                t.bank_no,
                t.trans_seq_no,
                t.add_time,
                t.status,
                t.uploadfile_name
            };
            var sortstr = "forpay_no desc";
            var sortrtn = "";
            var dicsort = new Dictionary <string, string>();

            dicsort.Add("seq_no", "forpay_no");
            dicsort.Add("company_name", "company_name");
            dicsort.Add("add_time", "add_time");
            dicsort.Add("foruse", "foruse");
            dicsort.Add("charge_type", "charge_type");
            dicsort.Add("charge_amount", "charge_amount");
            dicsort.Add("bank_name", "bank_name");
            dicsort.Add("bank_no", "bank_no");
            dicsort.Add("trans_seq_no", "trans_seq_no");
            dicsort.Add("status", "status");
            if (sortcolumn != "" && dicsort.ContainsKey(sortcolumn))
            {
                sortstr = dicsort[sortcolumn] + (sort == "" ? "" : " " + sort);
                sortrtn = sortcolumn + "#" + (sort == "" ? "asc" : sort);
            }
            var result = DB.LamdaQueryByPage(up, s, sortstr);
            var dic    = new Dictionary <string, string>();

            dic.Add("Create", "待审核");
            dic.Add("Review", "已审核");
            dic.Add("Success", "充值成功");
            dic.Add("Failed", "充值失败");
            return(new
            {
                code = "success",
                totalrow = result.TotalRow,
                totalpage = result.TotalPage,
                currentpage = result.CurrentPage,
                pagesize = result.Count_Of_OnePage,
                data = from t in result.QueryData <FrameDLRObject>()
                       select new
                {
                    t.uid,
                    seq_no = t.forpay_no,
                    charge_amount = "¥" + DecimalStd.IsNotDecimalThen(t.charge_amount).ToString("###,###.##"),
                    t.charge_type,
                    t.bank_name,
                    t.bank_no,
                    t.trans_seq_no,
                    t.company_name,
                    t.foruse,
                    add_time = DateTimeStd.IsDateTimeThen(t.add_time, "yyyy-MM-dd HH:mm:ss"),
                    status = dic.ContainsKey(t.status) ? dic[t.status] : "",
                    filename = t.uploadfile_name
                },
                sort = sortrtn
            });
        }
예제 #3
0
        object Use(string id)
        {
            lock (lockobj)
            {
                double amount    = PostDataD.amount;
                var    memo      = ComFunc.nvl(PostDataD.memo);
                var    ou_id     = ComFunc.nvl(PostDataD.ou_id);
                var    ebs_wd_no = ComFunc.nvl(PostDataD.ebs_wd_no);
                var    up        = DB.NewDBUnitParameter();
                BeginTrans();

                var s = from t in DB.LamdaTable("ecs_user_wallet", "a")
                        where t.user_id == id
                        select t;
                var result = DB.ExcuteLamda(up, s);
                if (result.QueryTable.RowLength <= 0)
                {
                    return(new { code = "failed", msg = "账号无效" });
                }

                dynamic item = result.QueryData <FrameDLRObject>()[0];
                if (amount > DoubleStd.IsNotDoubleThen(item.freeze_amount))
                {
                    return(new { code = "failed", msg = "金额溢出" });
                }
                //核销行资料
                var tmpamount = amount;
                //找出可用的行资料
                var availablelist = DB.ExcuteLamda(up, from t in DB.LamdaTable("ecs_user_wallet_line", "a")
                                                   orderby t.line_no ascending
                                                   where t.user_id == id && t.freeze_amount.isnull(0) > 0 && t.notnull(ou_id, t.ebs_ou_id == ou_id) && t.notnull(ebs_wd_no, t.ebs_wd_no.within($",{ebs_wd_no},"))
                                                   select t).QueryData <FrameDLRObject>();
                if (availablelist.Count <= 0)
                {
                    return(new { code = "failed", msg = "无可用额度" });
                }
                var total_freeze_amount = DoubleStd.IsNotDoubleThen(item.freeze_amount);
                var total_used_amount   = DoubleStd.IsNotDoubleThen(item.used_amount);
                var tmplist             = new List <object>();
                foreach (dynamic obj in availablelist)
                {
                    var freeze = DoubleStd.IsNotDoubleThen(obj.freeze_amount);
                    if (tmpamount > freeze)
                    {
                        obj.freeze_amount        = 0;
                        obj.used_amount          = DoubleStd.IsNotDoubleThen(obj.used_amount) + freeze;
                        obj.current_use_amount   = freeze;
                        obj.available_amount     = DoubleStd.IsNotDoubleThen(obj.total_amount) - DoubleStd.IsNotDoubleThen(obj.freeze_amount) - DoubleStd.IsNotDoubleThen(obj.used_amount);
                        obj.all_total_amount     = item.total_amount;
                        obj.all_freeze_amount    = total_freeze_amount = total_freeze_amount - freeze;
                        obj.all_used_amount      = total_used_amount = total_used_amount + freeze;
                        obj.all_available_amount = DoubleStd.IsNotDoubleThen(obj.all_total_amount) - DoubleStd.IsNotDoubleThen(obj.all_freeze_amount) - DoubleStd.IsNotDoubleThen(obj.all_used_amount);
                        tmplist.Add(obj);
                        tmpamount = tmpamount - freeze;
                    }
                    else
                    {
                        obj.freeze_amount        = DoubleStd.IsNotDoubleThen(obj.freeze_amount) - tmpamount;
                        obj.used_amount          = DoubleStd.IsNotDoubleThen(obj.used_amount) + tmpamount;
                        obj.current_use_amount   = tmpamount;
                        obj.available_amount     = DoubleStd.IsNotDoubleThen(obj.total_amount) - DoubleStd.IsNotDoubleThen(obj.freeze_amount) - DoubleStd.IsNotDoubleThen(obj.used_amount);
                        obj.all_total_amount     = item.total_amount;
                        obj.all_freeze_amount    = total_freeze_amount = total_freeze_amount - tmpamount;
                        obj.all_used_amount      = total_used_amount = total_used_amount + tmpamount;
                        obj.all_available_amount = DoubleStd.IsNotDoubleThen(obj.all_total_amount) - DoubleStd.IsNotDoubleThen(obj.all_freeze_amount) - DoubleStd.IsNotDoubleThen(obj.all_used_amount);
                        tmplist.Add(obj);
                        tmpamount = 0;
                        break;
                    }
                }
                if (tmpamount > 0)
                {
                    return(new { code = "failed", msg = "无可用额度" });
                }
                foreach (dynamic obj in tmplist)
                {
                    DB.QuickUpdate(up, "ecs_user_wallet_line", new
                    {
                        freeze_amount = obj.freeze_amount,
                        used_amount   = obj.used_amount,
                        memo          = memo,
                        last_time     = DateTime.Now,
                        last_id       = "WalletAPI"
                    }, new
                    {
                        user_id   = obj.user_id,
                        ebs_wd_no = obj.ebs_wd_no
                    });
                }

                DB.QuickUpdate(up, "ecs_user_wallet", new
                {
                    freeze_amount = DoubleStd.IsNotDoubleThen(item.freeze_amount) - amount,
                    used_amount   = DoubleStd.IsNotDoubleThen(item.used_amount) + amount
                }, new
                {
                    user_id = id
                });

                dynamic data = DB.ExcuteLamda(up, from t in DB.LamdaTable("ecs_user_wallet", "a")
                                              where t.user_id == id
                                              select t).QueryData <FrameDLRObject>()[0];
                var newseq = GetNewSeq(ComFunc.nvl(DB.Max(up, from t in DB.LamdaTable("ecs_user_wallet_log", "a")
                                                          where t.user_id == id
                                                          select t, "seq")));
                //记录流水
                foreach (dynamic obj in tmplist)
                {
                    DB.QuickInsert(up, "ecs_user_wallet_log", new
                    {
                        user_id               = id,
                        uid                   = Guid.NewGuid().ToString(),
                        amount                = obj.current_use_amount,
                        events                = "核销",
                        memo                  = memo,
                        ebs_wd_no             = obj.ebs_wd_no,
                        ebs_ou_id             = obj.ebs_ou_id,
                        last_time             = DateTime.Now,
                        last_id               = "WalletAPI",
                        seq                   = newseq,
                        line_total_amount     = obj.total_amount,
                        line_freeze_amount    = DecimalStd.IsNotDecimalThen(obj.freeze_amount),
                        line_used_amount      = DecimalStd.IsNotDecimalThen(obj.used_amount),
                        line_available_amount = obj.available_amount,
                        total_amount          = obj.all_total_amount,
                        freeze_amount         = DecimalStd.IsNotDecimalThen(obj.all_freeze_amount),
                        used_amount           = DecimalStd.IsNotDecimalThen(obj.all_used_amount),
                        available_amount      = DecimalStd.IsNotDecimalThen(obj.all_total_amount) - DecimalStd.IsNotDecimalThen(obj.all_freeze_amount) - DecimalStd.IsNotDecimalThen(obj.all_used_amount)
                    });
                    newseq = GetNewSeq(newseq);
                }

                CommitTrans();
                return(new
                {
                    code = "success",
                    wallet = new
                    {
                        user_id = data.user_id,
                        current_freeze_amount = amount,
                        total_amount = data.total_amount,
                        freeze_amount = DecimalStd.IsNotDecimalThen(data.freeze_amount),
                        used_amount = DecimalStd.IsNotDecimalThen(data.used_amount),
                        available_amount = data.total_amount - DecimalStd.IsNotDecimalThen(data.freeze_amount) - DecimalStd.IsNotDecimalThen(data.used_amount),
                        lines = from t in tmplist
                                select new
                        {
                            line_no = ((dynamic)t).line_no,
                            ebs_wd_no = ((dynamic)t).ebs_wd_no,
                            ebs_ou_id = ((dynamic)t).ebs_ou_id,
                            current_use_amount = ((dynamic)t).current_use_amount,
                            total_amount = ((dynamic)t).total_amount,
                            freeze_amount = ((dynamic)t).freeze_amount,
                            used_amount = ((dynamic)t).used_amount,
                            available_amount = DoubleStd.IsNotDoubleThen(((dynamic)t).total_amount) - DoubleStd.IsNotDoubleThen(((dynamic)t).freeze_amount) - DoubleStd.IsNotDoubleThen(((dynamic)t).used_amount)
                        }
                    }
                });
            }
        }
예제 #4
0
        object Charge(string id)
        {
            if (ComFunc.nvl(id) == "")
            {
                return new { code = "failed", msg = "账号无效" }
            }
            ;

            double amount = PostDataD.amount;
            var    memo   = ComFunc.nvl(PostDataD.memo);
            var    wd_no  = ComFunc.nvl(PostDataD.wd_no);
            var    ou_id  = ComFunc.nvl(PostDataD.ou_id);
            var    up     = DB.NewDBUnitParameter();

            BeginTrans();

            dynamic useritem = null;
            var     s        = from t in DB.LamdaTable("ecs_users", "a")
                               where t.user_id == id && t.is_validated == 1
                               select t;
            var userresult = DB.ExcuteLamda(up, s);

            if (userresult.QueryTable.RowLength <= 0)
            {
                return(new { code = "failed", msg = "账号无效" });
            }
            else
            {
                useritem = userresult.QueryData <FrameDLRObject>()[0];
            }

            var result = DB.ExcuteLamda(up, from t in DB.LamdaTable("ecs_user_wallet", "a")
                                        where t.user_id == id
                                        select t);

            if (amount <= 0)
            {
                return(new { code = "failed", msg = "金额不合法" });
            }
            if (DB.IsExists(up, from t in DB.LamdaTable("ecs_user_wallet_line", "a")
                            where t.ebs_wd_no == wd_no
                            select t))
            {
                return(new { code = "failed", msg = "WD编号重复" });
            }



            if (result.QueryTable.RowLength <= 0)
            {
                DB.QuickInsert(up, "ecs_user_wallet", new
                {
                    user_id      = id,
                    user_name    = useritem.user_name,
                    total_amount = amount,
                    memo         = memo,
                    add_time     = DateTime.Now,
                    add_id       = "WalletAPI",
                    last_time    = DateTime.Now,
                    last_id      = "WalletAPI"
                });
            }
            else
            {
                dynamic item = result.QueryData <FrameDLRObject>()[0];
                DB.QuickUpdate(up, "ecs_user_wallet", new
                {
                    total_amount = DoubleStd.IsNotDoubleThen(item.total_amount) + amount
                }, new
                {
                    user_id = id
                });
            }
            //写入line
            var newlineno = IntStd.IsNotIntThen(DB.Max(up, from t in DB.LamdaTable("ecs_user_wallet_line", "a")
                                                       where t.user_id == id
                                                       select t, "line_no")) + 1;

            DB.QuickInsert(up, "ecs_user_wallet_line", new
            {
                user_id      = id,
                line_no      = newlineno,
                ebs_wd_no    = wd_no,
                ebs_ou_id    = ou_id,
                total_amount = amount,
                memo         = memo,
                add_time     = DateTime.Now,
                add_id       = "WalletAPI",
                last_time    = DateTime.Now,
                last_id      = "WalletAPI"
            });

            dynamic data = DB.ExcuteLamda(up, from t in DB.LamdaTable("ecs_user_wallet", "a")
                                          where t.user_id == id
                                          select t).QueryData <FrameDLRObject>()[0];

            var newseq = GetNewSeq(ComFunc.nvl(DB.Max(up, from t in DB.LamdaTable("ecs_user_wallet_log", "a")
                                                      where t.user_id == id
                                                      select t, "seq")));

            //记录流水

            DB.QuickInsert(up, "ecs_user_wallet_log", new
            {
                user_id               = id,
                uid                   = Guid.NewGuid().ToString(),
                amount                = amount,
                events                = "打款",
                memo                  = memo,
                ebs_wd_no             = wd_no,
                ebs_ou_id             = ou_id,
                last_time             = DateTime.Now,
                last_id               = "WalletAPI",
                seq                   = newseq,
                line_total_amount     = amount,
                line_freeze_amount    = 0,
                line_used_amount      = 0,
                line_available_amount = amount,
                total_amount          = data.total_amount,
                freeze_amount         = DecimalStd.IsNotDecimalThen(data.freeze_amount),
                used_amount           = DecimalStd.IsNotDecimalThen(data.used_amount),
                available_amount      = DecimalStd.IsNotDecimalThen(data.total_amount) - DecimalStd.IsNotDecimalThen(data.freeze_amount) - DecimalStd.IsNotDecimalThen(data.used_amount)
            });

            CommitTrans();
            return(new
            {
                code = "success",
                wallet = new
                {
                    user_id = data.user_id,
                    total_amount = data.total_amount,
                    freeze_amount = DecimalStd.IsNotDecimalThen(data.freeze_amount),
                    used_amount = DecimalStd.IsNotDecimalThen(data.used_amount),
                    available_amount = DecimalStd.IsNotDecimalThen(data.total_amount) - DecimalStd.IsNotDecimalThen(data.freeze_amount) - DecimalStd.IsNotDecimalThen(data.used_amount)
                }
            });
        }
예제 #5
0
        object PreCancel(string id)
        {
            lock (lockobj)
            {
                double amount    = PostDataD.amount;
                var    memo      = ComFunc.nvl(PostDataD.memo);
                var    ou_id     = ComFunc.nvl(PostDataD.ou_id);
                var    ebs_wd_no = ComFunc.nvl(PostDataD.ebs_wd_no);
                var    up        = DB.NewDBUnitParameter();
                BeginTrans();

                var s = from t in DB.LamdaTable("ecs_user_wallet", "a")
                        where t.user_id == id
                        select t;
                var result = DB.ExcuteLamda(up, s);
                if (result.QueryTable.RowLength <= 0)
                {
                    return(new { code = "failed", msg = "账号无效" });
                }
                dynamic item = result.QueryData <FrameDLRObject>()[0];
                if (amount > DoubleStd.IsNotDoubleThen(item.freeze_amount))
                {
                    return(new { code = "failed", msg = "金额溢出" });
                }
                //找到行资料-倒叙搜索
                var tmpamount     = amount;
                var availablelist = DB.ExcuteLamda(up, from t in DB.LamdaTable("ecs_user_wallet_line", "a")
                                                   orderby t.line_no descending
                                                   where t.user_id == id && t.freeze_amount.isnull(0) > 0 && t.notnull(ou_id, t.ebs_ou_id == ou_id) && t.notnull(ebs_wd_no, t.ebs_wd_no.within($",{ebs_wd_no},"))
                                                   select t).QueryData <FrameDLRObject>();
                if (availablelist.Count <= 0)
                {
                    return(new { code = "failed", msg = "无可用额度" });
                }
                var total_freeze_amount = DoubleStd.IsNotDoubleThen(item.freeze_amount);
                var total_used_amount   = DoubleStd.IsNotDoubleThen(item.used_amount);
                var tmplist             = new List <object>();
                foreach (dynamic obj in availablelist)
                {
                    var freeze = DoubleStd.IsNotDoubleThen(obj.freeze_amount);
                    if (tmpamount > freeze)
                    {
                        obj.freeze_amount         = 0;
                        obj.current_cancel_amount = freeze;
                        obj.available_amount      = DoubleStd.IsNotDoubleThen(obj.total_amount) - DoubleStd.IsNotDoubleThen(obj.freeze_amount) - DoubleStd.IsNotDoubleThen(obj.used_amount);
                        obj.all_total_amount      = item.total_amount;
                        obj.all_freeze_amount     = total_freeze_amount = total_freeze_amount - freeze;
                        obj.all_used_amount       = total_used_amount;
                        obj.all_available_amount  = DoubleStd.IsNotDoubleThen(obj.all_total_amount) - DoubleStd.IsNotDoubleThen(obj.all_freeze_amount) - DoubleStd.IsNotDoubleThen(obj.all_used_amount);
                        tmplist.Add(obj);
                        tmpamount = tmpamount - freeze;
                    }
                    else
                    {
                        obj.freeze_amount         = DoubleStd.IsNotDoubleThen(obj.freeze_amount) - tmpamount;
                        obj.current_cancel_amount = tmpamount;
                        obj.available_amount      = DoubleStd.IsNotDoubleThen(obj.total_amount) - DoubleStd.IsNotDoubleThen(obj.freeze_amount) - DoubleStd.IsNotDoubleThen(obj.used_amount);
                        obj.all_total_amount      = item.total_amount;
                        obj.all_freeze_amount     = total_freeze_amount = total_freeze_amount - tmpamount;
                        obj.all_used_amount       = total_used_amount;
                        obj.all_available_amount  = DoubleStd.IsNotDoubleThen(obj.all_total_amount) - DoubleStd.IsNotDoubleThen(obj.all_freeze_amount) - DoubleStd.IsNotDoubleThen(obj.all_used_amount);
                        tmplist.Add(obj);
                        tmpamount = 0;
                        break;
                    }
                }
                if (tmpamount > 0)
                {
                    return(new { code = "failed", msg = "无可用额度" });
                }

                CommitTrans();

                return(new
                {
                    code = "success",
                    wallet = new
                    {
                        user_id = item.user_id,
                        current_cancel_amount = amount,
                        total_amount = item.total_amount,
                        freeze_amount = DecimalStd.IsNotDecimalThen(item.freeze_amount) - DecimalStd.IsNotDecimalThen(amount),
                        used_amount = DecimalStd.IsNotDecimalThen(item.used_amount),
                        available_amount = item.total_amount - DecimalStd.IsNotDecimalThen(item.freeze_amount) - DecimalStd.IsNotDecimalThen(item.used_amount) + DecimalStd.IsNotDecimalThen(amount),
                        lines = from t in tmplist
                                select new
                        {
                            line_no = ((dynamic)t).line_no,
                            ebs_wd_no = ((dynamic)t).ebs_wd_no,
                            ebs_ou_id = ((dynamic)t).ebs_ou_id,
                            current_cancel_amount = ((dynamic)t).current_cancel_amount,
                            total_amount = ((dynamic)t).total_amount,
                            freeze_amount = ((dynamic)t).freeze_amount,
                            used_amount = ((dynamic)t).used_amount,
                            available_amount = DoubleStd.IsNotDoubleThen(((dynamic)t).total_amount) - DoubleStd.IsNotDoubleThen(((dynamic)t).freeze_amount) - DoubleStd.IsNotDoubleThen(((dynamic)t).used_amount)
                        }
                    }
                });
            }
        }