http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 12411|回复: 1

[小程序系列教程] 【小程序】【在线缴费系统】(五)管理端功能-缴费单位管理-数据库+逻辑处理

[复制链接]
发表于 2021-7-1 16:30:36 | 显示全部楼层 |阅读模式
【小程序】【在线缴费系统】(五)管理端功能-缴费单位管理-数据库+逻辑处理




导读部分


教程目录http://www.sufeinet.com/thread-40967-1-1.html



教程部分


数据库设计: danwei-数据库.jpg

Model层:

[C#] 纯文本查看 复制代码
 public class jiaofei_danwei
    {
        /// <summary>
        /// id
        /// </summary>	
        [OrmLiteField(IsPrimaryKey = true, InsertIgnore = true)]
        public int id { get; set; }
        /// <summary>
        /// 父id
        /// </summary>		
        public int parentid { get; set; }
        /// <summary>
        /// 排序值
        /// </summary>		
        public int sort { get; set; }
        /// <summary>
        /// 单位名称
        /// </summary>		
        public string name { get; set; }
        /// <summary>
        /// 是否已删除(0否, 1是)
        /// </summary>
        public int is_del { get; set; }
        /// <summary>
        /// 父ids
        /// </summary>
        public string pids { get; set; }
        /// <summary>
        /// 单位登记
        /// </summary>
        public int levelnum { get; set; }
        /// <summary>
        /// 是否为叶子单位  (0否, 1是)
        /// </summary>
        public int isyezi { get; set; }
        /// <summary>
        /// 缴费时间
        /// </summary>
        public DateTime btime { get; set; }
        /// <summary>
        /// 缴费时间
        /// </summary>
        public DateTime etime { get; set; }
        /// <summary>
        /// 缴费时间规则
        /// (0任何时间,1时间段, 2每天固定时间段)
        /// </summary>
        public int ruletype { get; set; }
        /// <summary>
        /// 每天固定时间段开始时间
        /// </summary>
        public int daybtime { get; set; }
        /// <summary>
        /// 每天固定时间段结束时间
        /// </summary>
        public int dayetime { get; set; }
        /// <summary>
        /// 添加时间
        /// </summary>
        [OrmLiteField(Ignore = true)]
        public DateTime addtime { get; set; }
        /// <summary>
        /// 添加时间
        /// </summary>
        [OrmLiteField(Ignore = true)]
        public string addtimestr { get { return addtime.ToString("yyyy-MM-dd HH:mm"); } }
        /// <summary>
        /// 
        /// </summary>
        [OrmLiteField(Ignore = true)]
        public List<jiaofei_danwei> child { get; set; }
        /// <summary>
        /// 父名称
        /// </summary>
        [OrmLiteField(Ignore =true)]
        public string p_name { get; set; }

        [OrmLiteField(Ignore = true)]
        public string btimestr { get { if (isyezi == 1) { return btime.ToString("yyyy-MM-dd HH:mm"); } return ""; } }
        [OrmLiteField(Ignore = true)]
        public string etimestr { get { if (isyezi == 1) { return etime.ToString("yyyy-MM-dd HH:mm"); } return ""; } }
        /// <summary>
        /// 缴费时间
        /// </summary>
        [OrmLiteField(Ignore =true)]
        public string timerulestr {
            get {
                if (isyezi == 1) {
                    if (ruletype == 0) { return "随时可缴费"; }
                    else if (ruletype == 1) { return $"{btimestr} 至 {etimestr}"; }
                    else if (ruletype == 2) { return $"每天{daybtime}时 至 {dayetime}时"; }
                }
                return "";
            }
        }



BLL逻辑结构层:
[C#] 纯文本查看 复制代码
 public class jiaofei_danweiBLL : BaseDAL<jiaofei_danwei>
    {
        /// <summary>
        /// 数据库链接字符串
        /// </summary>
        protected override string ConnName
        {
            get { return DALConfig.Zaixianjiaofei; }
        }

        public bool istojiaofei(jiaofei_danwei danwei, DateTime dt)
        {
            // 0任何时间
            if (danwei.ruletype == 0) { return true; }
            // 1时间段
            else if (danwei.ruletype == 1) { if ((dt - danwei.btime).TotalMinutes > 0 && (danwei.etime - dt).TotalMinutes > 0) { return true; } return false; }
            // 2每天固定时间段
            else if (danwei.ruletype == 2) {
                DateTime btime = Convert.ToDateTime($"{dt.Date.ToString("yyyy-MM-dd")} {danwei.daybtime}:00");
                DateTime etime = DateTime.Now;
                if (danwei.dayetime == 24) { etime = Convert.ToDateTime($"{dt.Date.ToString("yyyy-MM-dd")} 23:59"); }
                else { etime= Convert.ToDateTime($"{dt.Date.ToString("yyyy-MM-dd")} {danwei.dayetime}:00"); ; }

                if ((dt - btime).TotalMinutes > 0 && (etime - dt).TotalMinutes > 0) { return true; }
                return false;
            }
            return false;
        }
        /// <summary>
        /// 获取单位信息
        /// </summary>
        /// <param name="ids_list"></param>
        /// <returns></returns>
        public List<jiaofei_danwei> GetList(List<string> ids_list) {
            string danwei_ids = string.Join(",", ids_list.Select(l => l.TrimStart(',').TrimEnd(',')));
            List<jiaofei_danwei> danwei_list = FindList($"SELECT id,name FROM dbo.jiaofei_danwei WHERE id IN({danwei_ids})") ?? new List<jiaofei_danwei>();

            return danwei_list;
        }
        /// <summary>
        /// 获取当前单位ids的单位名称
        /// </summary>
        /// <param name="danwei_list"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public List<string> GetDanwei(List<jiaofei_danwei> danwei_list, string ids)
        {
            List<string> item_danwei_list = new List<string>();
            if (!string.IsNullOrEmpty(ids)) {
                foreach (var danwei_id in ids.TrimStart(',').TrimEnd(',').Split(','))
                {
                    jiaofei_danwei danwei = danwei_list.Find(d => d.id == InputHelper.GetInputInt(danwei_id));
                    if (danwei != null && danwei.id > 0) { item_danwei_list.Add(danwei.name); }
                }
            }

            return item_danwei_list;
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int Save(jiaofei_danwei info) {
            // 获取当前单位是否存在子集
            if (info.id > 0)
            {
                jiaofei_danwei c_info = FindListOne($"parentid={info.id} and is_del=0");
                if (c_info != null && c_info.id > 0) { info.isyezi = 0; } else { info.isyezi = 1; }
            }
            else { info.isyezi = 1; }
            
            int result = 0;
            if (info.id > 0) { result = Update(info);  }
            else { result = (int)insert(info);  }

            if (result > 0 && info.isyezi == 1) {
                // 修改当前叶子节点的所有父节点都为非叶子节点
                ExecuteNonQuery(System.Data.CommandType.Text, $"UPDATE dbo.jiaofei_danwei SET isyezi=0 WHERE id={info.parentid}", null);
            }

            return result;
        }
        /// <summary>
        /// 获取所有的单位
        /// </summary>
        /// <returns></returns>
        public List<jiaofei_danwei> GetAll() {
            List<jiaofei_danwei> ret_list = new List<jiaofei_danwei>();
            // 获取当前所有
            List<jiaofei_danwei> all_list = FindList($"is_del=0 ORDER BY sort DESC");
            if (all_list != null && all_list.Any()) {
                // 获取最大层级
                int max_level = all_list.OrderByDescending(o => o.levelnum).FirstOrDefault().levelnum;

                // 获取所有顶级分类
                IEnumerable<jiaofei_danwei> p_list = all_list.Where(a => a.parentid == 0);
                if (p_list != null && p_list.Any()) {
                    // 循环顶级,添加子类信息
                    foreach (var item in p_list)
                    {
                        // 循环处理子集信息
                        LoopToAppendChildren(all_list, item);

                        ret_list.Add(item);
                    }
                }
            }

            return ret_list;
        }
        /// <summary>
        /// 获取所有单位
        /// </summary>
        /// <returns></returns>
        public List<dynamic> GetSelectAll() {
            List<dynamic> ret_list = new List<dynamic>();
            // 获取当前所有
            List<jiaofei_danwei> all_list = FindList($"is_del=0 ORDER BY sort DESC");
            if (all_list != null && all_list.Any())
            {
                // 获取最大层级
                int max_level = all_list.OrderByDescending(o => o.levelnum).FirstOrDefault().levelnum;

                // 获取所有顶级分类
                IEnumerable<jiaofei_danwei> p_list = all_list.Where(a => a.parentid == 0);
                if (p_list != null && p_list.Any())
                {
                    // 循环顶级,添加子类信息
                    foreach (var item in p_list)
                    {
                        dynamic dy = new ExpandoObject();
                        dy.value = item.id;
                        dy.label = item.name;

                        // 循环处理子集信息
                        LoopToAppendSelectChildren(all_list, item, dy);

                        ret_list.Add(dy);
                    }
                }
            }

            return ret_list;
        }

        private void LoopToAppendSelectChildren(List<jiaofei_danwei> all, jiaofei_danwei curItem, dynamic ret_dy)
        {
            List<dynamic> sub_dy_items = new List<dynamic>();
            var subItems = all.Where(ee => ee.parentid == curItem.id);

            if (subItems != null && subItems.Any())
            {
                foreach (var subItem in subItems)
                {
                    dynamic sub_dy = new ExpandoObject();
                    sub_dy.value = subItem.id;
                    sub_dy.label = subItem.name;

                    LoopToAppendSelectChildren(all, subItem, sub_dy);//新闻1.1

                    sub_dy_items.Add(sub_dy);
                }
            }
            else { subItems = new List<jiaofei_danwei>(); }

            curItem.child = subItems.ToList();
            if (sub_dy_items != null && sub_dy_items.Any()) { ret_dy.children = sub_dy_items; }
        }

        private void LoopToAppendChildren(List<jiaofei_danwei> all, jiaofei_danwei curItem)
        {
            var subItems = all.Where(ee => ee.parentid == curItem.id);

            if (subItems != null && subItems.Any())
            {
                foreach (var subItem in subItems)
                {
                    LoopToAppendChildren(all, subItem);//新闻1.1
                }
            }

            curItem.child = subItems.ToList();
        }
    }



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-22 06:41

© 2014-2021

快速回复 返回顶部 返回列表