ss 1 year ago
commit
394472f036
100 changed files with 22179 additions and 0 deletions
  1. 1 0
      .env.example
  2. 6 0
      .gitignore
  3. 42 0
      .travis.yml
  4. 927 0
      CHANGELOG.md
  5. 32 0
      LICENSE.txt
  6. 10 0
      README.md
  7. 62 0
      application/admin/common.php
  8. 7 0
      application/admin/config/app.php
  9. 378 0
      application/admin/controller/Address.php
  10. 141 0
      application/admin/controller/AppIcon.php
  11. 91 0
      application/admin/controller/AppIos.php
  12. 91 0
      application/admin/controller/AppMgr.php
  13. 160 0
      application/admin/controller/Article.php
  14. 111 0
      application/admin/controller/ArticleCate.php
  15. 529 0
      application/admin/controller/ArticlePaper.php
  16. 212 0
      application/admin/controller/ArticleWorker.php
  17. 121 0
      application/admin/controller/AttendanceAddr.php
  18. 153 0
      application/admin/controller/AttendanceClass.php
  19. 172 0
      application/admin/controller/AttendanceGroup.php
  20. 152 0
      application/admin/controller/AttendanceLeave.php
  21. 166 0
      application/admin/controller/AttendanceMachine.php
  22. 59 0
      application/admin/controller/AttendanceMachineCmd.php
  23. 772 0
      application/admin/controller/AttendanceRecord.php
  24. 51 0
      application/admin/controller/Auth.php
  25. 91 0
      application/admin/controller/Balance.php
  26. 127 0
      application/admin/controller/Banner.php
  27. 18 0
      application/admin/controller/Base.php
  28. 173 0
      application/admin/controller/Bracelet.php
  29. 191 0
      application/admin/controller/Burst.php
  30. 166 0
      application/admin/controller/Bursting.php
  31. 62 0
      application/admin/controller/Bushu.php
  32. 318 0
      application/admin/controller/Car.php
  33. 135 0
      application/admin/controller/Cate.php
  34. 121 0
      application/admin/controller/CleanForm.php
  35. 324 0
      application/admin/controller/CleanPlan.php
  36. 364 0
      application/admin/controller/CleanPlanRecord.php
  37. 221 0
      application/admin/controller/CleanTask.php
  38. 188 0
      application/admin/controller/CleanType.php
  39. 375 0
      application/admin/controller/CockpitStatistics.php
  40. 52 0
      application/admin/controller/Comment.php
  41. 158 0
      application/admin/controller/Common.php
  42. 93 0
      application/admin/controller/CompanyDispatch.php
  43. 359 0
      application/admin/controller/CompanyGoods.php
  44. 65 0
      application/admin/controller/CompanyGoodsLog.php
  45. 640 0
      application/admin/controller/Complain.php
  46. 213 0
      application/admin/controller/Config.php
  47. 153 0
      application/admin/controller/ConveyCate.php
  48. 135 0
      application/admin/controller/ConveyDevice.php
  49. 160 0
      application/admin/controller/ConveyPlan.php
  50. 148 0
      application/admin/controller/ConveyPlanAddr.php
  51. 225 0
      application/admin/controller/ConveyPlanRecord.php
  52. 223 0
      application/admin/controller/ConveyStatistics.php
  53. 311 0
      application/admin/controller/Daily.php
  54. 110 0
      application/admin/controller/DailyForm.php
  55. 214 0
      application/admin/controller/DailyRecord.php
  56. 126 0
      application/admin/controller/DailyStatistics.php
  57. 276 0
      application/admin/controller/DailyTask.php
  58. 145 0
      application/admin/controller/DelayReason.php
  59. 151 0
      application/admin/controller/Dep.php
  60. 142 0
      application/admin/controller/DepCate.php
  61. 236 0
      application/admin/controller/Device.php
  62. 114 0
      application/admin/controller/DeviceCate.php
  63. 151 0
      application/admin/controller/DeviceForm.php
  64. 213 0
      application/admin/controller/DeviceRecord.php
  65. 96 0
      application/admin/controller/DeviceStatistics.php
  66. 385 0
      application/admin/controller/DeviceTask.php
  67. 291 0
      application/admin/controller/Dinner.php
  68. 315 0
      application/admin/controller/DinnerAddress.php
  69. 111 0
      application/admin/controller/DinnerApply.php
  70. 32 0
      application/admin/controller/DinnerConfig.php
  71. 656 0
      application/admin/controller/DinnerGroup.php
  72. 1908 0
      application/admin/controller/DinnerOrder.php
  73. 249 0
      application/admin/controller/DinnerRefuseOrder.php
  74. 120 0
      application/admin/controller/DinnerType.php
  75. 108 0
      application/admin/controller/DinnerUser.php
  76. 126 0
      application/admin/controller/DinnerWechat.php
  77. 125 0
      application/admin/controller/Feedback.php
  78. 43 0
      application/admin/controller/File.php
  79. 111 0
      application/admin/controller/GGoods.php
  80. 106 0
      application/admin/controller/GGoodsCate.php
  81. 59 0
      application/admin/controller/GOrderRefund.php
  82. 94 0
      application/admin/controller/GOrders.php
  83. 184 0
      application/admin/controller/Group.php
  84. 62 0
      application/admin/controller/Gui.php
  85. 564 0
      application/admin/controller/Hiddendanger.php
  86. 664 0
      application/admin/controller/House.php
  87. 111 0
      application/admin/controller/HouseAreas.php
  88. 114 0
      application/admin/controller/HouseCType.php
  89. 109 0
      application/admin/controller/HouseFee.php
  90. 220 0
      application/admin/controller/HouseLock.php
  91. 59 0
      application/admin/controller/HouseOwnerLog.php
  92. 1111 0
      application/admin/controller/HousePay.php
  93. 164 0
      application/admin/controller/ImportLog.php
  94. 1195 0
      application/admin/controller/Index.php
  95. 63 0
      application/admin/controller/Jiu.php
  96. 165 0
      application/admin/controller/Location.php
  97. 93 0
      application/admin/controller/MateApply.php
  98. 82 0
      application/admin/controller/MateCate.php
  99. 151 0
      application/admin/controller/MateCheck.php
  100. 0 0
      application/admin/controller/MateGoodsLog.php

+ 1 - 0
.env.example

@@ -0,0 +1 @@
+[APP]
APP_DEBUG = true
[DATABASE]
HOSTNAME = 127.0.0.1
DATABASE = hhqtest_jya_tech
USERNAME = hhqtest_jya_tech
PASSWORD = mGFXzjkAPazk8b7c
HOSTPORT = 3306
CHARSET = utf8mb4









+ 6 - 0
.gitignore

@@ -0,0 +1,6 @@
+/.idea
+/.vscode
+*.log
+.env
+.DS_Store
+/.env

File diff suppressed because it is too large
+ 42 - 0
.travis.yml


+ 927 - 0
CHANGELOG.md

@@ -0,0 +1,927 @@
+## V5.1.39 LTS(2019-11-18)
+
+本次更新为常规更新,主要包括:
+
+* 修正`memcached`驱动
+* 改进`HasManyThrough`关联查询
+* 改进`Request`类`isJson`方法
+* 改进关联查询
+* 改进`redis`驱动
+* 增加 Model类`getWhere`方法对复合主键的支持
+* 改进`newQuery`方法
+* 改进闭包查询的参数绑定
+* 修正`Validate`
+* 修复某些情况下URL会多一个冒号
+* 调整composer.json
+* 修复使用`Cache::clear()`时,报错缓存文件不存在问题
+* 使用File类的unlink方法进行文件删除
+* 改进`paraseData`方法
+* 修正image验证方法
+* 改进Url生成
+* 改进空操作对数字的支持
+* 改进一处PHP7.4兼容性问题
+
+## V5.1.38 LTS(2019-8-8)
+
+本次更新为常规更新,主要包括:
+
+* `Request`类增加`isJson`方法
+* 改进浮点型查询
+* 修正关联查询关联外键为空的查询错误
+* 远程一对多支持关联统计和预载入查询
+* 远程一对多关联支持`has`/`hasWhere`查询
+* 优化`parseIn`解析
+* 改进`parseLike`查询
+* 改进Url生成
+* 改进模型的`toArray`方法
+* 修正`notIn`查询
+* 改进`JSON`字段查询
+* 改进Controller类`display`/`fetch`方法返回`ViewResponse`对象
+* 改进`param`方法
+* 改进`mysql`驱动`getExplain`方法
+* 改进时间查询
+* 改进模型关联的`has`/`hasWhere`方法对软删除的支持
+* 修正社区反馈的BUG
+
+## V5.1.37 LTS(2019-5-26)
+
+本次更新为常规更新,主要更新如下:
+
+* 改进关联数据更新
+* 修正关联动态获取器
+* 改进`redis`驱动 
+* 修复验证规则里面出现二维数组时的错误
+* 改进跨域请求支持
+* 完善模型`hidden`方法对关联属性的支持
+* 改进`where`查询方法传入`Query`对象的支持`bind`数据
+* 改进数据集对象的`load`方法
+* 修正缓存类`clear`方法对`tag`的支持
+
+## V5.1.36 LTS(2019-4-28)
+
+本次更新为常规更新,主要更新如下:
+
+* 修正`chunk`方法一处异常抛出的错误
+* 修正模型输出的`visible`
+* 改进环境变量加载
+* 改进命令行日志的`level`配置支持
+* 修复设置有缓存前缀时,无法清空缓存标签的问题
+* HasMony对象`saveAll`方法兼容`Collection`格式参数格式
+* 修正`whereOr`查询使用字符串的问题
+* 改进`dateFormat`设置对写入数据的影响
+* 修正查询缓存
+* 记住指定的跳转地址
+* 改进软删除
+* 改进聚合查询SQL去除limit 1
+* 改进缓存驱动
+
+## V5.1.35 LTS(2019-3-2)
+
+本次主要为常规更新,修正了一些反馈的问题。
+
+* 修正验证类自定义验证方法执行两次的问题
+* 模型增加`isEmpty`方法用于判断是否空模型
+* 改进获取器对`append`的支持
+* 修正一对多关联的`withCount`自关联问题
+* facade类注释调整
+* 改进关联属性的`visible`和`hidden`判断
+* 修正路由分组的`MISS`路由
+* 改进pgsql.sql
+
+## V5.1.34 LTS(2019-1-30)
+
+本次更新为常规更新,修正了一些反馈的问题。
+
+* 改进Request类的`has`方法,支持`patch`
+* 改进`unique`验证的多条件支持
+* 修复自定义上传验证,检测文件大小
+* 改进`in`查询支持表达式
+* 改进路由的`getBind`方法
+* 改进验证类的错误信息获取
+* 改进`response`助手函数默认值
+* 修正mysql的`regexp`查询
+* 改进模型类型强制转换写入对`Expression`对象的支持
+
+## V5.1.33 LTS(2019-1-16)
+
+* 修复路由中存在多个相同替换的正则BUG
+* 修正whereLike查询
+* join方法支持参数绑定
+* 改进union方法
+* 修正多对多关联的attach方法
+* 改进验证类的正则规则自定义
+* 改进Request类method方法
+* 改进File日志类型的CLI日志写入
+* 改进文件日志time_format配置对JSON格式的支持
+
+## V5.1.32 LTS(2018-12-24)
+
+本次主要为常规更新,修正了一些反馈的问题。
+
+
+* 改进多对多关联的`attach`方法 
+* 改进聚合查询的`field`处理
+* 改进关联的`save`方法
+* 修正模型`exists`方法返回值
+* 改进时间字段写入和输出
+* 改进控制器中间件的调用
+* 改进路由变量替换的性能
+* 改进缓存标签的处理机制
+
+## V5.1.31 LTS (2018-12-9)
+
+本次版本包含一个安全更新,建议升级。
+
+* 改进`field`方法
+* 改进`count`方法返回类型
+* `download`函数增加在浏览器中显示文件功能
+* 修正多对多模型的中间表数据写入
+* 改进`sqlsrv`驱动支持多个Schemas模式查询
+* 统一助手函数与\think\response\Download函数文件过期时间
+* 完善关联模型的`save`方法 增加`make`方法仅创建对象不保存
+* 修改条件表达式对静态变量的支持
+* 修正控制器名获取
+* 改进view方法的`field`解析
+
+## V5.1.30 LTS(2018-11-30)
+
+该版本为常规更新,修正了一些社区反馈的问题。
+
+主要更新如下:
+
+* 改进查询类的`execute`方法
+* 判断路由规则定义添加对请求类型的判断
+* 修复`orderRaw`异常
+* 修正 `optimize:autoload`指令
+* 改进软删除的`destroy`方法造成重复执行事件的问题
+* 改进验证类对扩展验证规则 始终验证 不管是否`require`
+* 修复自定义验证`remove`所有规则的异常
+* 改进时间字段的自动写入支持微秒数据
+* 改进`Connection`类的`getrealsql`方法
+* 修正`https`地址的URL生成
+* 修复 `array_walk_recursive` 在低于PHP7.1消耗内部指针问题
+* 改进手动参数绑定使用
+* 改进聚合查询方法的`field`参数支持`Expression`
+
+## V5.1.29 LTS(2018-11-11)
+
+该版本主要改进了参数绑定的解析问题和提升性能,并修正了一些反馈的问题。
+
+* 改进手动参数绑定
+* 修正MISS路由的分组参数无效问题
+* 行为支持对象的方法
+* 修正全局查询范围
+* 改进`belongsto`关联的`has`方法
+* 改进`hasMany`关联
+* 改进模型观察者多次注册的问题
+* 改进`query`类的默认查询参数处理
+* 修正`parseBetween`解析方法
+* 改进路由地址生成的本地域名支持
+* 改进参数绑定的实际URL解析性能
+* 改进`Env`类的`getEnv`和`get`方法
+* 改进模板缓存的生成优化
+* 修复验证类的多语言支持
+* 修复自定义场景验证`remove`规则异常
+* File类添加是否自动补全扩展名的选项
+* 改进`strpos`对子串是否存在的判断
+* 修复`choice`无法用值选择第一个选项问题
+* 验证器支持多维数组取值验证
+* 改进解析`extend`和`block`标签的正则
+
+## V5.1.28 LTS(2018-10-29)
+
+该版本主要修正了上一个版本存在的一些问题,并改进了关联查询
+
+* 改进聚合查询方法的字段支持DISTINCT
+* 改进定义路由后url函数的端口生成
+* 改进控制器中间件对`swoole`等的支持
+* 改进Log类`save`方法
+* 改进验证类的闭包验证参数
+* 多对多关联支持指定中间表数据的名称
+* 关联聚合查询支持闭包方式指定聚合字段
+* 改进Lang类`get`方法
+* 多对多关联增加判断关联数据是否存在的方法
+* 改进关联查询使用`fetchsql`的情况
+* 改进修改器的是否已经执行判断
+* 增加`afterWith`和`beforeWith`验证规则 用于比较日期字段
+
+## V5.1.27 LTS(2018-10-22)
+
+该版本主要修正了路由绑定的参数,改进了修改器的执行多次问题,并正式宣布为LTS版本!
+
+
+* 修正路由绑定的参数丢失问题
+* 修正路由别名的参数获取
+* 改进修改器会执行多次的问题
+
+## V5.1.26(2018-10-12)
+
+该版本主要修正了上一个版本的一些问题,并改进了全局查询范围的支持,同时包含了一个安全更新。
+
+
+* 修正单一模块下注解路由无效的问题
+* 改进数据库的聚合查询的字段处理
+* 模型类增加`globalScope`属性定义 用于指定全局的查询范围
+* 模型的`useGlobalScope`方法支持传入数组 用于指定当前查询需要使用的全局查询范围
+* 改进数据集的`order`方法对数字类型的支持
+* 修正上一个版本`order`方法解析的一处BUG
+* 排序字段不合法或者错误的时候抛出异常
+* 改进`Request`类的`file`方法对上传文件的错误判断
+
+##  V5.1.25(2018-9-21)
+
+该版本主要改进了查询参数绑定的性能和对浮点型的支持,以及一些细节的完善。
+
+* 修正一处命令行问题
+* 改进`Socketlog`日志驱动,支持自定义默认展开日志类别
+* 修正`MorphMany`一处bug
+* 跳转到上次记住的url,并支持默认值
+* 改进模型的异常提示
+* 改进参数绑定对浮点型的支持
+* 改进`order`方法解析
+* 改进`json`字段数据的自动编码
+* 改进日志`log_write`可能造成的日志写入死循环
+* Log类增加`log_level`行为标签位置,用于对某个类型的日志进行处理
+* Route类增加`clear`方法清空路由规则
+* 分布式数据库配置支持使用数组
+* 单日志文件也支持`max_files`参数
+* 改进查询参数绑定的性能
+* 改进别名路由的URL后缀参数检测
+* 控制器前置方法和控制器中间件的`only`和`except`定义不区分大小写
+
+## V5.1.24(2018-9-5)
+
+该版本主要增加了命令行的表格输出功能,并增加了查看路由定义的指令,以及修正了社区的一些反馈问题。
+
+* 修正`Request`类的`file`方法
+* 修正路由的`cache`方法
+* 修正路由缓存的一处问题
+* 改进上传文件获取的异常处理
+* 改进`fetchCollection`方法支持传入数据集类名
+* 修正多级控制器的注解路由生成
+* 改进`Middleware`类`clear`方法
+* 增加`route:list`指令用于[查看定义的路由](752690) 并支持排序
+* 命令行增加`Table`输出类
+* `Command`类增加`table`方法用于输出表格
+* 改进搜索器查询方法支持别名定义
+* 命令行配置增加`auto_path`参数用于定义自动载入的命令类路径
+* 增加`make:command`指令用于[快速生成指令](354146)
+* 改进`make:controller`指令对操作方法后缀的支持
+* 改进命令行的定义文件支持索引数组 用于指令对象的惰性加载
+* 改进`value`和`column`方法对后续查询结果的影响
+* 改进`RuleName`类的`setRule`方法
+
+## V5.1.23(2018-8-23)
+
+该版本主要改进了数据集对象的处理,增加了`findOrEmpty`方法,并且修正了一些社区反馈的BUG。
+
+* 数据集类增加`diff`/`intersect`方法用于获取差集和交集(默认根据主键值比较)
+* 数据集类增加`order`方法支持指定字段排序
+* 数据集类增加`map`方法使用回调函数处理数据并返回新的数据集对象
+* Db增加`allowEmpty`方法允许`find`方法在没有数据的时候返回空数组或者空模型对象而不是null
+* Db增加`findOrEmpty`方法
+* Db增加`fetchCollection`方法用于指定查询返回数据集对象
+* 改进`order`方法的数组方式解析,增强安全性
+* 改进`withSearch`方法,支持第三个参数传入字段前缀标识,用于多表查询字段搜索
+* 修正`optimize:route`指令开启类库后缀后的注解路由生成
+* 修正redis缓存及session驱动
+* 支持指定`Yaconf`的独立配置文件
+* 增加`yaconf`助手函数用于配置文件
+
+
+## V5.1.22(2018-8-9)
+
+该版本主要增加了模型搜索器和`withJoin`方法,完善了模型输出和对`Yaconf`的支持,修正了一些社区反馈的BUG。
+
+* 改进一对一关联的`table`识别问题
+* 改进内置`Facade`类
+* 增加`withJoin`方法支持`join`方式的[一对一关联](一对一关联.md)查询
+* 改进`join`预载入查询的空数据问题
+* 改进`Config`类的`load`方法支持快速加载配置文件
+* 改进`execute`方法和事务的断线重连
+* 改进`memcache`驱动的`has`方法
+* 模型类支持定义[搜索器](搜索器.md)方法
+* 完善`Config`类对`Yaconf`的支持
+* 改进模型的`hidden/visible/append/withAttr`方法,支持在[查询前后调用](数组访问.md),以及支持数据集对象
+* 数据集对象增加`where`方法根据字段或者关联数据[过滤数据](模型数据集.md)
+* 改进AJAX请求的`204`判断
+
+
+## V5.1.21(2018-8-2)
+
+该版本主要增加了下载响应对象和数组查询对象的支持,并修正了一些社区反馈的问题。
+
+* 改进核心对象的无用信息调试输出
+* 改进模型的`isRelationAttr`方法判断
+* 模型类的`get`和`all`方法并入Db类
+* 增加[下载响应对象](文件下载.md)和`download`助手函数
+* 修正别名路由配置定义读取
+* 改进`resultToModel`方法
+* 修正开启类库后缀后的注解路由生成
+* `Response`类增加`noCache`快捷方法
+* 改进路由对象在`Swoole`/`Workerman`下面参数多次合并问题
+* 修正路由`ajax`/`pjax`参数后路由变量无法正确获取的问题
+* 增加清除中间件的方法
+* 改进依赖注入的参数规范自动识别(便于对接前端小写+下划线规范)
+* 改进`hasWhere`的数组条件的字段判断
+* 增加[数组查询对象](高级查询.md)`Where`支持(喜欢数组查询的福音)
+* 改进多对多关联的闭包支持
+
+## V5.1.20(2018-7-25)
+
+该版本主要增加了Db和模型的动态获取器的支持,并修正了一些已知问题。
+
+* Db类添加[获取器支持](703981)
+* 支持模型及关联模型字段[动态定义获取器](354046)
+* 动态获取器支持`JSON`字段
+* 改进路由的`before`行为执行(匹配后执行)
+*  `Config`类支持`Yaconf`
+* 改进Url生成的端口问题
+* Request类增加`setUrl`和`setBaseUrl`方法
+* 改进页面trace的信息显示
+* 修正`MorphOne`关联
+* 命令行添加[查看版本指令](703994)
+
+## V5.1.19 (2018-7-13)
+
+该版本是一个小幅改进版本,针对`Swoole`和`Workerman`的`Cookie`支持做了一些改进,并修正了一些已知的问题。
+
+
+* 改进query类`delete`方法对软删除条件判断
+* 修正分表查询的软删除问题
+* 模型查询的时候同时传入`table`和`name`属性
+* 容器类增加`IteratorAggregate`和`Countable`接口支持
+* 路由分组支持对下面的资源路由统一设置`only/except/vars`参数
+* 改进Cookie类更好支持扩展
+* 改进Request类`post`方法
+* 改进模型自关联的自动识别
+* 改进Request类对`php://input`数据的处理
+
+
+## V5.1.18 (2018-6-30)
+
+该版本主要完善了对`Swoole`和`Workerman`的`HttpServer`运行支持,改进`Request`类,并修正了一些已知的问题。
+
+* 改进关联`append`方法的处理
+* 路由初始化和检测方法分离
+* 修正`destroy`方法强制删除
+* `app_init`钩子位置移入`run`方法
+* `think-swoole`扩展更新到2.0版本
+* `think-worker`扩展更新到2.0版本
+* 改进Url生成的域名自动识别
+* `Request`类增加`setPathinfo`方法和`setHost`方法
+* `Request`类增加`withGet`/`withPost`/`withHeader`/`withServer`/`withCookie`/`withEnv`方法进行赋值操作
+* Route类改进`host`属性的获取
+* 解决注解路由配置不生效的问题
+* 取消Test日志驱动,改为使用`close`设置关闭全局日志写入
+* 修正路由的`response`参数
+* 修正204响应输出的判断
+
+## V5.1.17 (2018-6-18)
+
+该版本主要增加了控制器中间件的支持,改进了路由功能,并且修正了社区反馈的一些问题。
+
+* 修正软删除的`delete`方法
+* 修正Query类`Count`方法
+* 改进多对多`detach`方法
+* 改进Request类`Session`方法
+* 增加控制器中间件支持
+* 模型类增加`jsonAssoc`属性用于定义json数据是否返回数组
+* 修正Request类`method`方法的请求伪装
+* 改进静态路由的匹配
+* 分组首页路由自动完整匹配
+* 改进sqlsrv的`column`方法
+* 日志类的`apart_level`配置支持true自动生成对应类型的日志文件
+* 改进`204`输出判断
+* 修正cli下页面输出的BUG
+* 验证类使用更高效的`ctype`验证机制
+* 改进Request类`cookie`方法
+* 修正软删除的`withTrashed`方法
+* 改进多态一对多的预载入查询
+* 改进Query类`column`方法的缓存读取
+* Query类增加`whereBetweenTimeField`方法
+* 改进分组下多个相同路由规则的合并匹配问题
+* 路由类增加`getRule`/`getRuleList`方法获取定义的路由
+
+## V5.1.16 (2018-6-7)
+
+该版本主要修正了社区反馈的一些问题,并对Request类做了进一步规范和优化。
+
+* 改进Session类的`boot`方法
+* App类的初始化方法可以单独执行
+* 改进Request类的`param`方法
+* 改进资源路由的变量替换
+* Request类增加`__isset`方法
+* 改进`useGlobalScope`方法对软删除的影响
+* 修正命令行调用
+* 改进Cookie类`init`方法
+* 改进多对多关联删除的返回值
+* 一对多关联写入支持`replace`
+* 路由增加`filter`检测方法,用于通过请求参数检测路由是否匹配
+* 取消Request类`session/env/server`方法的`filter`参数
+* 改进关联的指定属性输出
+* 模型删除操作删除后不清空对象数据仅作标记
+* 调整模型的`save`方法返回值为布尔值
+* 修正Request类`isAjax`方法
+* 修正中间件的模块配置读取
+* 取消Request类的请求变量的设置功能
+* 取消请求变量获取的默认修饰符
+* Request类增加`setAction/setModule/setController`方法
+* 关联模型的`delete`方法调用Query类
+* 改进URL生成的域名识别
+* 改进URL检测对已定义路由的域名判断
+* 模型类增加`isExists`和`isForce`方法
+* 软删除的`destroy`和`restore`方法返回值调整为布尔值
+
+## V5.1.15 (2018-6-1)
+
+该版本主要改进了路由缓存的性能和缓存方式设置,增加了JSON格式文件日志的支持,并修正了社区反馈的一些问题。
+
+* 容器类增加`exists`方法 仅判断是否存在对象实例
+* 取消配置类的`autoload`方法
+* 改进路由缓存大小提高性能
+* 改进Dispatch类`init`方法
+* 增加`make:validate`指令生成验证器类
+* Config类`get`方法支持默认值参数
+* 修正字段缓存指令
+* 改进App类对`null`数据的返回
+* 改进模型类的`__isset`方法判断
+* 修正`Query`类的`withAggregate`方法
+* 改进`RuleItem`类的`setRuleName`方法
+* 修正依赖注入和参数的冲突问题
+* 修正Db类对第三方驱动的支持
+* 修正模型类查询对象问题
+* 修正File缓存驱动的`has`方法
+* 修正资源路由嵌套
+* 改进Request类对`$_SERVER`变量的读取
+* 改进请求缓存处理
+* 路由缓存支持指定单独的缓存方式和参数
+* 修正资源路由的中间件多次执行问题
+* 修正`optimize:config`指令
+* 文件日志支持`JSON`格式日志保存
+* 修正Db类`connect`方法
+* 改进Log类`write`方法不会自动写入之前日志
+* 模型的关联操作默认启用事务
+* 改进软删除的事件响应
+
+## V5.1.14 (2018-5-18)
+
+该版本主要对底层容器进行了一些优化改进,并增加了路由缓存功能,可以进一步提升路由性能。
+
+* 依赖注入的对象参数传入改进
+* 改进核心类的容器实例化
+* 改进日期字段的读取
+* 改进验证类的`getScene`方法
+* 模型的`create`方法和`save`方法支持`replace`操作
+* 改进`Db`类的调用机制
+* App类调整为容器类
+* 改进容器默认绑定
+* `Loader`类增加工厂类的实例化方法
+* 增加路由变量默认规则配置参数
+* 增加路由缓存设计
+* 错误处理机制改进
+* 增加清空路由缓存指令
+
+
+## V5.1.13 (2018-5-11)
+
+该版本主要增加了MySQL的XA事务支持,模型事件支持观察者,以及对Facade类的改进。
+
+* 改进自动缓存
+* 改进Url生成
+* 修正数据缓存
+* 修正`value`方法的缓存
+* `join`方法和`view`方法的条件支持使用`Expression`对象
+* 改进驱动的`parseKey`方法
+* 改进Request类`host`方法和`domain`方法对端口的处理
+* 模型增加`withEvent`方法用于控制当前操作是否需要执行模型事件
+* 模型`setInc/setDec`方法支持更新事件
+* 模型添加`before_restore/after_restore`事件
+* 增加模型事件观察者
+* 路由增加`mobile`方法设置是否允许手机访问
+* 数据库XA事务支持
+* 改进索引数组查询对`IN`查询的支持
+* 修正`invokeMethod`方法
+* 修正空数据写入返回值的BUG
+* redis驱动支持`predis`
+* 改进`parseData`方法
+* 改进模块加载
+* App类初始化方法调整
+* 改进数组查询对表达式`Expression`对象支持
+* 改进闭包的依赖注入调用
+* 改进多对多关联的中间表模型更新
+* 增加容器中对象的自定义实例化
+
+## V5.1.12 (2018-4-25)
+
+该版本主要改进了主从查询的及时性,并支持动态设置请求数据。
+
+* 支持动态设置请求数据
+* 改进`comment`方法解析
+* 修正App类`__unset`方法
+* 改进url生成的域名绑定
+* 改进主从查询的及时性
+* 修正`value`的数据缓存功能
+* 改进分页类的集合对象方法调用
+* 改进Db类的代码提示
+* SQL日志增加主从标记
+
+## V5.1.11 (2018-4-19)
+
+该版本为安全和修正版本,改进了JSON查询的参数绑定问题和容器类对象实例获取,并包含一处可能的安全隐患,建议更新。
+
+* 支持指定JSON数据查询的字段类型
+* 修正`selectInsert`方法
+* `whereColumn`方法支持数组方式
+* 改进容器类`make`方法
+* 容器类`delete`方法支持数组
+* 改进`composer`自动加载
+* 改进模板引擎
+* 修正`like`查询的一处安全隐患
+
+## V5.1.10 (2018-4-16)
+
+该版本为修正版本,修正上一个版本的一些BUG,并增强了`think clear`指令。
+
+* 改进`orderField`方法
+* 改进`exists`查询
+* 修改cli模式入口文件位置计算
+* 修正`null`查询
+* 改进`parseTime`方法
+* 修正关联预载入查询
+* 改进`mysql`驱动
+* 改进`think clear`指令 支持 `-c -l -r `选项
+* 改进路由规则对`/`结尾的支持
+
+## V5.1.9 (2018-4-12)
+
+该版本主要是一些改进和修正,并包含一个安全更新,是一个推荐更新版本。
+
+* 默认模板渲染规则支持配置保持操作方法名
+* 改进`Request`类的`ip`方法
+* 支持模型软删除字段的默认值定义
+* 改进路由变量规则对中文的支持
+* 使用闭包查询的时候使用`cache(true)` 抛出异常提示
+* 改进`Loader`类`loadComposerAutoloadFiles`方法
+* 改进查询方法安全性
+* 修正路由地址中控制器名驼峰问题
+* 调整上一个版本的`module_init`和`app_begin`的钩子顺序问题
+* 改进CLI命令行执行的问题
+* 修正社区反馈的其它问题
+
+## V5.1.8 (2018-4-5)
+
+该版本主要改进了中间件的域名和模块支持,并同时修正了几个已知问题。
+
+* 增加`template.auto_rule` 参数设置默认模板渲染的操作名自动转换规则
+* 默认模板渲染规则改由视图驱动实现
+* 修正路由标识定义
+* 修正控制器路由方法
+* 改进Request类`ip`方法支持自定义代理IP参数
+* 路由注册中间件支持数组方式别名
+* 改进命令行执行下的`composer`自动加载
+* 添加域名中间件注册支持
+* 全局中间件支持模块定义文件
+* Log日志配置支持`close`参数可以全局关闭日志写入
+* 中间件方法中捕获`HttpResponseException`异常
+* 改进中间件的闭包参数传入
+* 改进分组路由的延迟解析
+* 改进URL生成对域名绑定的支持
+* 改进文件缓存和文件日志驱动的并发支持
+
+## V5.1.7 (2018-3-28)
+
+该版本主要修正了路由的一些问题,并改进了查询的安全性。
+
+* 支持`middleware`配置文件预先定义中间件别名方便路由调用
+* 修正资源路由
+* 改进`field`方法 自动识别`fieldRaw`
+* 增加`Expression`类
+* Query类增加`raw`方法
+* Query类的`field`/ `order` 和` where`方法都支持使用`raw`表达式查询
+* 改进`inc/dec`查询 支持批量更新
+* 改进路由分组
+* 改进Response类`create`方法
+* 改进composer自动加载
+* 修正域名路由的`append`方法
+* 修正操作方法的初始化方法获取不到问题
+
+## V5.1.6 (2018-3-26)
+
+该版本主要改进了路由规则的匹配算法,大幅提升了路由性能。并正式引入了中间件的支持,可以在路由中定义或者全局定义。另外包含了一个安全更新,是一个建议更新版本。
+
+* 改进URL生成对路由`ext`方法的支持
+* 改进查询缓存对不同数据库相同表名的支持
+* 改进composer自动加载的性能
+* 改进空路由变量对默认参数的影响
+* mysql的`json`字段查询支持多级
+* Query类增加`option`方法
+* 优化路由匹配
+* 修复验证规则数字键名丢失问题
+* 改进路由Url生成
+* 改进一对一关联预载入查询
+* Request类增加`rootDomain`方法
+* 支持API资源控制器生成 `make:controller --api`
+* 优化Template类的标签解析
+* 容器类增加删除和清除对象实例的方法
+* 修正MorphMany关联的`eagerlyMorphToMany`方法一处错误
+* Container类的异常捕获改进
+* Domain对象支持`bind`方法
+* 修正分页参数
+* 默认模板的输出规则不受URL影响
+* 注解路由支持多级控制器
+* Query类增加`getNumRows`方法获取前次操作影响的记录数
+* 改进查询条件的性能
+* 改进模型类`readTransform`方法对序列化类型的处理
+* Log类增加`close`方法可以临时关闭当前请求的日志写入
+* 文件日志方式增加自动清理功能(设置`max_files`参数)
+* 修正Query类的`getPk`方法
+* 修正模板缓存的布局开关问题
+* 修正Query类`select`方法的缓存
+* 改进input助手函数
+* 改进断线重连的信息判断
+* 改进正则验证方法
+* 调整语言包的加载顺序 放到`app_init`之前
+* controller类`fetch`方法改为`final`
+* 路由地址中的变量支持使用`<var>`方式
+* 改进XMLResponse 支持传入编码过的xml内容
+* 修正Query类`view`方法的数组表名支持
+* 改进路由的模型闭包绑定
+* 改进分组变量规则的继承
+* 改进`cli-server`模式下的`composer`自动加载
+* 路由变量规则异常捕获
+* 引入中间件支持
+* 路由定义增加`middleware`方法
+* 增加生成中间件指令`make:middleware` 
+* 增加全局中间件定义支持
+* 改进`optimize:config`指令对全局中间件的支持
+* 改进config类`has`方法
+* 改进时间查询的参数绑定
+* 改进`inc/dec/exp`查询的安全性
+
+
+## V5.1.5 (2018-1-31)
+
+该版本主要增强了数据库的JSON查询,并支持JSON字段的聚合查询,改进了一些性能问题,修正了路由的一些BUG,主要更新如下:
+
+* 改进数据集查询对`JSON`数据的支持
+* 改进聚合查询对`JSON`字段的支持
+* 模型类增加`getOrFail`方法
+* 改进数据库驱动的`parseKey`方法
+* 改进Query类`join`方法的自关联查询
+* 改进数据查询不存在不生成查询缓存
+* 增加`run`命令行指令启动内置服务器
+* `Request`类`pathinfo`方法改进对`cli-server`支持
+* `Session`类增加`use_lock`配置参数设置是否启用锁机制
+* 优化`File`缓存自动生成空目录的问题
+* 域名及分组路由支持`append`方法传递隐式参数
+* 改进日志的并发写入问题
+* 改进`Query`类的`where`方法支持传入`Query`对象
+* 支持设置单个日志文件的文件名
+* 修正路由规则的域名条件约束 
+* `Request`类增加`subDomain`方法用于获取当前子域名
+* `Response`类增加`allowCache`方法控制是否允许请求缓存
+* `Request`类增加`sendData`方法便于扩展
+* 改进`Env`类不依赖`putenv`方法
+* 改进控制台`trace`显示错误
+* 改进`MorphTo`关联
+* 改进完整路由匹配后带斜线访问出错的情况
+* 改进路由的多级分组问题
+* 路由url地址生成支持多级分组
+* 改进路由Url生成的`url_convert`参数的影响
+* 改进`miss`和`auto`路由内部解析
+* 取消预载入关联查询缓存功能
+
+## V5.1.4 (2018-1-19)
+
+该版本主要增强了数据库和模型操作,主要更新如下:
+
+* 支持设置 `deleteTime`属性为`false` 关闭软删除
+* 模型增加`getError`方法
+* 改进Query类的`getTableFields`/`getFieldsType`方法 支持表名自动获取
+* 模型类`toCollection`方法增加参数指定数据集类
+* 改进`union`查询
+* 关联预载入`with`方法增加缓存参数
+* 改进模型类的`get`和`all`方法的缓存 支持关联缓存
+* 支持`order by field`操作
+* 改进`insertAll`分批写入
+* 改进`json`字段数据支持
+* 增加JSON数据的模型对象化操作
+* 改进路由`ext`参数检测 
+* 修正`rule`方法的`method`参数使用 `get|post` 方式注册路由的问题
+
+## V5.1.3 (2018-1-12)
+
+该版本主要改进了路由及调整函数加载顺序,主要更新如下:
+
+* 增加`env`助手函数;
+* 增加`route`助手函数;
+* 增加视图路由方法;
+* 增加路由重定向方法;
+* 路由默认区分最后的目录斜杆(支持设置不区分);
+* 调整公共文件和配置文件的加载顺序(可以在配置文件中直接使用助手函数);
+* 视图类增加`filter`方法设置输出过滤;
+* `view`助手函数增加`filter`参数;
+* 改进缓存生成指令;
+* Session类的`get`方法支持获取多级;
+* Request类`only`方法支持指定默认值;
+* 改进路由分组;
+* 修正使用闭包查询的时候自动数据缓存出错的情况;
+* 废除`view_filter`钩子位置;
+* 修正分组下面的资源路由;
+* 改进session驱动;
+
+## V5.1.2 (2018-1-8)
+
+该版本改进了配置类及数据库类,主要更新如下:
+
+* 修正嵌套路由分组;
+* 修正自定义模板标签界定符后表达式语法出错的情况;
+* 修正自关联的多次调用问题;
+* 修正数组查询的`null`条件查询;
+* 修正Query类的`order`及`field`的一处可能的BUG;
+* 配置参数设置支持三级;
+* 配置对象支持`ArrayAccess`;
+* App类增加`path`方法用于设置应用目录;
+* 关联定义增加`selfRelation`方法用于设置是否为自关联;
+
+## V5.1.1 (2018-1-3)
+
+修正一些反馈的BUG,包括:
+
+* 修正Cookie类存取数组的问题
+* 修正Controller的`fetch`方法
+* 改进跨域请求
+* 修正`insertAll`方法
+* 修正`chunk`方法
+
+## V5.1.0 (2018-1-1)
+
+主要更新如下:
+
+* 增加注解路由支持
+* 路由支持跨域请求设置
+* 增加`app_dispatch`钩子位置
+* 修正多对多关联的`detach`方法
+* 修正软删除的`destroy`方法
+* Cookie类`httponly`参数默认为false
+* 日志File驱动增加`single`参数配置记录同一个文件(不按日期生成)
+* 路由的`ext`和`denyExt`方法支持不传任何参数
+* 改进模型的`save`方法对`oracle`的支持
+* Query类的`insertall`方法支持配合`data`和`limit`方法
+* 增加`whereOr`动态查询支持
+* 日志的ip地址记录改进
+* 模型`saveAll`方法支持`isUpdate`方法
+* 改进`Pivot`模型的实例化操作
+* 改进Model类的`data`方法
+* 改进多对多中间表模型类
+* 模型增加`force`方法强制更新所有数据
+* Hook类支持设置入口方法名称
+* 改进验证类
+* 改进`hasWhere`查询的数据重复问题
+* 模型的`saveall`方法返回数据集对象
+* 改进File缓存的`clear`方法
+* 缓存添加统一的序列化机制
+* 改进泛三级域名的绑定
+* 改进泛域名的传值和取值
+* Request类增加`panDomain`方法
+* 改进废弃字段判断
+* App类增加`create`方法用于实例化应用类库
+* 容器类增加`has`方法
+* 改进多数据库切换连接
+* 改进断线重连的异常捕获
+* 改进模型类`buildQuery`方法
+* Query类增加`unionAll`方法
+* 关联统计功能增强(支持Sum/Max/Min/Avg)
+* 修正延迟写入
+* chunk方法支持复合主键
+* 改进JSON类型的写入
+* 改进Mysql的insertAll方法
+* Model类`save`方法改进复合主键包含自增的情况
+* 改进Query类`inc`和`dec`方法的关键字处理
+* File缓存inc和dec方法保持原来的有效期
+* 改进redis缓存的有效期判断
+* 增加checkRule方法用于单独数据的多个验证规则
+* 修正setDec方法的延迟写入
+* max和min方法增加force参数
+* 二级配置参数区分大小写
+* 改进join方法自关联的问题
+* 修正关联模型自定义表名的情况
+* Query类增加getFieldsType和getTableFields方法
+* 取消视图替换功能及view_replace_str配置参数
+* 改进域名绑定模块后的额外路由规则问题
+* 改进mysql的insertAll方法
+* 改进insertAll方法写入json字段数据的支持
+* 改进redis长连接多编号库的情况
+
+## RC3版本(2017-11-6)
+
+主要更新如下:
+
+* 改进redis驱动的`get`方法
+* 修正Query类的`alias`方法
+* `File`类错误信息支持多语言
+* 修正路由的额外参数解析
+* 改进`whereTime`方法
+* 改进Model类`getAttr`方法
+* 改进App类的`controller`和`validate`方法支持多层
+* 改进`HasManyThrough`类
+* 修正软删除的`restore`方法
+* 改进`MorpthTo`关联
+* 改进数据库驱动类的`parseKey`方法
+* 增加`whereField`动态查询方法
+* 模型增加废弃字段功能
+* 改进路由的`after`行为检查和`before`行为机制
+* 改进路由分组的检查
+* 修正mysql的`json`字段查询
+* 取消Connection类的`quote`方法
+* 改进命令行的支持
+* 验证信息支持多语言
+* 修正路由模型绑定
+* 改进参数绑定类型对枚举类型的支持
+* 修正模板的`{$Think.version} `输出
+* 改进模板`date`函数解析
+* 改进`insertAll`方法支持分批执行
+* Request类`host`方法支持反向代理
+* 改进`JumpResponse`支持区分成功和错误模板
+* 改进开启类库后缀后的关联外键自动识别问题
+* 修正一对一关联的JOIN方式预载入查询问题
+* Query类增加`hidden`方法
+
+## RC2版本(2017-10-17)
+
+主要更新如下:
+
+* 修正视图查询
+* 修正资源路由
+* 修正`HasMany`关联 修正`where`方法的闭包查询
+* 一对一关联绑定属性到父模型后 关联属性不再保留
+* 修正应用的命令行配置文件读取
+* 改进`Connection`类的`getCacheKey`方法
+* 改进文件上传的非法图像异常
+* 改进验证类的`unique`规则
+* Config类`get`方法支持获取一级配置
+* 修正count方法对`fetchSql`的支持
+* 修正mysql驱动对`socket`支持
+* 改进Connection类的`getRealSql`方法
+* 修正`view`助手函数
+* Query类增加`leftJoin` `rightJoin` 和 `fullJoin`方法
+* 改进app_namespace的获取
+* 改进`append`方法对一对一`bind`属性的支持
+* 改进关联的`saveall`方法的返回值
+* 路由标识设置异常修复
+* 改进Route类`rule`方法
+* 改进模型的`table`属性设置
+* 改进composer autofile的加载顺序
+* 改进`exception_handle`配置对闭包的支持
+* 改进app助手函数增加参数
+* 改进composer的加载路径判断
+* 修正路由组合变量的URL生成
+* 修正路由URL生成
+* 改进`whereTime`查询并支持扩展规则
+* File类的`move`方法第二个参数支持`false`
+* 改进Config类
+* 改进缓存类`remember`方法
+* 惯例配置文件调整 Url类当普通模式参数的时候不做`urlencode`处理
+* 取消`ROOT_PATH`和`APP_PATH`常量定义 如需更改应用目录 自己重新定义入口文件
+* 增加`app_debug`的`Env`获取
+* 修正泛域名绑定
+* 改进查询表达式的解析机制
+* mysql增加`regexp`查询表达式 支持正则查询
+* 改进查询表达式的异常判断
+* 改进model类的`destroy`方法
+* 改进Builder类 取消`parseValue`方法
+* 修正like查询的参数绑定问题
+* console和start文件移出核心纳入应用库
+* 改进Db类主键删除方法
+* 改进泛域名绑定模块
+* 取消`BIND_MODULE`常量 改为在入口文件使用`bind`方法设置
+* 改进数组查询
+* 改进模板渲染的异常处理
+* 改进控制器基类的架构方法参数
+* 改进Controller类的`success`和`error`方法
+* 改进对浏览器`JSON-Handle`插件的支持
+* 优化跳转模板的移动端显示
+* 修正模型查询的`chunk`方法对时间字段的支持
+* 改进trace驱动
+* Collection类增加`push`方法
+* 改进Redis Session驱动
+* 增加JumpResponse驱动
+
+
+## RC1(2017-9-8)
+
+主要新特性为:
+
+* 引入容器和Facade支持
+* 依赖注入完善和支持更多场景
+* 重构的(对象化)路由
+* 配置和路由目录独立
+* 取消系统常量
+* 助手函数增强
+* 类库别名机制
+* 模型和数据库增强
+* 验证类增强
+* 模板引擎改进
+* 支持PSR-3日志规范
+* RC1版本取消了5.0多个字段批量数组查询的方式

+ 32 - 0
LICENSE.txt

@@ -0,0 +1,32 @@
+
+ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
+版权所有Copyright © 2006-2018 by ThinkPHP (http://thinkphp.cn)
+All rights reserved。
+ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
+
+Apache Licence是著名的非盈利开源组织Apache采用的协议。
+该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
+允许代码修改,再作为开源或商业软件发布。需要满足
+的条件: 
+1. 需要给代码的用户一份Apache Licence ;
+2. 如果你修改了代码,需要在被修改的文件中说明;
+3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
+带有原来代码中的协议,商标,专利声明和其他原来作者规
+定需要包含的说明;
+4. 如果再发布的产品中包含一个Notice文件,则在Notice文
+件中需要带有本协议内容。你可以在Notice中增加自己的
+许可,但不可以表现为对Apache Licence构成更改。 
+具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.

+ 10 - 0
README.md

@@ -0,0 +1,10 @@
+廊坊项目
+===============
+
+基于ThinkPHP 5.1(LTS版本)开发
+
+> 运行环境要求PHP5.6以上。
+
+> MYSQL要求5.7及以上
+
+> Apache2.4

+ 62 - 0
application/admin/common.php

@@ -0,0 +1,62 @@
+<?php
+/**
+ * 检测用户是否登录
+ * @return integer 0-未登录,大于0-当前登录用户ID
+ */
+function is_login(){
+    $user = session('user_auth');
+    if (empty($user)) {
+        return 0;
+    } else {
+        return session('user_auth_sign') == data_auth_sign($user) ? $user['id'] : 0;
+    }
+}
+
+
+/**
+ * 递归获取菜单列表
+ * @param int $pid
+ * @param array $result
+ * @param int $flag
+ * @return array
+ */
+function get_menu($pid=0,&$result=array(),$flag=0){
+    $map['pid'] = $pid;
+    $list = \think\Db::name('menu')->where($map)->field('id,title,pid')->order('sort asc')->select();
+    $flag++;
+    foreach ($list as $k=>$v){
+        if($flag == 4){
+            continue;
+        }
+        if($flag>1){
+            $str = '';
+            if($flag>2){
+                for ($i=2;$i<$flag;$i++){
+                    $str .= ' |-- ';
+                }
+            }
+            $v['title'] = $str.' |-- '.$v['title'];
+        }
+        $result[] = $v;
+        get_menu($v['id'],$result,$flag);
+    }
+    return $result;
+}
+
+/**
+ * 获取当前org_id
+ * @return int
+ */
+function cur_org_id(){
+
+    return session('orgId');
+}
+//判断是否是超级管理员或总公司人员
+function is_admin($userId){
+    if($userId==1) return true;
+    $userInfo = \think\Db::name('user')
+        ->where('id',$userId)
+        ->find();
+    return $userInfo['type']==1?true:false;
+}
+

+ 7 - 0
application/admin/config/app.php

@@ -0,0 +1,7 @@
+<?php
+
+//配置文件
+return [
+    'dispatch_success_tmpl'  => __DIR__ . '/../view/commmon/dispatch_jump.tpl',
+    'dispatch_error_tmpl'    => __DIR__ . '/../view/commmon/dispatch_jump.tpl',
+];

+ 378 - 0
application/admin/controller/Address.php

@@ -0,0 +1,378 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class Address extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $type = input('type','','trim');
+            if($type != ''){
+                $map[]=['','exp',Db::raw("FIND_IN_SET($type,types)")];
+            }
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('address')->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $ts = $v['types']?explode(',',$v['types']):[];
+                $lists[$k]['types_text'] = model('Address')->getTypeStr($ts);
+            }
+
+            //数据返回
+            $totalCount = db('address')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $types = model('Address')->getTypes();
+            $this->assign('types',$types);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('Address')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('Address')->getError());
+            }
+        }else{
+            if($id){
+                $info = db('address')->where('id',$id)->find();
+                if($info){
+                    $info['types'] = $info['types']?explode(',',$info['types']):[];
+                }
+                $this->assign('info',$info);
+            }
+            $ts = model('Address')->getTypes();
+            $types = [];
+            foreach ($ts as $k=>$v){
+                $types[] = [
+                    'id' => $k,
+                    'title' => $v
+                ];
+            }
+            $dep = model('dep')->getList();
+            $this->assign('dep',$dep);
+            $this->assign('types',$types);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('address')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('address')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function qrcode($id=0){
+        $info = Db::name('address')->where('id',$id)->find();
+        $code = get_qrcode_str('address',$id);
+        $config = config('app.addr_url');
+        $code = $config.$code;
+        $this->assign('code',$code);
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+    // 地址下载
+    public function addrdown(){
+        $orgid = $this->orgId;
+        $map[] = ['del','=',0];
+        $map[] = ['org_id','=',$this->orgId];
+        $title = input('title','','trim');
+        if($title){
+            $map[] = ['title','like','%'.$title.'%'];
+        }
+        $enable = input('enable','','trim');
+        if($enable != ''){
+            $map[] = ['enable','=',$enable];
+        }
+        $type = input('type','','trim');
+        if($type != ''){
+            $map[]=['','exp',Db::raw("FIND_IN_SET($type,types)")];
+        }
+        $ids = input('ids','','trim');
+        if($ids !=''){
+            $map[] = ['id','in',explode(',',$ids)];
+        }
+        $map= empty($map) ? true: $map;
+        //数据查询
+        $lists = db('address')->where($map)->select();
+        $config = config('app.addr_url');
+        foreach ($lists as $k=>$v){
+            $lists[$k]['code'] = $config.get_qrcode_str('address',$v['id']);
+        }
+        $path = date('Ymd').'_'.$orgid.'_'.time().mt_rand(1000,9999);
+        $dir = './uploads/qrcodeimg/'.$path.'/';
+
+
+        foreach ($lists as $v1){
+            $name = str_ireplace('/','_',$v1['title']).'('.$v1['id'].')'.'.jpg';
+            $filepath = $dir.'/'.$name;
+            create_qrcode($v1['code'],$filepath);
+        }
+
+        $zippath = './uploads/qrcodeimg/'.$path.'.zip';
+        $spath = $dir;
+        @unlink($zippath);
+        $zip = new \ZipArchive();
+        if($zip->open($zippath, \ZipArchive::CREATE)=== TRUE){
+            add_file_to_zip($spath,$zip); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
+            $zip->close(); //关闭处理的zip文件
+            if(!file_exists($zippath)){
+                $this->error("打包失败"); //即使创建,仍有可能失败。。。。
+            }
+
+            deldir($dir); // 删除生成的目录
+
+            $downname = session('orgName').'地点二维码.zip';
+            header("Cache-Control: public");
+            header("Content-Description: File Transfer");
+            header('Content-disposition: attachment; filename='.$downname); //文件名
+            header("Content-Type: application/zip"); //zip格式的
+            header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
+            header('Content-Length: '. filesize($zippath)); //告诉浏览器,文件大小
+            @readfile($zippath);
+
+        }else{
+            $this->error("打包失败");
+        }
+    }
+
+    public function import(){
+        return $this->fetch();
+    }
+    /**
+     * 下载点模板
+     */
+    public function downloadtem(){
+        set_time_limit(0);
+        ini_set("memory_limit","512M");
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+
+        $fileName = '地点模板.xlsx';
+        $excel = new \PHPExcel();
+        $sheet = $excel->setActiveSheetIndex(0);
+        $arr = array('A','B','C','D');
+        $types = model('Address')->getTypes();
+        ksort($types);
+        foreach($arr as $k=>$v){
+            $excel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(true);//换行
+            $excel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
+            if($k==3){
+                $excel->getActiveSheet()->getColumnDimension($v)->setWidth(100);
+            }else{
+                $excel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
+
+            }
+        }
+        $sheet->setCellValueByColumnAndRow(0,1,'名称');
+        $sheet->setCellValueByColumnAndRow(1,1,'设备编号');
+        $sheet->setCellValueByColumnAndRow(2,1,'备注');
+        $sheet->setCellValueByColumnAndRow(3,1,'类型('.implode(',',$types).') 多个用英文逗号隔开');
+
+
+        $excel->getActiveSheet()->setCellValue('A2', '示例地址');
+        $excel->getActiveSheet()->setCellValue('B2', 'XXX');
+        $excel->getActiveSheet()->setCellValue('C2', 'XXX');
+        $excel->getActiveSheet()->setCellValue('D2', '报修,运送');
+
+        ob_end_clean();//清除缓冲区,避免乱码
+        header('Content-Type: application/vnd.ms-excel');
+        header('Content-Disposition: attachment;filename="'.$fileName.'"');
+        header('Cache-Control: max-age=0');
+
+        $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
+        $objWriter->save('php://output'); //文件通过浏览器下载
+
+    }
+
+
+    /**
+     * 导入
+     */
+    public function importexcel(){
+        set_time_limit(0);
+        ini_set("memory_limit", -1);
+        ob_flush();//清空缓存
+        flush();//刷新缓存
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+        $orgId = $this->orgId;
+        if(request()->file()) {
+            $file = request()->file('file');
+            //获取文件后缀
+            $e = explode('.',$_FILES['file']['name']);
+            $ext = $e[count($e)-1];
+            if($ext == 'xls'){
+                \PHPExcel_IOFactory::createReader( 'Excel5');
+            }else{
+                \PHPExcel_IOFactory::createReader('Excel2007');
+            }
+            $newArr=['xls','xlsx'];
+            if(!in_array($ext,$newArr)){
+                exit('文件格式不正确');
+            }
+            // 移动到框架应用根目录/uploads/ 目录下
+            $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
+                ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
+            if(!$info){
+                exit('文件上传失败');
+            }
+            $img = './uploads/files/' . $info->getSaveName();
+            $filePath = str_replace('\\', '/', $img);
+            $newPath = \PHPExcel_IOFactory::load($filePath);
+
+            $excelArray = $newPath->getsheet(0)->toArray();   //转换为数组格式
+
+            array_shift($excelArray);  //删除第一个数组(标题);
+
+            if(empty($excelArray)){
+                exit('文件内容为空');
+            }
+            foreach ($excelArray as $k => $v) {
+                if(!$v[0]){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称为空,未导入</font><br />";
+                    continue;
+                }
+                if(!$v[3]){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型为空,未导入</font><br />";
+                    continue;
+                }
+                $check = Db::name('address')
+                    ->where('org_id',$orgId)
+                    ->where('del',0)
+                    ->where('title',$v[0])
+                    ->find();
+                if($check){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称已存在,未导入</font><br />";
+                    continue;
+                }
+                $typeId = [];
+                $type = explode(',',$v[3]);
+                $types = model('Address')->getTypes();
+                $types =  array_flip($types);
+                foreach ($type as $k1=>$v1){
+                    if(isset($types[$v1])){
+                        $typeId[] = $types[$v1];
+                    }
+                }
+                if(count($type)!=count($typeId) || empty($typeId)){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型字段格式错误,未导入</font><br />";
+                    continue;
+                }
+                $rData = [
+                    'org_id'=>$orgId,
+                    'title'=>$v[0],
+                    'sn'=>$v[1],
+                    'remark'=>$v[2],
+                    'types'=>implode(',',$typeId),
+                    'create_time'=>getTime()
+                ];
+                $ret=Db::name('address')->insert($rData);
+
+                if(!$ret){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,导入失败</font><br />";
+                }else{
+                    echo "<font color=\"green\" style='margin-left:20px;font-size: 17px'>第".($k+1)."行,导入成功</font><br />";
+                }
+
+            }
+        }else{
+            exit('请上传文件');
+        }
+
+    }
+
+    public function three($id=0){
+        if(request()->isPost()){
+            $id = input('id/d',0);
+            $x = input('x','','trim');
+            $y = input('y','','trim');
+            $z = input('z','','trim');
+            $xyz[] = $x;
+            $xyz[] = $y;
+            $xyz[] = $z;
+            $ret = Db::name('address')->where('id',$id)->update(['xyz'=>implode(',',$xyz),'update_time' => date('Y-m-d H:i:s')]);
+            if($ret){
+                $this->success('操作成功');
+            }else{
+                $this->error('操作失败');
+            }
+        }else{
+            $info = Db::name('address')->where('id',$id)->find();
+            $arr = $info['xyz']?explode(',',$info['xyz']):[];
+            $x = '';
+            $y = '';
+            $z = '';
+            if(count($arr) == 3){
+                $x = $arr[0];
+                $y = $arr[1];
+                $z = $arr[2];
+            }
+            $this->assign('x',$x);
+            $this->assign('y',$y);
+            $this->assign('z',$z);
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+
+}

+ 141 - 0
application/admin/controller/AppIcon.php

@@ -0,0 +1,141 @@
+<?php
+namespace app\admin\controller;
+
+use app\hander\HelpHander;
+use think\Db;
+use think\Exception;
+
+class AppIcon extends Auth
+{
+
+    public function index(){
+        $pid = input('pid',0,'intval');
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $map[] = ['del','=',0];
+            $map[] = ['pid','=',$pid];
+            //数据查询
+            $lists = db('app_icon')->where($map)->limit($start,$length)->order(['sort'=>'desc','id'=>'desc'])->select();
+            foreach ($lists as $k=>$v){
+                if($v['pid']){
+                    $lists[$k]['ptitle'] = db('app_icon')->where('id',$v['pid'])->value('name');
+                }else{
+                    $lists[$k]['ptitle'] = '无';
+                }
+            }
+            //数据返回
+            $totalCount = db('app_icon')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            if($pid){
+                $ptitle = '['.db('app_icon')->where('id',$pid)->value('name').']子模块列表';
+            }else{
+                $ptitle = '模块列表';
+            }
+            $this->assign('meta_title',$ptitle);
+            $this->assign('pid',$pid);
+            $this->assign('pid',$pid);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0,$pid=0){
+        if(request()->isPost()){
+            $res = model('AppIcon')->updates();
+            if($res){
+                $this->success('操作成功',url('index',['pid' => $pid]));
+            }else{
+                $this->error(model('AppIcon')->getError());
+            }
+        }else{
+            $title = '添加';
+            if($id){
+                $title = '编辑';
+                $info = db('app_icon')->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            $this->assign('pid',$pid);
+            $this->assign('title',$title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $info = db('app_icon')->where('pid',$id)->where('del',0)->find();
+        if($info){
+            $this->error('有下级分类不能删除');
+        }
+        $res = db('app_icon')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('AppIcon')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function batchSort(){
+        $data = input('data','','trim');
+        if(!$data){
+            $this->error('参数错误');
+        }
+        $data = json_decode($data,true);
+        if(!$data){
+            $this->error('参数错误');
+        }
+
+        Db::startTrans();
+        try{
+            foreach ($data as $k=>$v){
+                Db::name('app_icon')->where('id',$v['id'])->setField('sort',$v['sort']);
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+}

+ 91 - 0
application/admin/controller/AppIos.php

@@ -0,0 +1,91 @@
+<?php
+namespace app\admin\controller;
+
+class AppIos extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('app_ios')->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db('app_ios')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('AppIos')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('AppMgr')->getError());
+            }
+        }else{
+            if($id){
+                $info = db('AppIos')->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('AppIos')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('AppIos')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+}

+ 91 - 0
application/admin/controller/AppMgr.php

@@ -0,0 +1,91 @@
+<?php
+namespace app\admin\controller;
+
+class AppMgr extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('app_mgr')->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db('app_mgr')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('AppMgr')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('AppMgr')->getError());
+            }
+        }else{
+            if($id){
+                $info = db('AppMgr')->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('AppMgr')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('AppMgr')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+}

+ 160 - 0
application/admin/controller/Article.php

@@ -0,0 +1,160 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class Article extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\Article();
+        $this->table=$this->model->table;
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $cate = input('cate_id','','trim');
+            if($cate != ''){
+                $map[] = ['cate_id','=',$cate];
+            }
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['cate_name'] = db('article_cate')
+                    ->where('id',$v['cate_id'])
+                    ->value('title');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name','文章列表');
+            $cate = (new \app\common\model\ArticleCate())->getList();
+            $this->assign('cate',$cate);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $info['roles_ids'] = !empty($info['roles_ids'])?explode(',',$info['roles_ids']):[];
+                $this->assign('info',$info);
+            }
+            $roles = (new \app\common\model\WorkTypeMode())->getRoles(13);
+            $a = [];
+            foreach ($roles as $k=>$v){
+                 $a[] = [
+                     'id'=>$v['id'],
+                     'title'=>$v['name'],
+                 ];
+            }
+            $cate = (new \app\common\model\ArticleCate())->getList();
+            $this->assign('cate',$cate);
+            $this->assign('roles',$a);
+
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function batchSort(){
+        $data = input('data','','trim');
+        if(!$data){
+            $this->error('参数错误');
+        }
+        $data = json_decode($data,true);
+        if(!$data){
+            $this->error('参数错误');
+        }
+
+        Db::startTrans();
+        try{
+            foreach ($data as $k=>$v){
+                Db::name('article')->where('id',$v['id'])->setField('sort',$v['sort']);
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+
+
+}

+ 111 - 0
application/admin/controller/ArticleCate.php

@@ -0,0 +1,111 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+
+class ArticleCate extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\ArticleCate();
+        $this->table=$this->model->table;
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name','文章分类');
+
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+}

+ 529 - 0
application/admin/controller/ArticlePaper.php

@@ -0,0 +1,529 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+
+class ArticlePaper extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\ArticlePaper();
+        $this->table= $this->model->table;
+        $this->table1= 'article_record';
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['article_title'] = db('article')
+                    ->where('id',$v['article_id'])
+                    ->value('title');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name','试卷列表');
+            return $this->fetch();
+        }
+    }
+    public function record($id){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['questionnaire_id','=',$id];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table1)->where($map)->limit($start,$length)->order($order)->select();
+            //数据返回
+            $totalCount = db($this->table1)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $info = db($this->table)
+                ->where('id',$id)
+                ->find();
+            $this->assign('m_name','['.$info['title'].']'.'回收记录');
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            $article = (new \app\common\model\Article())->getList();
+            $this->assign('cate',$article);
+            return $this->fetch();
+        }
+    }
+
+    public function share($id){
+        $info =db($this->table)
+            ->where('id',$id)
+            ->find();
+        $strs = aes_encrypt('wj',config('app.encryption_key'));
+        $code = getSite().'/h5/Wj/index?id='.$id.'&code='.$strs.'&orgId='.$info['org_id'];
+        $this->assign('url',$code);
+        return $this->fetch();
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del_question($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $info = db('article_question')
+            ->where('id',$id)
+            ->find();
+        $page = db('article_paper')
+            ->where('id',$info['article_paper_id'])
+            ->find();
+        if($page['status'] ==2){
+            $this->error("已发布的试卷不能删除题目");
+        }
+        $res = db('article_question')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+
+    public function fb($id=0,$status=0){
+        $enable = $status==1 || $status==0 ?2:1;
+        $res = db($this->table)->where('id',$id)->setField('status',$enable);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    //回收记录详情
+    public function info($id){
+        $info = $this->model->record_info($id);
+        if (!$info) {
+            exit('数据不存在');
+        }
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+
+    //试题管理
+    public function article($id=0){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['del','=',0];
+            $map[] = ['article_paper_id','=',$id];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('article_question')->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db('article_question')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $info = db('article_paper')
+                ->where('id',$id)
+                ->find();
+            $this->assign('m_name','['.$info['title'].']试题列表');
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+    //添加试题
+    public function article_add($id=0){
+        if(request()->isPost()){
+            $data = request()->post();
+            $info =db('article_paper')
+                ->where('id',$data['article_paper_id'])
+                ->find();
+            if(!$info || $info['org_id'] != $this->orgId){
+                $this->error("试卷不存在");
+            }
+            if(!in_array($info['status'],[0,1])){
+                $this->error('已发布过的试卷无法添加新题目');
+            }
+            $title = trim($data['title']);
+            $score = (int) $data['score'];
+            $sort = (int) $data['sort'];
+            $type = (int) $data['type'];
+            $options = trim($data['options']);
+            if(!$title){
+                $this->error('未填写题干');
+            }
+            if(mb_strlen($title) > 500){
+                $this->error('题干过长,请控制在500字以内');
+            }
+            if($score <= 0){
+                $this->error('分值错误');
+            }
+            if(!in_array($type,array(0,1))){
+                $this->error('类型错误');
+            }
+            if(!$options){
+                $this->error('未填写题目选项');
+            }
+            $options = json_decode($options,true);
+            if(!$options){
+                $this->error('选项参数错误');
+            }
+
+            $correct = 0; // 正确答案个数
+            foreach ($options as $k=>$v){
+                $text = trim($v['text']);
+                if(!$text){
+                    $this->error('选项不能为空');
+                }
+                $options[$k]['text'] = $text;
+                if($v['answer'] == '1'){
+                    $correct++;
+                }
+            }
+            if($correct == 0){
+                $this->error('未设置正确答案');
+            }
+            if($correct > 1&&$type == 0){
+                $this->error('单选题只能设置一个正确答案');
+            }
+
+            $data = array(
+                'article_paper_id' => $data['article_paper_id'],
+                'title' => $title,
+                'type' => $type,
+                'score' => $score,
+                'sort' => $sort>0?$sort:0,
+                'options' => json_encode($options,JSON_UNESCAPED_UNICODE),
+                'create_time' => date('Y-m-d h:i:s'),
+                'update_time' => date('Y-m-d h:i:s')
+            );
+            $res = db('article_question')
+                ->insertGetId($data);
+            if($res){
+                $this->success('操作成功');
+            }else{
+                $this->error('操作失败');
+            }
+        }else{
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+
+    public function edit_question($id){
+        if ($id <= 0) {
+            $this->error("参数错误");
+        }
+
+        $question = db('article_question')
+            ->where('id',$id)
+            ->find();
+        if(!$question){
+            $this->error("题目不存在");
+        }
+
+        $info = db('article_paper')
+            ->where('id',$question['article_paper_id'])
+            ->find();
+        if(!$info || $info['org_id'] != $this->orgId){
+            $this->error("试卷不存在");
+        }
+        if(request()->isPost()){
+            $data = request()->post();
+            $title = trim($data['title']);
+            $options = trim($data['options']);
+            if(!$title){
+                $this->error('未填写题干');
+            }
+            if(mb_strlen($title) > 500){
+                $this->error('题干过长,请控制在500字以内');
+            }
+            if(in_array($info['status'],[0,1])){
+                $score = (int) $data['score'];
+                $sort = (int) $data['sort'];
+                $type = (int) $data['type'];
+                if($score <= 0){
+                    $this->error('分值错误');
+                }
+                if(!in_array($type,array(0,1))){
+                    $this->error('类型错误');
+                }
+            }
+            if(!$options){
+                $this->error('未填写题目选项');
+            }
+            $options = json_decode($options,true);
+            if(!$options){
+                $this->error('选项参数错误');
+            }
+
+            $correct = 0; // 正确答案个数
+            foreach ($options as $k=>$v){
+                $text = trim($v['text']);
+                if(!$text){
+                    $this->error('选项不能为空');
+                }
+                $options[$k]['text'] = $text;
+                if($v['answer'] == '1'){
+                    $correct++;
+                }
+            }
+            if($correct == 0){
+                $this->error('未设置正确答案');
+            }
+            if($correct > 1&& in_array($info['status'],[0,1]) &&$type == 0){
+                $this->error('单选题只能设置一个正确答案');
+            }
+
+            $oldoptions = json_decode($question['options'],true);
+            if(count($oldoptions) != count($options)){
+                $this->error('选项参数错误');
+            }
+
+            $data = array(
+                'title' => $title,
+                'options' => json_encode($options,JSON_UNESCAPED_UNICODE),
+                'update_time' => date('Y-m-d h:i:s')
+            );
+
+            if($info['status'] == 0){
+                $data['score'] = $score;
+                $data['type'] = $type;
+                $data['sort'] = $sort>0?$sort:0;
+            }
+
+            $res = db('article_question')->where('id',$id)->update($data);
+            if($res){
+                $this->success('操作成功');
+            }else{
+                $this->error('操作失败');
+            }
+        }else{
+            $this->assign('info',$info);
+            $question['options'] = json_decode($question['options'],true);
+            $this->assign('question',$question);
+            return $this->fetch();
+        }
+    }
+
+    public function article_rank($id){
+
+        $ret = db('article_record')
+            ->where('article_paper_id', $id)
+            ->field('article_record.*,max(SCORE) as SCORE')
+            ->group('user_id')
+            ->order(['score'=>'desc','create_time'=>'asc'])
+            ->select();
+        foreach ($ret as $key => $value) {
+            $ret[$key]['article_paper_name'] = db('article_paper')
+              ->where('id',$value['article_paper_id'])
+              ->value('title');
+            $ret[$key]['user_name'] = db('user')
+            ->where('id',$value['user_id'])
+            ->value('real_name');
+        }
+
+        $this->assign('list',$ret);
+        return $this->fetch();
+    }
+    public function article_log($id){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['article_paper_id','=',$id];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('article_record')->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $key => $value) {
+                $lists[$key]['article_paper_name'] = db('article_paper')
+                    ->where('id',$value['article_paper_id'])
+                    ->value('title');
+                $lists[$key]['user_name'] = db('user')
+                    ->where('id',$value['user_id'])
+                    ->value('real_name');
+            }
+            //数据返回
+            $totalCount = db('article_record')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $info = db('article_paper')
+                ->where('id',$id)
+                ->find();
+            $this->assign('m_name','['.$info['title'].']考试记录');
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+    public function log_info($id){
+
+        $list = $this->show_detail_info($id);
+        $info = $this->show_info($id);
+        $this->assign('list',$list);
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+    public function show_detail_info($id)
+    {
+        $ret = db('article_record_answer')
+            ->alias('a')
+            ->field('c.*,a.answer,b.user_id,b.article_paper_id')
+            ->join('article_record b','b.id = a.article_record_id')
+            ->join('article_question c','c.id = a.article_question_id')
+            ->where('a.article_record_id', $id)
+            ->order('c.sort', 'asc')
+            ->select();
+        foreach ($ret as $key => $value) {
+            $ret[$key]['article_paper_name'] = db('article_paper')
+                ->where('id',$value['article_paper_id'])
+                ->value('title');
+            $ret[$key]['user_name'] = db('user')
+                ->where('id',$value['user_id'])
+                ->value('real_name');
+            $ret[$key]['options'] = json_decode($value['options'],true);
+         }
+        return $ret;
+    }
+
+    public function show_info($id)
+    {
+        $ret = db('article_record')
+            ->where('id',$id)
+             ->find();
+        if ($ret) {
+            $ret['article_paper_name'] =
+                db('article_paper')
+                    ->where('id',$ret['article_paper_id'])
+                    ->value('title');
+            $ret['user_name'] =
+                db('user')
+                    ->where('id',$ret['user_id'])
+                    ->value('real_name');
+        }
+        return $ret;
+    }
+}

+ 212 - 0
application/admin/controller/ArticleWorker.php

@@ -0,0 +1,212 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class ArticleWorker extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            $map1 = [];
+            $map = [];
+            $b = input('begin','','trim');
+            $e = input('end','','trim');
+            $title = input('title','','trim');//护工
+            if($title) {
+                $map1[] = ['title', 'like', '%' . $title . '%'];
+            }
+            if($b && $e){
+                if($b <= $e){
+                    $b = date('Ymd',strtotime($b));
+                    $e = date('Ymd',strtotime($e));
+                    $map[] = ['create_yyyymmdd','>=',$b];
+                    $map[] = ['create_yyyymmdd','<=',$e];
+                }
+            }
+            if($b && $e==''){
+                $b = date('Ymd',strtotime($b));
+                $map[] = ['create_yyyymmdd','>=',$b];
+            }
+            if($b=='' && $e){
+                $e = date('Ymd',strtotime($e));
+                $map[] = ['create_yyyymmdd','<=',$e];
+            }
+            $cateId = input('roles_id','','trim');
+            if($cateId){
+                $map1['roles_id'] = $cateId;
+            }
+            //数据返回
+            $res = $this->show_all_page_search_worker($this->orgId,$map,$map1,$start,$length);
+            $totalPage = $res['total'];
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $res['count'];
+            $result['rows'] = $res['data'];
+            return json($result);
+        }else{
+            $this->assign('m_name','员工学习数据');
+            $cate  = Db::name('roles')
+                ->where('enable',1)
+                ->where('del',0)
+                ->where('del',0)
+                ->where('org_id',$this->orgId)
+                ->where('parent_id','>',0)
+                ->select();
+            $this->assign('cate',$cate);
+            return $this->fetch();
+        }
+    }
+
+    // 获取员工学习数据
+    public function show_all_page_search_worker($org, $map,$map1,$start,$length)
+    {
+        $pageSize = $length;
+        $total = 0;
+        $roles_ids = array();
+        if(isset($map1['roles_id'])){
+            $roles_ids[] = $map1['roles_id'];
+        }else{
+            $roles_ids = $this->get_worker_roles([],$org);
+
+        }
+        if($roles_ids){
+            $query = Db::name('user')
+                ->alias('a')
+                ->where('b.roles_id','in',$roles_ids);
+        }else{
+            $query = Db::name('user')
+                ->alias('a')
+                ->where('b.roles_id','=',-1);
+        }
+        $query->where('c.org_id',$org);
+        $query->where('a.del',0);
+        $query->join('user_roles b','user.id = b.user_id');
+        $query->join('user_org c','user.id = c.user_id');
+        $db = clone $query;
+        $count = $query->count();
+
+        $db1 = $db;
+        $total = ceil($count / $pageSize);
+        //查看当前的
+        $pageNumber = empty($pageNumber) ? 0 : $pageNumber;
+        //防止访问超过实际页数
+        $pageNumber = max(0, min($pageNumber, $total - 1));
+        $offset = $pageNumber * $pageSize;
+        $db1->limit($start, $length);
+        $db1->field('a.id as user_id,a.real_name,b.roles_id');
+        $list = $db1->select();
+        foreach ($list as $k=>$v){
+            $list[$k]['roles_name'] = Db::name('roles')
+            ->where('id',$v['roles_id'])
+            ->value('name');
+
+            $res = Db::name('record')
+                ->where($map)
+                ->where('user_id',$v['user_id'])
+                ->field('SUM(view) as views,SUM(time) as times')
+                ->group('user_id')
+                ->find();
+            $list[$k]['views'] = 0;
+            $list[$k]['times'] = 0;
+            if($res){
+                $list[$k]['views'] = $res['views'];
+                $list[$k]['times'] = $res['times'];
+            }
+        }
+
+        $ret = array('data' => $list, 'total' => $total, 'count' => $count);
+        return $ret;
+    }
+    public function get_worker_roles($roles,$org){
+        $roles_ids = array();
+        if (!$roles) {
+            $roles_ids = Db::name('roles')
+                ->where('enable',1)
+                ->where('del',0)
+                ->where('del',0)
+                ->where('org_id',$org)
+                ->where('parent_id','>',0)
+                ->column('id');
+        }else{
+            $roles_ids = $roles;
+        }
+        return $roles_ids;
+    }
+    public function workLog($id){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            $res = $this->show_all_page_search_worker_record($this->orgId,$id,$start,$length);
+            $totalPage = $res['total'];
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $res['count'];
+            $result['rows'] = $res['data'];
+            return json($result);
+        }else{
+            $user = Db::name('user')
+                ->where('id',$id)
+                ->value('real_name');
+            $this->assign('m_name','['.$user.']学习记录');
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+
+    // 员工学习数据 -- 查看
+    public function show_all_page_search_worker_record($org,$uid,$start,$length){
+        $pageSize = $length;
+        $total = 0;
+        $query = Db::name('record')
+            ->alias('a')
+           ->join('article b','b.id = a.article_id')
+           ->where('a.user_id',$uid)
+           ->where('a.org_id',$org)
+           ->group('a.article_id');
+
+        $db = clone $query;
+        $count = $query->count();
+
+        $this->db = $db;
+        $total = ceil($count / $pageSize);
+        //查看当前的
+        $pageNumber = empty($pageNumber) ? 0 : $pageNumber;
+        //防止访问超过实际页数
+        $pageNumber = max(0, min($pageNumber, $total - 1));
+        $offset = $pageNumber * $pageSize;
+        $this->db->field('b.title,b.limit,a.user_id,a.article_id,a.id');
+        $this->db->limit($start, $length);
+        $this->db->order('a.id', 'DESC');
+        $list = $this->db->select();
+        foreach ($list as $k=>$v){
+            $res =  Db::name('record')
+              ->where('user_id',$v['user_id'])
+            ->where('article_id',$v['article_id'])
+           ->field('SUM(time) as times')->find();
+            $list[$k]['times'] = 0;
+            if($res){
+                $list[$k]['times'] = $res['times'];
+            }
+            if($list[$k]['times'] >= $list[$k]['limit']){
+                $list[$k]['status'] = '达标';
+            }else{
+                $list[$k]['status'] = '未达标';
+            }
+        }
+        $ret = array('data' => $list, 'total' => $total, 'count' => $count);
+        return $ret;
+    }
+}

+ 121 - 0
application/admin/controller/AttendanceAddr.php

@@ -0,0 +1,121 @@
+<?php
+namespace app\admin\controller;
+
+class AttendanceAddr extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('attendance_addr')->limit($start,$length)->where($map)->order(['id'=>'desc'])->select();
+
+            //数据返回
+            $totalCount = db('attendance_addr')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            return $this->fetch();
+        }
+
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('AttendanceAddr')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('AttendanceAddr')->getError());
+            }
+        }else{
+            $title = '新增';
+            if($id){
+                $title = '编辑';
+                $info = db('attendance_addr')->where('id',$id)->find();
+                if($info['lat'] && $info['lng']){
+                    $info['latlng'] = $info['lat'].'-'.$info['lng'];
+                }
+                $this->assign('info',$info);
+            }
+
+            $this->assign('title',$title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('attendance_addr')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('attendance_addr')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    /**
+     * 排序
+     * @param int $id
+     * @param int $sort
+     */
+    public function changeSort($id=0,$sort=0){
+        if($id<0||$sort<0){
+            $this->error('参数错误');
+        }
+        $res = db('attendance_addr')->where('id',$id)->update(['sort'=>$sort]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+}

+ 153 - 0
application/admin/controller/AttendanceClass.php

@@ -0,0 +1,153 @@
+<?php
+namespace app\admin\controller;
+
+class AttendanceClass extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('attendance_class')->limit($start,$length)->where($map)->order(['id'=>'desc'])->select();
+            foreach ($lists as $k=>$v){
+                $content = json_decode($v['content'],true);
+                $dates = $content['dates'];
+
+                $times = [];
+                foreach ($dates as $kk=>$vv){
+                    $st = '';
+                    if($vv['snext'] == 1){
+                        $st .= '次日'.$vv['stime'];
+                    }else{
+                        $st .= $vv['stime'];
+                    }
+                    $st .= '-';
+                    if($vv['enext'] == 1){
+                        $st .= '次日'.$vv['etime'];
+                    }else{
+                        $st .= $vv['etime'];
+                    }
+                    $times[] = $st;
+                }
+
+                $lists[$k]['timeAll'] = implode(',',$times);
+            }
+            //数据返回
+            $totalCount = db('attendance_class')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            return $this->fetch();
+        }
+
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('AttendanceClass')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('AttendanceClass')->getError());
+            }
+        }else{
+            $title = '新增';
+            if($id){
+                $title = '编辑';
+                $info = db('attendance_class')->where('id',$id)->find();
+                $content = json_decode($info['content'],true);
+                $info['type'] = $content['type'];
+                $dates = $content['dates'];
+//                $timeOne = $timeTwo = $timeThree = '';
+//                $timeOne = $dates[0]['stime'].','.$dates[0]['etime'];
+//                if(!empty($dates[1])){
+//                    $timeTwo = $dates[1]['stime'].','.$dates[1]['etime'];
+//                }
+//                if(!empty($dates[2])){
+//                    $timeThree = $dates[2]['stime'].','.$dates[2]['etime'];
+//                }
+//
+//                $info['time1'] = $timeOne;
+//                $info['time2'] = $timeTwo;
+//                $info['time3'] = $timeThree;
+
+                $info['start1'] = $dates[0]['stime'];
+                $info['end1'] = $dates[0]['etime'];
+                if(!empty($dates[1])){
+                    $info['start2'] = $dates[1]['stime'];
+                    $info['end2'] = $dates[1]['etime'];
+                }
+                if(!empty($dates[2])){
+                    $info['start3'] = $dates[2]['stime'];
+                    $info['end3'] = $dates[2]['etime'];
+                }
+
+                $this->assign('info',$info);
+            }
+
+            $this->assign('title',$title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('attendance_class')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('attendance_class')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+
+}
+

+ 172 - 0
application/admin/controller/AttendanceGroup.php

@@ -0,0 +1,172 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class AttendanceGroup extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('attendance_group')->limit($start,$length)->where($map)->order(['id'=>'desc'])->select();
+            //数据返回
+            $totalCount = db('attendance_group')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            return $this->fetch();
+        }
+
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('AttendanceGroup')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('AttendanceGroup')->getError());
+            }
+        }else{
+            $title = '新增';
+            if($id){
+                $title = '编辑';
+            }
+            $info = model('AttendanceGroup')->info($id);
+            $this->assign('info',$info);
+            $users = model('WorkTypeMode')->getWorkerUserApp($this->orgId,-1);
+
+            $classes = db('attendance_class')->where('org_id',$this->orgId)->where('del',0)->select();
+            $addrs= db('attendance_addr')->where('org_id',$this->orgId)->where('del',0)->where('enable',1)->select();
+
+            $this->assign('users',$users);
+            $this->assign('classes',$classes);
+            $this->assign('addrs',$addrs);
+            $this->assign('title',$title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('attendance_group')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+    /*
+     * 排班*/
+    public function scheduling(){
+        $id = input('id',0);
+
+        $this->assign('id',$id);
+        return $this->fetch();
+    }
+
+
+    public function pbjson(){
+        $id = input('id');
+        $start = input('start');
+        $end = input('end');
+        $data = array();
+        if(!$start||!$end||$start>$end){
+            header('Content-Type:application/json; charset=utf-8');
+            exit(json_encode($data));
+        }
+        $start = date('Y-m-d',strtotime($start));
+        $end = date('Y-m-d',strtotime($end));
+
+        $list = db('attendance_group_class')
+            ->alias('gc')
+            ->join('attendance_class c','c.id = gc.class_id')
+            ->where('gc.day','>=',$start)
+            ->where('gc.day','<=',$end)
+            ->where('gc.group_id',$id)
+            ->field('c.name,gc.*')
+            ->select();
+
+        foreach ($list as $k=>$v){
+            $arr = array(
+                'taskid' => $v['id'],
+                'title' => $v['name'],
+                'status' => 1,
+                'start' => $v['day'].' 00:00:00',
+                'end' => $v['day'].' 23:59:59'
+            );
+            $arr['color'] = '#478fca';
+            $data[] = $arr;
+        }
+
+        header('Content-Type:application/json; charset=utf-8');
+        exit(json_encode($data));
+    }
+
+    public function addGroupClass(){
+        $gid = input('id');
+
+        if(request()->isPost()){
+            $res = model('AttendanceGroup')->groupUpdates();
+            if($res){
+                $this->success('操作成功',url('addGroupClass'));
+            }else{
+                $this->error(model('AttendanceGroup')->getError());
+            }
+        }else{
+            $start = input('start');
+            $start = date('Y-m-d',strtotime($start));
+            $info = model('AttendanceGroup')->showOne($gid);
+
+            $content = json_decode($info['content'],true);
+            $circle = $content['circle'];
+
+
+            $classids = $info['class_id']?explode(',',$info['class_id']):[];
+            $class = [];
+            if($classids){
+                $class = db('attendance_class')->whereIn('id',$classids)->select();
+            }
+            $this->assign('gid',$gid);
+            $this->assign('classList',$class);
+            $this->assign('weekList',$circle);
+            $this->assign('day',$start);
+            return $this->fetch();
+        }
+    }
+
+
+
+}
+

+ 152 - 0
application/admin/controller/AttendanceLeave.php

@@ -0,0 +1,152 @@
+<?php
+namespace app\admin\controller;
+
+class AttendanceLeave extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['u.real_name','like','%'.$title.'%'];
+            }
+            $status = input('status',0);
+            if($status){
+                $map[] = ['al.status','=',$status];
+            }
+            $map[] = ['al.org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('attendance_leave')
+                ->alias('al')
+                ->field('u.real_name,al.*')
+                ->join('user u','u.id=al.user_id')
+                ->limit($start,$length)
+                ->where($map)
+                ->order('al.id desc')
+                ->select();
+            foreach ($lists as $k=>$v){
+                $startday = date('Y-m-d',strtotime($v['start_time']));
+                if($startday.' 12:00:00' > $v['start_time']){
+                    $lists[$k]['start_time'] = $startday.' 上午';
+                } else {
+                    $lists[$k]['start_time'] = $startday.' 下午';
+                }
+                $endday = date('Y-m-d',strtotime($v['end_time']));
+                if($endday.' 12:00:00' > $v['end_time']){
+                    $lists[$k]['end_time'] = $endday.' 上午';
+                } else {
+                    $lists[$k]['end_time'] = $endday.' 下午';
+                }
+            }
+
+            //数据返回
+            $totalCount = db('attendance_leave')
+                ->alias('al')
+                ->join('user u','u.id=al.user_id')
+                ->where($map)
+                ->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('AttendanceLeave')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('AttendanceLeave')->getError());
+            }
+        }else{
+            $title = '新增';
+            if($id){
+                $title = '编辑';
+                $info = db('attendance_leave')->where('id',$id)->find();
+
+                //上下午
+                $start_time = date('H:i:s',strtotime($info['start_time']));
+
+                if($start_time < '12:00:00'){
+                    $info['apm1'] = 1;
+                }else{
+                    $info['apm1'] = 2;
+                }
+                //上下午
+                $end_time = date('H:i:s',strtotime($info['end_time']));
+                if($end_time < "12:00:00"){
+                    $info['apm2'] = 1;
+                }else{
+                    $info['apm2'] = 2;
+                }
+                $info['start_time'] = date('Y-m-d' ,strtotime($info['start_time']));
+                $info['end_time'] = date('Y-m-d' ,strtotime($info['end_time']));
+
+                $this->assign('info',$info);
+            }
+            $userList = model('WorkTypeMode')->getWorkerUserApp($this->orgId);
+
+            $this->assign('userList',$userList);
+            $this->assign('title',$title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('attendance_leave')->where('id',$id)->delete();
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    public function check(){
+        $id = input('id',0);
+        if($id < 1){
+            $this->error('参数错误');
+        }
+        if(request()->isPost()){
+             $data = [
+                 'status'=>input('status'),
+             ];
+            $res = db('attendance_leave')->where('id',$id)->update($data);
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error('操作失败');
+            }
+        }
+        $this->assign('id',$id);
+        return $this->fetch();
+    }
+
+
+}

+ 166 - 0
application/admin/controller/AttendanceMachine.php

@@ -0,0 +1,166 @@
+<?php
+namespace app\admin\controller;
+use think\Db;
+class AttendanceMachine extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $sn = input('sn','','trim');
+            if($sn){
+                $map[] = ['sn','like','%'.$sn.'%'];
+            }
+
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('attendance_machine')->limit($start,$length)->where($map)->order(['id'=>'desc'])->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['org_name'] = db('org')->where('id',$v['org_id'])->value('name');
+            }
+            //数据返回
+            $totalCount = db('attendance_machine')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $orgList = db('org')->where('del',0)->where('enable',1)->where('type',2)->select();
+            $this->assign('orgList',$orgList);
+            return $this->fetch();
+        }
+
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('AttendanceMachine')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('AttendanceMachine')->getError());
+            }
+        }else{
+            $title = '新增';
+            if($id){
+                $title = '编辑';
+                $info = db('attendance_machine')->where('id',$id)->find();
+
+                $this->assign('info',$info);
+            }
+            $orgList = db('org')->where('del',0)->where('enable',1)->where('type',2)->select();
+            $this->assign('orgList',$orgList);
+            $this->assign('title',$title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('attendance_machine')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    // 清空设备数据
+    public function clear(){
+        $id = input('id/d',0);
+        $info = model('AttendanceMachine')->info($id);
+        $title = "清除全部数据";
+        $command = 'C:${CmdID}:CLEAR DATA';
+        $ret = model('AttendanceMachineCmd')->add($id,$title,$command);
+        if($ret){
+            $this->success('命令添加成功');
+        }else{
+            $this->error('命令添加失败');
+        }
+    }
+
+    // 重新导入数据
+    public function reload(){
+        $id = input('id/d',0);
+        $info = model('AttendanceMachine')->info($id);
+        if($info['org_id'] > 0){
+            $users = db('user')
+                ->alias('u')
+                ->join('user_org uo','uo.user_id = u.id')
+                ->where('u.del',0)
+                ->where('u.enable',1)
+                ->where('uo.org_id',$info['org_id'])
+                ->where('u.kq_img','<>','')
+                ->field('u.id,u.kq_name as name,u.kq_img as img')
+                ->select();
+            $users = $users?$users:[];
+            foreach ($users as $k=>$v){
+                $users[$k]['card'] = 1000000000 + $v['id']; // 物业用户
+                $users[$k]['id'] = "WY{$v['id']}";
+            }
+        }
+
+        if(empty($users) && !isset($users)){
+            $this->error('当前项目无打卡人员');
+        }
+
+        Db::startTrans();
+        try{
+            // 先清空数据,再导入
+            $title = "清除全部数据";
+            $command = 'C:${CmdID}:CLEAR DATA';
+            $ret = model('AttendanceMachineCmd')->add($id,$title,$command);
+            if(!$ret){
+                exception('清空数据添加失败');
+            }
+
+            // 导入超级管理员
+            $admin = config('app.machine_admin');
+            $ret = model('AttendanceMachineCmd')->updateAdminInfo($info['id'],$admin['id'],$admin['name'],$admin['card']);
+            if(!$ret){
+                exception('操作失败');
+            }
+
+            foreach ($users as $k=>$v){
+                $ret = model('AttendanceMachineCmd')->updateUserInfo($info['id'],$v['id'],$v['name'],$v['card']);
+                if(!$ret){
+                    exception('操作失败');
+                }
+
+                $ret = model('AttendanceMachineCmd')->updateUserImg($info['id'],$v['id'],$v['name'],$v['img']);
+                if(!$ret){
+                    exception('操作失败');
+                }
+            }
+
+            Db::commit();
+            $this->success('命令添加成功');
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+    }
+
+
+}

+ 59 - 0
application/admin/controller/AttendanceMachineCmd.php

@@ -0,0 +1,59 @@
+<?php
+namespace app\admin\controller;
+use think\Db;
+
+class AttendanceMachineCmd extends Auth
+{
+
+    public function index()
+    {
+        if (request()->isAjax()) {
+            //分页参数
+            $length = input('rows', 10, 'intval');   //每页条数
+            $page = input('page', 1, 'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx', 'id', 'trim');      //排序列
+            $sort = input('sord', 'desc', 'trim');        //排序方式
+            $order = $sortRow . ' ' . $sort;
+
+            $sn = input('sn', '', 'trim');
+            if ($sn) {
+                $map[] = ['am.sn', '=',$sn];
+            }
+            $map[] = ['am.org_id', '=', $this->orgId];
+            $map[] = ['am.del', '=', 0];
+            $map = empty($map) ? true : $map;
+            //数据查询
+            $lists = db('attendance_machine_cmd')
+                ->alias('amc')
+                ->join('attendance_machine am','am.id = amc.machine_id')
+                ->field('amc.*,am.sn,am.org_id')
+                ->where($map)
+                ->limit($start, $length)
+                ->order('amc.id desc')
+                ->select();
+
+            foreach ($lists as $k => $v) {
+                $lists[$k]['org_name'] = db('org')->where('id', $v['org_id'])->value('name');
+            }
+            //数据返回
+            $totalCount = db('attendance_machine_cmd')
+                ->alias('amc')
+                ->join('attendance_machine am','am.id = amc.machine_id')                 ->where($map)
+                ->count();
+            $totalPage = ceil($totalCount / $length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        } else {
+            $orgList = db('org')->where('del', 0)->where('enable', 1)->where('type', 2)->select();
+            $this->assign('orgList', $orgList);
+            return $this->fetch();
+        }
+
+    }
+
+}

+ 772 - 0
application/admin/controller/AttendanceRecord.php

@@ -0,0 +1,772 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+
+class AttendanceRecord extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $star = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['u.real_name','like','%'.$title.'%'];
+            }
+            $start = input('start','','trim');
+            if($start){
+                $map[] = ['ar.create_time',',>=',$start.' 00:00:00'];
+            }
+            $end= input('end','','trim');
+            if($end){
+                $map[] = ['ar.create_time',',<=',$end.' 23:59:59'];
+            }
+            $map[] = ['u.del','=',0];
+            $map[] = ['ar.org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('attendance_record')
+                ->alias('ar')
+                ->field('u.real_name,ar.*')
+                ->leftJoin('user u','u.id=ar.user_id')
+                ->limit($star,$length)
+                ->where($map)
+                ->order(['ar.id'=>'desc'])
+                ->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['day'] = Db::name('attendance_user_class')->where('id',$v['user_class_id'])->value('day');
+
+                $lists[$k]['group_name'] = Db::name('attendance_group')
+                    ->alias('ag')
+                    ->join('attendance_user_class auc', 'auc.group_id = ag.id')
+                    ->where('auc.id',$v['user_class_id'])
+                    ->value('ag.name');
+
+            }
+
+            //数据返回
+            $totalCount = db('attendance_record')
+                ->alias('ar')
+                ->leftJoin('user u','u.id=ar.user_id')
+                ->where($map)
+                ->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    public function check(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['u.real_name','like','%'.$title.'%'];
+            }
+
+            $month = input('month','','trim');
+            if($month){
+                $map[] = ['auc.day','>=',$month.'-01'];
+                $map[] = ['auc.day','<=',$month.'-31'];
+            }else{
+                $smonth= date('Y-m').'-01';
+                $emonth = date('Y-m').'-31';
+                $map[] = ['auc.day','>=',$smonth];
+                $map[] = ['auc.day','<=',$emonth];
+            }
+
+            $map[] = ['u.del','=',0];
+            $map[] = ['auc.org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+
+            //数据查询
+            $lists = db('attendance_user_class')
+                ->alias('auc')
+                ->field('u.real_name,auc.*')
+                ->join('user u','u.id=auc.user_id')
+                ->limit($start,$length)
+                ->where($map)
+                ->order(['auc.id'=>'desc'])
+                ->select();
+
+            foreach ($lists as $k=>$v){
+                $record = db('attendance_record')
+                    ->where('user_class_id',$v['id'])
+                    ->order('create_time asc')
+                    ->select();
+
+                $record = $record?$record:[];
+
+                $lack = 0;
+                $early = 0;
+                $late = 0;
+                foreach ($record as $kk=>$vv){
+                    if($vv['effective'] == 1&&$vv['status'] == 1){
+                        $late++;
+                    }else if($vv['effective'] == 1&&$vv['status'] == 2){
+                        $early++;
+                    }
+                }
+                $dates = json_decode($v['content'],true);
+                $lists[$k]['content'] = $dates;
+                foreach ($dates as $kk=>$vv){
+                    $snr = $enr = [];
+                    if($record){
+                        $f1 = 0;
+                        $f2 = 0;
+                        foreach ($record as $kkk=>$vvv){
+                            if($vvv['kq_time'] == $vv['stime']){
+                                $snr[] = $vvv;
+                                $f1 = 1;
+                            }
+                            if($vvv['kq_time'] == $vv['etime']){
+                                $enr[] = $vvv;
+                                $f2 = 1;
+                            }
+                        }
+                        if(!$f1){
+                            $lack++;
+                        }
+                        if(!$f2){
+                            $lack++;
+                        }
+                    }else{
+                        $lack += 2;
+                    }
+                    $dates[$kk]['slist'] = $snr;
+                    $dates[$kk]['elist'] = $enr;
+                }
+
+                $lists[$k]['lack'] = $lack;     //缺卡次数
+                $lists[$k]['early'] = $early;      //早退
+                $lists[$k]['late'] = $late;       //迟到
+            }
+
+            //数据返回
+            $totalCount = db('attendance_user_class')
+                ->alias('auc')
+                ->field('u.real_name,auc.*')
+                ->join('user u','u.id=auc.user_id')
+                ->where($map)
+                ->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('month',date('Y-m'));
+            return $this->fetch();
+        }
+    }
+
+    public function checkDetails(){
+        $id = input('id',0);
+        if($id < 1){
+            $this->error('参数错误');
+        }
+
+        $info = db('attendance_user_class')->where('id',$id)->find();
+
+        $record = db('attendance_record')->where('user_class_id',$id)->order('create_time asc')->select();
+        $record = $record?$record:[];
+
+        $dates = json_decode($info['content'],true);
+        foreach ($dates as $kk=>$vv){
+            $snr = $enr = [];
+            if($record){
+                foreach ($record as $kkk=>$vvv){
+                    if($vvv['kq_time'] == $vv['stime']){
+                        $snr[] = $vvv;
+                    }
+                    if($vvv['kq_time'] == $vv['etime']){
+                        $enr[] = $vvv;
+                    }
+                }
+            }
+            $dates[$kk]['slist'] = $snr;
+            $dates[$kk]['elist'] = $enr;
+        }
+
+        $info['content'] = $dates;
+
+        //获取今日请假记录
+        $leave = db('attendance_leave')
+            ->where('status',1)
+            ->where('user_id',$info['user_id'])
+            ->where('start_time','<=',$info['day'].' 23:59:59')
+            ->where('end_time','>=',$info['day'].' 00:00:00')
+            ->select();
+        foreach ($leave as $k=>$v){
+            if($v['leave_type'] == 1){
+                $leave[$k]['leavetype_name'] = '事假';
+            }
+            if($v['leave_type'] == 2){
+                $leave[$k]['leavetype_name'] = '病假';
+            }
+            if($v['leave_type'] == 3){
+                $leave[$k]['leavetype_name'] = '年假';
+            }
+            if($v['leave_type'] == 4){
+                $leave[$k]['leavetype_name'] = '婚假';
+            }
+            if($v['leave_type'] == 5){
+                $leave[$k]['leavetype_name'] = '婚假';
+            }
+            if($v['leave_type'] == 6){
+                $leave[$k]['leavetype_name'] = '丧假';
+            }
+        }
+
+        $info['leave'] = $leave;
+        $this->assign('info',$info);
+        return $this->fetch();
+
+    }
+
+    // 改变打卡状态
+    public function changeAttendance(){
+
+        $data = [
+            'type' => input('type'),
+            'time' => input('time'),
+            'min' => input('min'),
+            'id' => input('id'),
+            'cate' => input('cate'),
+            'status' => input('status')
+        ];
+
+        if($data['type'] == 2 && $data['min'] <= 0){
+            $this->error('分钟数不能为0');
+        }
+        if(!$data['time']){
+            $this->error('参数错误1');
+        }
+        $info = db('attendance_user_class')->where('id',$data['id'])->find();
+
+        if(!$info){
+            $this->error('参数错误2');
+        }
+
+        if($data['cate'] == 1){ // 上班(正常上班/下班的记录是不可修改的)
+            $ret = db('attendance_record')
+                ->where('user_id',$info['user_id'])
+                ->where('create_time',$data['time'])
+                ->where('cate',1)
+                ->where('effective',1)
+                ->where('status',0)
+                ->find();;
+
+            if($ret){
+                $this->error('上班打卡为正常状态,不能修改');
+            }
+        }else if($data['cate'] == 2){// 下班
+            $ret = db('attendance_record')
+                ->where('user_id',$info['user_id'])
+                ->where('user_class_id',$data['id'])
+                ->where('create_time',$data['time'])
+                ->where('cate',2)
+                ->where('effective',1)
+                ->where('status',0)
+                ->find();
+            if($ret){
+                $this->error('下班打卡为正常状态,不能修改');
+            }
+        }
+        if($data['type'] == 1){
+            $data['min'] = 0;
+        }
+
+        $signdate = $data['time'];
+        $status = 0;
+        $result = '管理员修改为:正常';
+        if($data['cate'] == 1 && $data['type'] == 2){ //上班
+            $signdate = date('Y-m-d H:i:s',strtotime($data['time']) + $data['min']*60);
+            $status = 1;
+            $result = '管理员修改为:迟到';
+        }else if($data['cate'] == 2 && $data['type'] == 2){
+            $signdate = date('Y-m-d H:i:s',strtotime($data['time']) - $data['min']*60);
+            $status = 2;
+            $result = '管理员修改为:早退';
+        }
+
+        Db::startTrans();
+        try{
+                db('attendance_record')
+                ->where('user_class_id',$data['id'])
+                ->where('user_id',$info['user_id'])
+                ->where('kq_time',$data['time'])
+                ->update(['effective' => 0,'result'=>"打卡无效:此记录已被更新"]);
+
+            $rdata = [
+                'kq_time' => $data['time'],
+                'user_id' => $info['user_id'],
+                'org_id' => $info['org_id'],
+                'type' => 4,
+                'from' => '管理员修改',
+                'result' => $result,
+                'create_time' => $signdate,
+                'user_class_id' => $data['id'],
+                'effective' => 1,
+                'status' => $status,
+                'cate' => $data['cate'],
+                'duration' => $data['min']*60
+            ];
+            $add = db('attendance_record')->insert($rdata);
+
+            if(!$add){
+                exception('操作失败');
+            }
+
+            $dates = json_decode($info['content'],true);
+            foreach ($dates as $k=>$v){
+                if($rdata['cate'] == 1 && $v['stime'] == $rdata['kq_time']){
+                    $dates[$k]['ssign'] = $rdata['create_time'];
+                }else if($rdata['cate'] == 2 && $v['etime'] == $rdata['kq_time']){
+                    $dates[$k]['esign'] = $rdata['create_time'];
+                }
+            }
+            $save = db('attendance_user_class')->where('id',$info['id'])->update(['content' => json_encode($dates)]);
+
+            if(!$save){
+                exception('操作失败');
+            }
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+    public function results(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $month = input('month','','trim');
+
+            if($month){
+                $map[] = ['auc.day','>=',$month.'-01'];
+                $map[] = ['auc.day','<=',$month.'-31'];
+            }else{
+                $smonth= date('Y-m').'-01';
+                $emonth = date('Y-m').'-31';
+                $map[] = ['auc.day','>=',$smonth];
+                $map[] = ['auc.day','<=',$emonth];
+            }
+            $start_time = $month.'-01';
+            $end_time = $month.'-31';
+
+            $map[] = ['u.del','=',0];
+            $map[] = ['u.enable','=',1];
+            $map[] = ['auc.org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('attendance_user_class')
+                ->alias('auc')
+                ->field('auc.*,count(*) as days,u.real_name')
+                ->join('user u','u.id=auc.user_id')
+                ->limit($start,$length)
+                ->where($map)
+                ->order('auc.user_id asc')
+                ->group('auc.user_id')
+                ->select();
+
+            foreach ($lists as $k=>$v){
+                $duration = 0;
+                $uclist = Db::name('attendance_user_class')
+                    ->field('content')
+                    ->where('org_id',cur_org_id())
+                    ->where('day','>=',$start_time)
+                    ->where('day','<=',$end_time)
+                    ->where('user_id',$v['user_id'])
+                    ->select();
+                foreach ($uclist as $key=>$val){
+                    $dates = json_decode($val['content'],true);
+                    foreach ($dates as $kk=>$vv){
+                        if(!empty($vv['ssgin']) && !empty($vv['esign'])){
+                            $duration += strtotime($vv['esign']) - strtotime($vv['ssgin']);
+                        }
+                    }
+                }
+                $lists[$k]['duration'] = round($duration/60);
+
+                $work = Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->field('auc.day')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->group('auc.day')
+                    ->select();
+                $lists[$k]['work'] = $work ? count($work): 0; // 出勤天数
+
+                $bk = Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.type',2)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->select();
+
+                $lists[$k]['bk'] = $bk ? count($bk) : 0; // 补卡次数
+
+                $late = Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.status',1)
+                    ->where('ar.effective',1)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->select();
+
+                $lists[$k]['late'] = $late ? count($late) :0; // 迟到次数
+
+                $lated = Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.status',1)
+                    ->where('ar.effective',1)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->sum('ar.duration');
+
+                $lists[$k]['late_duration'] = $lated?round($lated['duration']/60):0; // 迟到时长
+
+                $early = Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.status',2)
+                    ->where('ar.effective',1)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->select();
+
+                $lists[$k]['early'] = $early ? count($early) :0; // 早退次数
+
+                $earlyd =  Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.status',2)
+                    ->where('ar.effective',1)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->sum('ar.duration');
+
+                $lists[$k]['early_duration'] = $earlyd?round($earlyd['duration']/60):0; // 早退时长
+
+                // 请假天数
+                $leave = Db::name('attendance_leave')
+                    ->where('user_id',$v['user_id'])
+                    ->where('status',1)
+                    ->where('start_time','<=',$end_time.' 23:59:59')
+                    ->where('end_time','>=',$start_time.' 00:00:00')
+                    ->sum('cur_days');
+
+                $lists[$k]['leave'] = $leave ? round($leave['cur_days'],1): 0; // 请假天数
+            }
+
+            //数据返回
+            $totalCount = Db::name('attendance_user_class')
+                ->alias('auc')
+                ->field('auc.*,count(*) as days,u.real_name')
+                ->join('user u','u.id=auc.user_id')
+                ->where($map)
+                ->group('auc.user_id')
+                ->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('month',date('Y-m'));
+            return $this->fetch();
+        }
+    }
+
+    //excel导出
+    public function export() {
+
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+        if (request()->isGet()) {
+            $month = input('month','','trim');
+
+            if($month){
+                $map[] = ['auc.day','>=',$month.'-01'];
+                $map[] = ['auc.day','<=',$month.'-31'];
+            }else{
+                $smonth= date('Y-m').'-01';
+                $emonth = date('Y-m').'-31';
+                $map[] = ['auc.day','>=',$smonth];
+                $map[] = ['auc.day','<=',$emonth];
+            }
+            $start_time = $month.'-01';
+            $end_time = $month.'-31';
+
+            $map[] = ['u.del','=',0];
+            $map[] = ['u.enable','=',1];
+            $map[] = ['auc.org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('attendance_user_class')
+                ->alias('auc')
+                ->field('auc.*,count(*) as days,u.real_name')
+                ->join('user u','u.id=auc.user_id')
+                ->where($map)
+                ->order('auc.user_id asc')
+                ->group('auc.user_id')
+                ->select();
+
+            foreach ($lists as $k=>$v){
+                $duration = 0;
+                $uclist = Db::name('attendance_user_class')
+                    ->field('content')
+                    ->where('org_id',cur_org_id())
+                    ->where('day','>=',$start_time)
+                    ->where('day','<=',$end_time)
+                    ->where('user_id',$v['user_id'])
+                    ->select();
+                foreach ($uclist as $key=>$val){
+                    $dates = json_decode($val['content'],true);
+                    foreach ($dates as $kk=>$vv){
+                        if(!empty($vv['ssgin']) && !empty($vv['esign'])){
+                            $duration += strtotime($vv['esign']) - strtotime($vv['ssgin']);
+                        }
+                    }
+                }
+                $lists[$k]['duration'] = round($duration/60);
+
+                $work = Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->field('auc.day')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->group('auc.day')
+                    ->select();
+                $lists[$k]['work'] = $work ? count($work): 0; // 出勤天数
+
+                $bk = Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.type',2)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->select();
+
+                $lists[$k]['bk'] = $bk ? count($bk) : 0; // 补卡次数
+
+                $late = Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.status',1)
+                    ->where('ar.effective',1)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->select();
+
+                $lists[$k]['late'] = $late ? count($late) :0; // 迟到次数
+
+                $lated = Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.status',1)
+                    ->where('ar.effective',1)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->sum('ar.duration');
+
+                $lists[$k]['late_duration'] = $lated?round($lated['duration']/60):0; // 迟到时长
+
+                $early = Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.status',2)
+                    ->where('ar.effective',1)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->select();
+
+                $lists[$k]['early'] = $early ? count($early) :0; // 早退次数
+
+                $earlyd =  Db::name('attendance_record')
+                    ->alias('ar')
+                    ->join('attendance_user_class auc','ar.user_class_id = auc.id')
+                    ->where('auc.org_id',cur_org_id())
+                    ->where('auc.day','>=',$start_time)
+                    ->where('auc.day','<=',$end_time)
+                    ->where('ar.status',2)
+                    ->where('ar.effective',1)
+                    ->where('ar.user_id',$v['user_id'])
+                    ->sum('ar.duration');
+
+                $lists[$k]['early_duration'] = $earlyd?round($earlyd['duration']/60):0; // 早退时长
+
+                // 请假天数
+                $leave = Db::name('attendance_leave')
+                    ->where('user_id',$v['user_id'])
+                    ->where('status',1)
+                    ->where('start_time','<=',$end_time.' 23:59:59')
+                    ->where('end_time','>=',$start_time.' 00:00:00')
+                    ->sum('cur_days');
+
+                $lists[$k]['leave'] = $leave ? round($leave['cur_days'],1): 0; // 请假天数
+            }
+            //实例化PHPExcel类
+            $objPHPExcel =new \PHPExcel();
+            //激活当前的sheet表
+            $objPHPExcel->setActiveSheetIndex(0);
+            //设置表格头(即excel表格的第一行)
+            $objPHPExcel->setActiveSheetIndex(0)
+                ->setCellValue('A1', '姓名')
+                ->setCellValue('B1', '应出勤天数')
+                ->setCellValue('C1', '出勤天数')
+                ->setCellValue('D1', '工作时长')
+                ->setCellValue('E1', '迟到次数')
+                ->setCellValue('F1', '迟到时长')
+                ->setCellValue('G1', '早退次数')
+                ->setCellValue('H1', '早退时长')
+                ->setCellValue('I1', '补卡次数')
+                ->setCellValue('J1', '请假');
+            // 设置表格头水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('I1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('J1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置列水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('I')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('J')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置单元格宽度
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(30);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(30);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(30);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(30);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('I')->setWidth(30);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('J')->setWidth(30);
+            //循环刚取出来的数组,将数据逐一添加到excel表格。
+            for ($i = 0; $i < count($lists); $i++) {
+                $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['real_name']);
+                $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['days']);
+                $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['work']);
+                $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['duration']);
+                $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['late']);
+                $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['late_duration']);
+                $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['early']);
+                $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['early_duration']);
+                $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['bk']);
+                $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['leave']);
+
+            }
+            //设置保存的Excel表格名称
+            $filename = '考勤报表_' . date('YmdHis', time()) . '.xls';
+            //设置当前激活的sheet表格名称
+            $objPHPExcel->getActiveSheet()->setTitle('考勤报表');
+            //设置浏览器窗口下载表格
+            ob_end_clean();
+            header("Content-Type: application/force-download");
+            header("Content-Type: application/octet-stream");
+            header("Content-Type: application/download");
+            header('Content-Disposition:inline;filename="' . $filename);
+            //生成excel文件
+            $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+            //下载文件在浏览器窗口
+            return $objWriter->save('php://output');
+        }
+
+    }
+
+
+
+}

+ 51 - 0
application/admin/controller/Auth.php

@@ -0,0 +1,51 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class Auth extends Base
+{
+    public $userId;
+    public $orgId;
+    public $rolesId;
+    protected function initialize()
+    {
+        if(!is_login()){
+            if(request()->isAjax()){
+                $this->error('未登录,请先登录');
+            }else{
+                $this->redirect(url('common/login'));
+            }
+        }
+        $this->userId = is_login();
+        $this->orgId = cur_org_id();
+
+        $user = session('user_auth');
+        $this->rolesId = !empty($user)&&isset($user['rolesId'])?$user['rolesId']:0;
+        $this->assign('rolesId',$this->rolesId);
+
+        // 检查是否有紧急事件
+        $info = Db::name('burst_record')
+            ->where('user_id',$this->userId)
+            ->where('status',1)
+            ->where('del',0)
+            ->find();
+        if($info){
+            $this->redirect(url('Bursting/index'));
+        }
+
+        parent::initialize();
+
+    }
+
+    public function getTableField($table,$where,$field){
+
+        $val = Db::name($table)
+            ->where($where)
+            ->value($field);
+        return $val;
+    }
+
+
+
+}

+ 91 - 0
application/admin/controller/Balance.php

@@ -0,0 +1,91 @@
+<?php
+
+namespace app\admin\controller;
+use app\common\model\WorkerBalance;
+use think\App;
+use think\Db;
+use think\Exception;
+
+class Balance extends Auth {
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model = new \app\common\model\Worker();
+    }
+    public function index() {
+        if (request()->isAjax()) {
+            //分页参数
+            $length = input('rows', 10, 'intval');   //每页条数
+            $page = input('page', 1, 'intval');      //第几页
+            $title = input('title', '', 'trim');
+            $map = [];
+            if ($title) {
+                $map['name'] = $title;
+            }
+            $recommend = input('recommend', '', 'trim');
+            if ($recommend != '') {
+                $map['recommend'] = $recommend;
+            }
+            $enable = input('enable', '', 'trim');
+            if ($enable != '') {
+                $map['enable'] = $enable;
+            }
+            $gender = input('gender', '', 'trim');
+            if ($gender != '') {
+                $map['gender'] = $gender;
+            }
+            $map['balance'] = 1;
+            //数据查询
+            $result = $this->model->lists($this->orgId, $map, $page, $length);
+            return json($result);
+        }
+        else {
+            return $this->fetch();
+        }
+    }
+
+
+
+    public function js(){
+        $data = request()->post();
+        $ids = $data['ids'];
+        $balanceModel = new WorkerBalance();
+        $model = new \app\common\model\Worker();
+        $succ = 0;
+        $err = 0;
+        $er = [];
+        $logId = Db::name('settlement_log')
+            ->insertGetId([
+                'user_id'=>$this->userId,
+                'org_id'=>$this->orgId,
+                'create_time'=>date('Y-m-d H:i:s'),
+            ]);
+        if(!$logId){
+            $this->error('结算记录保存失败');
+        }
+        foreach ($ids as $k=>$id){
+            $user_id = Db::name('worker')
+                ->where('id',$id)
+                ->value('user_id');
+            $info = $model->getUserInfo($user_id);
+            $res = $balanceModel->saveWorkerBalance($this->orgId,
+                -$info['balance'],$this->userId,$id,2,'',0,$logId);
+            if($res){
+                $succ++;
+            }else{
+                $err++;
+                $er[] = $info['real_name'].':'.$balanceModel->getError();
+
+            }
+        }
+        if(empty($er)){
+            $msg = '成功:'.$succ.'失败:'.$err;
+            $a = ['code'=>0,'msg'=>$msg];
+        }else{
+            $msg = '成功:'.$succ.'失败:'.$err.' 失败原因:'.json_encode($er,JSON_UNESCAPED_UNICODE);
+            $a = ['code'=>1,'msg'=>$msg];
+        }
+        $this->success('','',$a);
+
+    }
+
+}

+ 127 - 0
application/admin/controller/Banner.php

@@ -0,0 +1,127 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+use think\Exception;
+
+class Banner extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('banner')->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db('banner')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('Banner')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('Banner')->getError());
+            }
+        }else{
+            if($id){
+                $info = db('banner')->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('banner')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('banner')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function batchSort(){
+        $data = input('data','','trim');
+        if(!$data){
+            $this->error('参数错误');
+        }
+        $data = json_decode($data,true);
+        if(!$data){
+            $this->error('参数错误');
+        }
+
+        Db::startTrans();
+        try{
+            foreach ($data as $k=>$v){
+                Db::name('banner')->where('id',$v['id'])->setField('sort',$v['sort']);
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+
+}

+ 18 - 0
application/admin/controller/Base.php

@@ -0,0 +1,18 @@
+<?php
+namespace app\admin\controller;
+
+use think\Controller;
+use think\Db;
+
+class Base extends Controller
+{
+    protected function initialize()
+    {
+        parent::initialize();
+
+    }
+
+
+
+
+}

+ 173 - 0
application/admin/controller/Bracelet.php

@@ -0,0 +1,173 @@
+<?php
+namespace app\admin\controller;
+
+use app\watch\controller\Api;
+use think\App;
+use think\Db;
+use think\Exception;
+
+class Bracelet extends Auth
+{
+    protected $sex = [
+        '未知',
+        '男',
+        '女'
+    ];
+
+    public function __construct(App $app) {
+        parent::__construct($app);
+        $this->api=new Api($this->app);
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('name','','trim');
+            if($title){
+                $map[] = ['nickname','like','%'.$title.'%'];
+            }
+
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('bracelet_device')
+                ->where($map)->limit($start,$length)->order($order)
+                ->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['sex'] =$v['sex']==0?'位置':($v['sex']==1?'男':'女');
+                $watch = new Api($this->app);
+                $info = $watch->getDevice($v['imei']);
+                if(!$info['success']) $this->error($v['imei'].$info['error_desc']);
+                $lists[$k]['online'] = $info['obj']['online']?'在线':'离线';
+                $lists[$k]['jk'] = '';
+                $lists[$k]['icon'] = '';
+
+            }
+            //数据返回
+            $totalCount = Db::name('bracelet_device')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0)
+    {
+        if (request()->isPost()) {
+            $model = new \app\common\model\Bracelet();
+            $res = $model->saves();
+            if ($res) {
+                $this->success('操作成功', url('index'));
+            } else {
+                $this->error($model->getError());
+            }
+        } else {
+            $meta_title = '新增设备';
+            if ($id) {
+                $info = Db::name('bracelet_device')
+                    ->where('id', $id)->find();
+
+                $this->assign('info', $info);
+                $meta_title = '编辑设备';
+            }
+
+
+            $this->assign('sex', $this->sex);
+
+            $this->assign('meta_title', $meta_title);
+            return $this->fetch();
+        }
+
+    }
+
+    /**
+     * 删除
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('bracelet_device')->where('id',$id)->update([
+            'del'=>1,
+            'del_time'=>date('Y-m-d H:i:s')
+        ]);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+    /**
+     * 设置亲情通话
+     *
+     * @author wst
+     * @date   2021/6/1 17:22
+     */
+    public function number($id=0){
+
+        if($params = request()->post()){
+            $seqId = $params['seqId'];
+            $id = $params['id'];
+            unset($params['id'],$params['seqId']);
+            $res = $this->api->deviceSosNumbers($id,$seqId,$params);
+            if($res['success']){
+                $this->success('操作成功');
+            }
+            $this->error($res['error_desc']);
+
+        }else{
+            $meta_title = '亲情号码';
+            $detail = $this->api->getDevice($id);
+            if(!$detail['success']) $this->error($detail['error_desc']);
+            $info = $detail['obj']['sos_numbers'];
+            $this->assign('info',$info);
+            $this->assign('id',$id);
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+    /**
+     * 编辑单条亲情号码
+     *
+     * @author wst
+     * @date   2021/6/1 17:44
+     */
+    public function editNumber(){
+        $params = request()->get();
+        $this->assign('info',$params);
+        return $this->fetch();
+
+    }
+    /**
+     * 清空单条亲情号码
+     *
+     * @author wst
+     * @date   2021/6/1 17:44
+     */
+    public function clearNumber(){
+        $params = request()->get();
+        $res = $this->api->deviceSosNumbers($params['id'],$params['seqId'],['clear'=>1]);
+        if($res['success']){
+            $this->success('操作成功');
+        }
+        $this->error($res['error_desc']);
+
+    }
+
+}

+ 191 - 0
application/admin/controller/Burst.php

@@ -0,0 +1,191 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class Burst extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('burst')->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db('burst')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('Burst')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('Burst')->getError());
+            }
+        }else{
+            $meta_title = '新增';
+            if($id){
+                $info = db('burst')->where('id',$id)->find();
+                $this->assign('info',$info);
+                $meta_title = '编辑';
+            }
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('burst')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('burst')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function start($id = 0){
+        $info = Db::name('burst')->where('id',$id)->where('del',0)->find();
+        if(!$info){
+            $this->error('数据不存在');
+        }
+        // 检查是否有未完成的任务
+        $ret = Db::name('burst_record')
+            ->where('user_id',$this->userId)
+            ->where('status',1)
+            ->where('del',0)
+            ->find();
+        if($ret){
+            $this->error('你还有进行中的事件未结束');
+        }
+        $content = json_decode($info['content'],true);
+        $content[0]['status'] = 1;
+        $data = [
+            'burst_id' => $info['id'],
+            'user_id' => $this->userId,
+            'org_id' => $this->orgId,
+            'content' => json_encode($content),
+            'status' => 1,
+            'create_time' => date('Y-m-d H:i:s')
+        ];
+        $res = Db::name('burst_record')->insertGetId($data);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    //显示列表
+    public function record()
+    {
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','br.id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['b.title','like','%'.$title.'%'];
+            }
+            $title = input('uname','','trim');
+            if($title){
+                $map[] = ['u.real_name','like','%'.$title.'%'];
+            }
+            $enable = input('status','','trim');
+            if($enable != ''){
+                $map[] = ['br.status','=',$enable];
+            }
+
+            $map[] = ['br.del','=',0];
+            $map[] = ['br.org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('burst_record')
+                ->alias('br')
+                ->join('burst b','b.id = br.burst_id')
+                ->join('user u','u.id = br.user_id')
+                ->field('br.*,u.real_name,b.title')
+                ->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = Db::name('burst_record')
+                ->alias('br')
+                ->join('burst b','b.id = br.burst_id')
+                ->join('user u','u.id = br.user_id')
+                ->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+
+}

+ 166 - 0
application/admin/controller/Bursting.php

@@ -0,0 +1,166 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class Bursting extends Base
+{
+    protected $userId = 0;
+    protected function initialize()
+    {
+        parent::initialize();
+
+        if (!is_login()) {
+            $this->redirect(url('Common/logout'));
+        }
+        $this->userId = is_login();
+    }
+
+    public function index()
+    {
+        $info = Db::name('burst_record')
+            ->where('user_id',$this->userId)
+            ->where('status',1)
+            ->where('del',0)
+            ->find();
+        if(!$info){
+            $this->redirect(url('Index/index'));
+        }
+        $binfo =  Db::name('burst')
+            ->where('id',$info['burst_id'])
+            ->find();
+        $info['title'] = $binfo['title'];
+        $this->changeStatus($info);
+
+        $info = Db::name('burst_record')
+            ->where('id',$info['id'])
+            ->where('del',0)
+            ->find();
+        $info['title'] = $binfo['title'];
+
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+    public function detail()
+    {
+        $id = input('id');
+        $info = Db::name('burst_record')
+            ->where('id',$id)
+            ->where('del',0)
+            ->find();
+        if(!$info){
+            $this->error('数据不存在');
+            exit;
+        }
+        $binfo =  Db::name('burst')
+            ->where('id',$info['burst_id'])
+            ->find();
+        $info['title'] = $binfo['title'];
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+    // 更改步骤状态
+    private function changeStatus($info){
+        if($info['status'] == 2 || $info['status'] == 3){
+            return $info;
+        }
+        $curTime = time();
+        $ctime = ($curTime - strtotime($info['create_time']))/60;
+        $content = json_decode($info['content'],true);
+        $t = 0;
+        // 查状态
+        foreach ($content as $k=>$v){
+            $t1 = $t;
+            $t = $t + $v['time'];
+
+            $s = 0; // 都已完成
+            foreach ($v['options'] as $kk=>$vv){
+                if($vv['status'] == 0){
+                    $s = 1;
+                }
+            }
+
+            if($v['status'] == 0||$v['status'] == 1){
+                if($ctime < $t && $ctime >= $t1){
+                    $content[$k]['status'] = 1;
+                    if($s == 0){
+                        $content[$k]['status'] = 2;
+                        if($k+1 < count($content)){
+                            $content[$k+1]['status'] = 1;
+                        }
+                    }
+                }else if($ctime >= $t){
+                    $content[$k]['status'] = 2;
+                }
+            }
+        }
+
+        $status = $info['status'];
+        if($ctime < $t){
+            $flag = 0;
+            foreach ($content as $k=>$v){
+                foreach ($v['options'] as $kk=>$vv){
+                    if($vv['status'] == 0){
+                        $flag = 1;
+                        break;
+                    }
+                }
+            }
+            if($flag == 0){
+                $status = 2;
+            }
+        }else{
+            $status = 3;
+        }
+
+//        if($content[count($content) - 1]['status'] == 2 && $ctime >= $t){
+//            $status = 3;
+//        } else if ($content[count($content) - 1]['status'] == 2 && $ctime < $t){
+//            $status = 2;
+//        }
+
+        $content = json_encode($content);
+        Db::name('burst_record')->where('id',$info['id'])->update(['status'=>$status,'content' => $content,'update_time'=>date('Y-m-d H:i:s')]);
+        $info['content'] = $content;
+        return $info;
+    }
+
+    public function finish(){
+        $id = input('id/d',0);
+        $index = input('index/d',0);
+        $index2 = input('index2/d',0);
+        $info = Db::name('burst_record')
+            ->where('id',$id)
+            ->where('del',0)
+            ->find();
+        if(!$info){
+            $this->error('数据不存在');
+        }
+        if($info['status'] != 1){
+            $this->error('无权限操作');
+        }
+        $content = json_decode($info['content'],true);
+        foreach ($content as $k=>$v){
+            if($k == $index){
+                foreach ($v['options'] as $kk => $vv){
+                    if($kk == $index2){
+                        $content[$k]['options'][$kk]['status'] = 1;
+                    }
+                }
+            }
+        }
+        $content = json_encode($content);
+        $ret = Db::name('burst_record')->where('id',$id)->update(['content' => $content,'update_time'=>date('Y-m-d H:i:s')]);
+        if($ret){
+            $info['content'] = $content;
+            $this->changeStatus($info);
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+}

+ 62 - 0
application/admin/controller/Bushu.php

@@ -0,0 +1,62 @@
+<?php
+namespace app\admin\controller;
+use app\watch\controller\Api;
+use think\App;
+use think\facade\Db;
+
+class Bushu extends Auth
+{
+    public function __construct(App $app) {
+        parent::__construct($app);
+        $this->api = new Api($this->app);
+    }
+    public function index(){
+
+        $id = request()->get('id');
+        if(empty($id)){
+            $d = $this->api->community(1,10);
+            if(!isset($d['objs'][0])) $this->error('没有添加设备');
+            $id = isset($d['objs'][0]['_id'])?$d['objs'][0]['_id']:'';
+        }
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $date = input('riqi','');
+            $imei = input('imei','');
+            $p = ['rows_per_page'=>$length,'page'=>$page];
+
+            if($date){
+               $p['time_begin'] = date('Ymd',strtotime($date));
+            }
+            if(!empty($imei)){
+                $id = $imei;
+            }
+            $list = $this->api->devicePedometerData($id,$p);
+            if(!$list['success']){
+                $this->error($list['error_desc']);
+            }
+            $data = [];
+            foreach ($list['objs'] as $k=>$v){
+                $a = [
+                    'id'=>$k+1,
+                    'heartrate'=>$v['heartrate'],
+                    'created_at'=>nDate($v['created_at']['$date']),
+                ];
+                $data[$k] = $a;
+            }
+            $result['page'] = $page;
+            $result['total'] = $list['page']['page_count'];
+            $result['records'] = $list['page']['total'];
+            $result['rows'] = $data;
+            return json($result);
+        }else{
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+
+
+
+
+}

+ 318 - 0
application/admin/controller/Car.php

@@ -0,0 +1,318 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class Car extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\Car();
+        $this->table= 'car_view';
+
+    }
+    public function index($import_id=0){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $plate_num = input('plate_num','','trim');
+            if($plate_num){
+                $map[] = ['plate_num','like','%'.$plate_num.'%'];
+            }
+            $name = input('name','','trim');
+            if($name){
+                $map[] = ['name','like','%'.$name.'%'];
+            }
+            $tcw_title = input('tcw_title','','trim');
+            if($tcw_title){
+                $map[] = ['tcw_title','like','%'.$tcw_title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            if($import_id >0){
+                $map[] = ['import_log_id','=',$import_id];
+            }else{
+                $map[] = ['del','=',0];
+            }
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['is_show_option'] =$import_id>0?false:true;
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            $cType = Db::name('house_c_type')
+                ->where('del',0)
+                ->where('enable',1)
+                ->select();
+            $logInfo = [];
+            if($import_id>0){
+                $logInfo = Db::name('import_log')
+                    ->where('id',$import_id)
+                    ->find();
+            }
+            $this->assign('import_id',$import_id);
+            $this->assign('importInfo',$logInfo);
+            $this->assign('m_name','绑定车辆');
+            $this->assign('cType',$cType);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $area = Db::name('house')
+                    ->where('id',$info['carport_id'])
+                    ->find();
+                $info['line'] = [$area['area_id'],$info['carport_id']];
+                $this->assign('info',$info);
+            }
+            $tree = $this->model->tree();
+            $this->assign('tree',$tree);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('car')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('car')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    public function getType(){
+        $catId = input('id');
+        $list = Db::name('house_c_type')
+        ->where('cate',$catId)
+        ->where('del',0)
+        ->where('enable',1)
+        ->select();
+        $this->success('','',$list);
+    }
+    // excel
+    public function import(){
+
+        return $this->fetch();
+    }
+
+    /**
+     * 下载绑定车辆列表模板
+     */
+    public function downloadtem(){
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+        set_time_limit(0);
+        ini_set("memory_limit","512M");
+        $fileName = '绑定车辆列表.xlsx';
+        $excel = new \PHPExcel();
+        $sheet = $excel->setActiveSheetIndex(0);
+        $arr = array('A','B','C','D','E','F');
+        foreach($arr as $k=>$v){
+            $excel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(true);//换行
+            $excel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
+            $excel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
+        }
+        $sheet->setCellValueByColumnAndRow(0,1,'小区名称');
+        $sheet->setCellValueByColumnAndRow(1,1,'停车位名称');
+        $sheet->setCellValueByColumnAndRow(2,1,'品牌及车辆');
+        $sheet->setCellValueByColumnAndRow(3,1,'车牌号');
+        $sheet->setCellValueByColumnAndRow(4,1,'业主姓名');
+        $sheet->setCellValueByColumnAndRow(5,1,'业主电话');
+
+        ob_end_clean();//清除缓冲区,避免乱码
+        header('Content-Type: application/vnd.ms-excel');
+        header('Content-Disposition: attachment;filename="'.$fileName.'"');
+        header('Cache-Control: max-age=0');
+
+        $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
+        $objWriter->save('php://output'); //文件通过浏览器下载
+
+    }
+
+    /**
+     * 导入
+     */
+    public function importexcel(){
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+        set_time_limit(0);
+        ini_set("memory_limit", -1);
+        ob_flush();//清空缓存
+        flush();//刷新缓存
+
+        $orgId = cur_org_id();
+        $file = request()->file('file');
+        if(!$file){
+            exit('请上传文件');
+        }
+        // 移动到框架应用根目录/uploads/ 目录下
+        $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
+            ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
+        if(!$info){
+            exit('上传文件失败');
+
+        }
+        $img = env('root_path').'/public/uploads/files/' . $info->getSaveName();
+        $finfo = $info->getInfo();
+        $fileExt = explode('.',$finfo['name']);
+        $finfo['file_name'] = $finfo['name'];
+        $filepath = str_replace('\\', '/', $img);
+        $file_type = $fileExt[count($fileExt)-1];
+
+        if($file_type == 'xls'){
+            $objReader = \PHPExcel_IOFactory::createReader('Excel5');
+        }else{
+            $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
+        }
+        $imData = [
+            'org_id'=>$orgId,
+            'title'=>$finfo['file_name'],
+            'type'=>3,
+            'create_time'=>getTime(),
+        ];
+        $importId =Db::name('import_log')->insertGetId($imData);
+        $objPHPExcel = $objReader->load($filepath,$encode='utf-8');
+        $table = array(0,1,2,3,4,5,6);
+        $allobjWorksheets = $objPHPExcel->getAllSheets();
+        try{
+            @unlink($filepath);
+            foreach($allobjWorksheets as $key=>$objWorksheet){
+                $highestRow = $objWorksheet->getHighestRow();
+                $success = 0;
+                $error = 0;
+                $errorMsg = [];
+                for ($row = 2; $row <= $highestRow; ++$row) {
+                    $oneData = array();
+                    for ($col = 0; $col < count($table); ++$col) {
+                        $cell = $objWorksheet->getCellByColumnAndRow($col, $row);
+                        $value = (string)$cell->getValue();
+                        $oneData[$table[$col]]= $value;
+                    }
+                    if(!$oneData[0]||!$oneData[1] ||!$oneData[3] ||!$oneData[4] ||!$oneData[5]){
+                        $msg = "第".$row."行,数据存在空值,未导入";
+                        echo "<font color=\"red\">".$msg."</font><br />";
+                        $error++;
+                        $errorMsg[] = $msg;
+                        continue;
+                    }
+                    $area =Db::name('house_areas')
+                        ->where('title',trim($oneData[0]))
+                        ->where('type',1)
+                        ->where('pid',0)
+                        ->find();
+                    if(!$area){
+                        $msg = "第".$row."行,小区<".$oneData[0].">不存在,未导入";
+                        echo "<font color=\"red\">".$msg."</font><br />";
+                        $error++;
+                        $errorMsg[] = $msg;
+                        continue;
+                    }
+                    $carport = Db::name('house')
+                        ->where('title',trim($oneData[1]))
+                        ->where('area_id',$area['id'])
+                        ->where('del',0)
+                        ->where('cate',5)
+                        ->find();
+                    if(!$carport){
+                        $msg = "第".$row."行,小区<".$oneData[0].">下面停车位<".$oneData[1].">不存在,未导入";
+                        echo "<font color=\"red\">".$msg."</font><br />";
+                        $error++;
+                        $errorMsg[] = $msg;
+                        continue;
+                    }
+                    $data = [
+                        'org_id'=>$orgId,
+                        'carport_id'=>$carport['id'],
+                        'brand'=>$oneData[2],
+                        'plate_num'=>$oneData[3],
+                        'name'=>$oneData[4],
+                        'phone'=>$oneData[5],
+                        'create_time'=>getTime(),
+                        'import_log_id'=>$importId
+                    ];
+                    $Id = Db::name('car')->insertGetId($data);
+                    if(!$Id){
+                        $msg = "第".$row."行,导入失败";
+                        echo "<font color=\"red\">".$msg."</font><br />";
+                        $error++;
+                        $errorMsg[] = $msg;
+                        continue;
+                    }
+                    $success++;
+                }
+                Db::name('import_log')->where('id',$importId)
+                    ->update(
+                        [
+                            'success'=>$success,
+                            'error'=>$error,
+                            'error_msg'=>json_encode($errorMsg),
+                        ]
+                    );
+            }
+            echo "<font color=\"green\">导入完成</font><br />";
+        }catch (Exception $e){
+            echo $e->getMessage();
+            echo "<font color=\"red\">数据异常,已停止导入</font><br />";
+        }
+    }
+
+
+}

+ 135 - 0
application/admin/controller/Cate.php

@@ -0,0 +1,135 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class Cate extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['c.title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['c.enable','=',$enable];
+            }
+            $map[] = ['c.del','=',0];
+            $map[] = ['c.org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+
+            //数据查询
+            $lists = Db::name('cate')
+                ->alias('c')
+                ->field('c.*,o.name as orgTitle')
+                ->Leftjoin('org o','c.org_id=o.id')
+                ->where($map)
+                ->limit($start,$length)
+                ->order($order)
+                ->select();
+
+            //数据返回
+            $totalCount = Db::name('cate')->alias('c')->Leftjoin('org o','c.org_id=o.id')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','服务列表');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $model = new \app\common\model\Cate();
+            $res = $model->updates($this->orgId);
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($model->getError());
+            }
+        }else{
+            $meta_title = '新增服务';
+            if($id){
+                $info = Db::name('cate')->where('id',$id)->find();
+
+                $this->assign('info',$info);
+
+                $meta_title = '编辑服务';
+            }
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('cate')->where('id',$id)->update(['del' => 1]);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('cate')->where('id',$id)->update([$fn => $fv]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    /**
+     * 排序
+     * @param int $id
+     * @param int $sort
+     */
+    public function changeSort($id=0,$sort=0){
+        if($id<0||$sort<0){
+            $this->error('参数错误');
+        }
+        $res = Db::name('cate')->where('id',$id)->update(['sort'=>$sort]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+}

+ 121 - 0
application/admin/controller/CleanForm.php

@@ -0,0 +1,121 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+
+class CleanForm extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\CleanForm();
+        $this->table= $this->model->table;
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['type_name'] = db('clean_type')
+                    ->where('id',$v['type_id'])
+                    ->value('title');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name','任务内容');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info = db($this->table)->where('id',$id)->find();
+                if(!empty($info) && !empty($info['address_ids'])){
+                    $info['address_ids'] = explode(',',$info['address_ids']);
+                }
+                $this->assign('info',$info);
+            }
+
+            $this->assign('type',(new \app\common\model\CleanType())->getList());
+            $this->assign('address',(new \app\common\model\Address())->getListByType(8));
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+}

+ 324 - 0
application/admin/controller/CleanPlan.php

@@ -0,0 +1,324 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\util\ExcelUtil;
+use think\App;
+use think\Db;
+use think\Exception;
+
+class CleanPlan extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\CleanPlan();
+        $this->table= $this->model->table;
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['pid','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $ids = Db::name($this->table)->where('del',0)->where('pid',$v['id'])->column('id');
+                $lists[$k]['count'] = 0;
+                $lists[$k]['finish'] = 0;
+                $lists[$k]['notFinish'] = 0;
+                if($ids){
+                    $lists[$k]['count'] = Db::name('clean_plan_record')->where('del',0)->where('plan_id','in',$ids)->count();
+                    $lists[$k]['finish'] = Db::name('clean_plan_record')->where('del',0)->where('enable',1)->where('plan_id','in',$ids)->count();
+                    $lists[$k]['notFinish'] = Db::name('clean_plan_record')->where('del',0)->where('enable',0)->where('plan_id','in',$ids)->count();
+                }
+            }
+            //数据返回
+            $totalCount = Db::name($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name','专项年计划');
+            return $this->fetch();
+        }
+    }
+
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id > 0){
+                $info = Db::name($this->table)->where('id',$id)->find();
+                if($info){
+                    $info['forms'] = $info['forms']?explode(',',$info['forms']):[];
+                    $info['addrs'] = $info['addrs']?explode(',',$info['addrs']):[];
+                    $info['user'] = $info['user']?explode(',',$info['user']):[];
+                }
+                $this->assign('info',$info);
+            }
+
+            $users = (new \app\common\model\User())->getCleanWorker();
+            $this->assign('user',$users);
+
+            $this->assign('type',(new \app\common\model\CleanType())->getList());
+            $this->assign('address',(new \app\common\model\Address())->getListByType(8));
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $info = Db::name($this->table)->where('id',$id)->where('del',0)->find();
+        if(!$info){
+            $this->error('记录不存在或已删除');
+        }
+        if($info['pid'] == 0){ // 年计划
+            $planIds = Db::name($this->table)->where('pid',$id)->where('del',0)->column('id');
+
+            //删除年下面的月计划
+            Db::name($this->table)->where('pid',$id)->where('del',0)->setField('del',1);
+            //删除日计划
+            if(!empty($planIds)){
+                Db::name('clean_plan_record')->whereIn('plan_id',$planIds)->setField('del',1);
+            }
+
+        }else{
+             Db::name('clean_plan_record')->where('plan_id',$id)->setField('del',1);
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function month($id=0){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['pid','=',$id];
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['count'] = Db::name('clean_plan_record')->where('plan_id',$v['id'])->where('del',0)->count();
+                $lists[$k]['finish'] = Db::name('clean_plan_record')->where('plan_id',$v['id'])->where('del',0)->where('enable',1)->count();
+                $lists[$k]['notFinish'] = Db::name('clean_plan_record')->where('plan_id',$v['id'])->where('del',0)->where('enable',0)->count();
+
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('id',$id);
+            $info = Db::name('clean_plan')->where('id',$id)->find();
+            $this->assign('m_name','['.$info['title'].']月计划');
+            return $this->fetch();
+        }
+    }
+
+    public function madd($id=0,$pid=0){
+        if(request()->isPost()){
+            $res = $this->model->mupdates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id > 0){
+                $info = Db::name($this->table)->where('id',$id)->find();
+                if($info){
+                    $info['forms'] = $info['forms']?explode(',',$info['forms']):[];
+                    $info['addrs'] = $info['addrs']?explode(',',$info['addrs']):[];
+                    $pid = $info['pid'];
+                    $info['user'] = $info['user']?explode(',',$info['user']):[];
+                }
+                $this->assign('info',$info);
+            }
+            $pinfo = Db::name($this->table)->where('id',$pid)->find();
+
+            $months = [];
+            for ($i=1;$i<=12;$i++){
+                $months[] = [
+                    'id' => $i>9?$pinfo['year'].'-'.$i:$pinfo['year'].'-0'.$i,
+                    'title' => $i.'月'
+                ];
+            }
+            $this->assign('months',$months);
+
+            $forms = $pinfo['forms']?explode(',',$pinfo['forms']):[];
+            $addrs = $pinfo['addrs']?explode(',',$pinfo['addrs']):[];
+            $uids = $pinfo['user']?explode(',',$pinfo['user']):[];
+            $typs = (new \app\common\model\CleanType())->getList();
+            $address = (new \app\common\model\Address())->getListByType(8);
+            foreach ($typs as $k=>$v){
+                if(!in_array($v['id'],$forms)){
+                    unset($typs[$k]);
+                }
+            }
+
+            foreach ($address as $k=>$v){
+                if(!in_array($v['id'],$addrs)){
+                    unset($address[$k]);
+                }
+            }
+
+            $users = (new \app\common\model\User())->getCleanWorker();
+            $nuser = [];
+            foreach ($users as $k=>$v){
+                if(in_array($v['id'],$uids)){
+                    $nuser[] = $v;
+                }
+            }
+            $this->assign('user',$nuser);
+
+            $this->assign('type',$typs?$typs:[]);
+            $this->assign('address',$address?$address:[]);
+            $this->assign('pid',$pid);
+            return $this->fetch();
+        }
+    }
+
+    public function export($id = 0){
+        set_time_limit(0);
+        ini_set("memory_limit","3000M");
+        $info = Db::name('clean_plan')->where('id',$id)->where('pid',0)->where('del',0)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+        $lists = Db::name('clean_plan')->where('pid',$id)->where('del',0)->order('month asc,id asc')->select();
+        if(!$lists){
+            $this->error('未设置月计划');
+        }
+        $sheets = [];
+        $data = [];
+        foreach ($lists as $k=>$v){
+            $sheets[] = $v['month'];
+            $record = Db::name('clean_plan_record')
+                ->alias('a')
+                ->join('clean_type b','b.id = a.form_id')
+                ->join('address c','c.id = a.address_id')
+                ->where('a.plan_id',$v['id'])
+                ->where('a.del',0)
+                ->field('a.start,a.end,a.remark,b.title as btitle,c.title as atitle,a.create_time,a.enable,a.finish_user_id,a.finish_time,a.id,a.content')
+                ->order('a.start asc,a.id asc')
+                ->select();
+            $record = $record?$record:[];
+            foreach ($record as $kk=>$vv){
+                $users = Db::name('clean_plan_user')
+                    ->alias('a')
+                    ->join('user b','a.user_id = b.id')
+                    ->where('a.record_id',$vv['id'])
+                    ->column('b.real_name');
+                $record[$kk]['users'] = $users?implode(',',$users):'';
+                $record[$kk]['finish_user'] = '';
+                if($vv['finish_user_id'] > 0){
+                    $record[$kk]['finish_user'] = Db::name('user')->where('id',$vv['finish_user_id'])->value('real_name');
+                }
+
+                if($vv['enable'] == 0){
+                    $record[$kk]['enable_text'] = '未完成';
+                }else{
+                    $record[$kk]['enable_text'] = '已完成';
+                }
+
+            }
+            $data[] = $record;
+        }
+        $filename = $info['year'].'_'.$info['title'];
+        $header = [ // header格式,title和name必须存在
+            ['title' => '任务项', 'name' => 'btitle','width'=>'20'],
+            ['title' => '地点', 'name' => 'atitle','width'=>'20'],
+            ['title' => '开始时间', 'name' => 'start','width'=>'20'],
+            ['title' => '结束时间', 'name' => 'end','width'=>'20'],
+            ['title' => '备注', 'name' => 'remark','width'=>'20'],
+            ['title' => '人员', 'name' => 'users','width'=>'20'],
+            ['title' => '状态', 'name' => 'enable_text','width'=>'20'],
+            ['title' => '汇报人', 'name' => 'finish_user','width'=>'20'],
+            ['title' => '汇报内容', 'name' => 'content','width'=>'20'],
+            ['title' => '汇报时间', 'name' => 'finish_time','width'=>'20'],
+        ];
+        ExcelUtil::exportBySheet($filename,$header,$sheets,$data);
+    }
+}

+ 364 - 0
application/admin/controller/CleanPlanRecord.php

@@ -0,0 +1,364 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class CleanPlanRecord extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\CleanPlanRecord();
+        $this->table= $this->model->table;
+
+    }
+    public function index($id=0){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $formId = input('formId','','trim');
+            if($formId != ''){
+                $map[] = ['form_id','=',$formId];
+            }
+
+            $addrId = input('addrId','','trim');
+            if($addrId != ''){
+                $map[] = ['address_id','=',$addrId];
+            }
+
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['plan_id','=',$id];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $ftitle = Db::name('clean_type')->where('id',$v['form_id'])->value('title');
+                $atitle = Db::name('address')->where('id','in',explode(',',$v['address_id']))->select();
+                $lists[$k]['form_title'] = $ftitle;
+                $lists[$k]['addr_title'] = $atitle?implode(',',array_column($atitle,'title')):"";
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $pinfo = Db::name('clean_plan')->where('id',$id)->find();
+            $this->assign('pinfo',$pinfo);
+            $ptitle = Db::name('clean_plan')->where('id',$pinfo['pid'])->value('title');
+            $this->assign('m_name','['.$ptitle.']'.$pinfo['month'].'日计划');
+
+            $forms = $pinfo['forms']?explode(',',$pinfo['forms']):[];
+            $addrs = $pinfo['addrs']?explode(',',$pinfo['addrs']):[];
+            $typs = (new \app\common\model\CleanType())->getList();
+            $address = (new \app\common\model\Address())->getListByType(8);
+            foreach ($typs as $k=>$v){
+                if(!in_array($v['id'],$forms)){
+                    unset($typs[$k]);
+                }
+            }
+
+            foreach ($address as $k=>$v){
+                if(!in_array($v['id'],$addrs)){
+                    unset($address[$k]);
+                }
+            }
+
+            $this->assign('type',$typs?$typs:[]);
+            $this->assign('address',$address?$address:[]);
+
+            return $this->fetch();
+        }
+    }
+
+
+    /**
+     * 新增
+     */
+    public function add($id=0,$plan_id=0){
+        if(request()->isPost()){
+            $res = $this->model->addSave();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            $pinfo = Db::name('clean_plan')->where('id',$plan_id)->find();
+            if($id > 0){
+                $info = Db::name($this->table)->where('id',$id)->find();
+                if($info){
+                    $plan_id = $info['plan_id'];
+                }
+            }else{
+                $info['start'] = $pinfo['month'].'-01';
+                $info['end'] = $pinfo['month'].'-01';
+            }
+            $this->assign('info',$info);
+            $this->assign('plan_id',$plan_id);
+
+            $forms = $pinfo['forms']?explode(',',$pinfo['forms']):[];
+            $addrs = $pinfo['addrs']?explode(',',$pinfo['addrs']):[];
+            $uids = $pinfo['user']?explode(',',$pinfo['user']):[];
+            $typs = (new \app\common\model\CleanType())->getList();
+            $address = (new \app\common\model\Address())->getListByType(8);
+            foreach ($typs as $k=>$v){
+                if(!in_array($v['id'],$forms)){
+                    unset($typs[$k]);
+                }
+            }
+
+            foreach ($address as $k=>$v){
+                if(!in_array($v['id'],$addrs)){
+                    unset($address[$k]);
+                }
+            }
+
+            $users = (new \app\common\model\User())->getCleanWorker();
+            $nuser = [];
+            foreach ($users as $k=>$v){
+                if(in_array($v['id'],$uids)){
+                    $nuser[] = $v;
+                }
+            }
+            $this->assign('user',$nuser);
+
+            $this->assign('type',$typs?$typs:[]);
+            $this->assign('address',$address?$address:[]);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增
+     */
+    public function edit($id=0){
+        if(request()->isPost()){
+            $res = $this->model->editSave();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id > 0){
+                $info = Db::name($this->table)->where('id',$id)->find();
+                if($info){
+                    $plan_id = $info['plan_id'];
+                    $uids = Db::name('clean_plan_user')->where('record_id',$info['id'])->column('user_id');
+                    $info['user'] = $uids?$uids:[];
+                    $info['address_id'] = $info['address_id']?explode(',',$info['address_id']):[];
+                }
+                $this->assign('info',$info);
+            }
+            $this->assign('plan_id',$plan_id);
+
+            $pinfo = Db::name('clean_plan')->where('id',$plan_id)->find();
+            $forms = $pinfo['forms']?explode(',',$pinfo['forms']):[];
+            $addrs = $pinfo['addrs']?explode(',',$pinfo['addrs']):[];
+            $uids = $pinfo['user']?explode(',',$pinfo['user']):[];
+            $typs = (new \app\common\model\CleanType())->getList();
+            $address = (new \app\common\model\Address())->getListByType(8);
+            foreach ($typs as $k=>$v){
+                if(!in_array($v['id'],$forms)){
+                    unset($typs[$k]);
+                }
+            }
+
+            foreach ($address as $k=>$v){
+                if(!in_array($v['id'],$addrs)){
+                    unset($address[$k]);
+                }
+            }
+
+            $users = (new \app\common\model\User())->getCleanWorker();
+            $nuser = [];
+            foreach ($users as $k=>$v){
+                if(in_array($v['id'],$uids)){
+                    $nuser[] = $v;
+                }
+            }
+            $this->assign('user',$nuser);
+
+            $this->assign('type',$typs?$typs:[]);
+            $this->assign('address',$address?$address:[]);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function calendar(){
+        $m = input('month','');
+        $curMonth = input('month',date('Y-m'));
+        $this->assign('curMonth',$curMonth);
+        $back = 0;
+        $year = '';
+        if($m){
+            $back = 1;
+            list($year,$y1) = explode('-',$m);
+        }
+        $this->assign('back',$back);
+        $this->assign('year',$year);
+        return $this->fetch();
+    }
+
+    public function calendardata(){
+        $start = input('start');
+        $end = input('end');
+        $data = array();
+        if(!$start||!$end||$start>$end){
+            header('Content-Type:application/json; charset=utf-8');
+            exit(json_encode($data));
+        }
+        $start = date('Y-m-d H:i:s',strtotime($start));
+        $end = date('Y-m-d H:i:s',strtotime($end));
+        $map[] = [''];
+        $list = (new \app\common\model\CleanPlanRecord())->get_list_by_time($this->orgId,$start,$end);
+
+        foreach ($list as $k=>$v){
+            $arr = array(
+                'taskid' => $v['id'],
+                'title' => "任务项:{$v['ftitle']}<br>地点:{$v['atitle']}<br>开始时间:{$v['start']}<br>结束时间:{$v['end']}<br>",
+                'status' => $v['enable'],
+                'start' => $v['start'].' 00:00:00',
+                'end' => $v['end'].' 23:59:59'
+            );
+            if($v['enable'] == 0){
+                $arr['color'] = '#478fca';
+            }else{
+                $arr['color'] = '#69aa46';
+            }
+
+//            if($v['status'] == 0){
+//                $arr['color'] = '#777777';
+//            }else if($v['status'] == 1){
+//                $arr['color'] = '#478fca';
+//            }else if($v['status'] == 2){
+//                $arr['color'] = '#69aa46';
+//            }else if($v['status'] == 3){
+//                $arr['color'] = '#dd5a43';
+//            }else if($v['status'] == 5){
+//                $arr['color'] = '#53a2a7';
+//            }else{
+//                $arr['color'] = '#5b53a7';
+//            }
+            $data[] = $arr;
+        }
+        header('Content-Type:application/json; charset=utf-8');
+        exit(json_encode($data));
+    }
+
+    public function year(){
+        $year = input('year',date('Y'));
+        $month = [];
+        for ($i=1;$i<=12;$i++){
+            if($i>10){
+                $a = $i;
+            }else{
+                $a='0'.$i;
+            }
+            $month[] = $year.'-'.$a;
+        }
+        $list = [];
+        foreach ($month as $k=>$v){
+            $c = $c1 = $c2 = 0;
+            $plan =Db::name('clean_plan')
+                ->where('del',0)
+                ->where('enable',1)
+                ->where('org_id',$this->orgId)
+                ->where('month',$v)
+                ->find();
+            if($plan){
+                $c = Db::name('clean_plan_record')
+                    ->where('plan_id',$plan['id'])
+                    ->where('del',0)->count();
+                $c1 = Db::name('clean_plan_record')
+                    ->where('plan_id',$plan['id'])
+                    ->where('del',0)
+                    ->where('enable',0)
+                    ->count();
+                $c2 = Db::name('clean_plan_record')
+                    ->where('plan_id',$plan['id'])
+                    ->where('del',0)
+                    ->where('enable',1)
+                    ->count();
+            }
+            $list[] = [
+                'title'=>$v,
+                'count'=>$c,
+                'count1'=>$c1,
+                'count2'=>$c2,
+            ];
+        }
+
+        $this->assign('lists',$list);
+        $this->assign('last',$year+1);
+        $this->assign('prv',$year-1);
+        return $this->fetch();
+    }
+
+    public function detail($id = 0){
+        $info = $this->model->detail($id,$this->orgId);
+        if($info){
+            $info['imgs'] = $info['imgs']?explode(',',$info['imgs']):[];
+        }
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+}

+ 221 - 0
application/admin/controller/CleanTask.php

@@ -0,0 +1,221 @@
+<?php
+
+namespace app\admin\controller;
+use think\App;
+use think\Db;
+
+class CleanTask extends Auth {
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model = new \app\common\model\CleanTask();
+        $this->table = $this->model->table;
+    }
+    public function index() {
+        if (request()->isAjax()) {
+            //分页参数
+            $length = input('rows', 10, 'intval');   //每页条数
+            $page = input('page', 1, 'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx', 'id', 'trim');      //排序列
+            $sort = input('sord', 'desc', 'trim');        //排序方式
+            $order = $sortRow . ' ' . $sort;
+            $title = input('title', '', 'trim');
+            if ($title) {
+                $map[] = ['title', 'like', '%' . $title . '%'];
+            }
+            $enable = input('enable', '', 'trim');
+            if ($enable != '') {
+                $map[] = ['enable', '=', $enable];
+            }
+            $status = input('status', '', 'trim');
+            if ($status != '') {
+                $map[] = ['status', '=', $status];
+            }
+            $map[] = ['del', '=', 0];
+            $map[] = ['org_id', '=', $this->orgId];
+            $map = empty($map) ? true : $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start, $length)->order($order)->select();
+            foreach ($lists as $k => $v) {
+                $userlist = Db::name('clean_task_user')
+                    ->alias('clean_task_user')
+                    ->join('user user', 'user.id = clean_task_user.user_id')
+                    ->field('user.id,user.real_name')
+                    ->where('clean_task_user.task_id', $v['id'])
+                    ->select();
+                $users = array();
+                foreach ($userlist as $kk => $vv) {
+                    $users[] = $vv['real_name'];
+                }
+                $lists[$k]['user'] = implode(',', $users);
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount / $length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }
+        else {
+            $this->assign('m_name', '计划管理');
+            return $this->fetch();
+        }
+    }
+    /**
+     * 新增/编辑
+     */
+    public function add($id = 0) {
+        if (request()->isPost()) {
+            $res = $this->model->updates();
+            if ($res) {
+                $this->success('操作成功', url('index'));
+            }
+            else {
+                $this->error($this->model->getError());
+            }
+        }
+        else {
+            if ($id) {
+                $info = db($this->table)->where('id', $id)->find();
+                $info['type'] = db('clean_task_form')
+                    ->where('task_id', $id)
+                    ->column('form_id');
+                $info['user'] = db('clean_task_user')
+                    ->where('task_id', $id)
+                    ->column('user_id');
+                $this->assign('info', $info);
+            }
+            $this->assign('user', (new \app\common\model\User())->getCleanWorker());
+            $this->assign('type', (new \app\common\model\CleanType())->getGroupList());
+            return $this->fetch();
+        }
+    }
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id = 0) {
+        if (!$id) {
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id', $id)->update([
+            'del'=>1,
+            'del_user_id'=>is_login(),
+            'del_datetime'=>getTime(),
+        ]);
+        if ($res) {
+            $this->success('删除成功');
+        }
+        else {
+            $this->error('删除失败');
+        }
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id = 0, $fn = '', $fv = 0) {
+        if (!$fn || !$id) {
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id', $id)->setField($fn, $fv);
+        if ($res) {
+            $this->success('操作成功');
+        }
+        else {
+            $this->error('操作失败');
+        }
+    }
+
+    public function details($id = 0){
+
+        $info = Db::name('clean_task')->where('id',$id)->find();
+        if(!$info){
+            $this->error('参数错误');
+        }
+        $info['check_user_name'] =  Db::name('user')->where('id',$info['check_user'])->value('real_name');
+
+        $taskUser = Db::name('clean_task_user')
+            ->alias('ctu')
+            ->join('user u','u.id=ctu.user_id')
+            ->where('ctu.task_id',$info['id'])
+            ->column('u.real_name');
+
+        $info['task_user'] = $taskUser?implode(',',$taskUser):'';
+
+        $taskFormId = Db::name('clean_task_form')->where('task_id',$id)->column('form_id');
+
+        $addr = Db::name('clean_type')
+            ->alias('ct')
+            ->field('cf.id,ct.title')
+            ->join('clean_form cf','cf.type_id=ct.id')
+            ->whereIn('cf.id',$taskFormId)
+            ->select();
+
+
+        foreach ($addr as $k=>$v){
+            $record = Db::name('clean_record')
+                ->alias('cr')
+                ->field('cr.*,u.real_name')
+                ->join('user u','u.id=cr.user_id')
+                ->where('cr.task_id',$id)
+                ->where('cr.form_id',$v['id'])
+                ->find();
+            if($record){
+                $record['check_json'] = [];
+                if($record['check_json']){
+                    $cjson = json_decode($record['check_json'],true);
+                    foreach ($cjson as $kk=>$vv){
+                        $address = Db::name('address')->where('id',$vv)->value('title');
+                        $cjson = [
+                            'addr'=>$address,
+                            'status'=>$vv['status']
+                        ];
+                    }
+                    $record['check_json'] = $cjson;
+                }
+
+
+            }
+            $addr[$k]['record'] = $record;
+        }
+        $info['formList'] = $addr;
+
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+
+    public function subDetail(){
+        $id = input('id');
+        $info = Db::name('clean_record')->where('id',$id)->find();
+        $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');
+        $info['task_title'] = Db::name('clean_task')->where('id',$info['task_id'])->value('title');
+        if($info['check_json']){
+            $cjson = json_decode($info['check_json'],true);
+            $tarr = [];
+            foreach ($cjson as $kk=>$vv){
+                $address = Db::name('address')->where('id',$vv['id'])->value('title');
+                $tarr[] = [
+                    'addr'=>$address,
+                    'status'=>$vv['status']
+                ];
+            }
+            $info['check_json'] = $tarr;
+        }
+        $info['items'] = Db::name('clean_record_items')
+            ->alias('cri')
+            ->field('mg.title,cri.*')
+            ->join('mate_goods mg','mg.id=cri.items_id')
+            ->where('cri.record_id',$info['id'])
+            ->select();
+
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+}

+ 188 - 0
application/admin/controller/CleanType.php

@@ -0,0 +1,188 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class CleanType extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\CleanType();
+        $this->table= $this->model->table;
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['parent_id','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name','任务类型');
+            return $this->fetch();
+        }
+    }
+    public function show(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['parent_id','>',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as &$v){
+                $v['parent_title'] = db($this->table)->where('id',$v['parent_id'])->value('title');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name','任务项');
+            return $this->fetch();
+        }
+    }
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info = db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            $type = input('type','');
+            if($type==1){
+                $parent =$this->model->list();
+                $this->assign('parent_list',$parent);
+            }
+            $this->assign('type',$type);
+
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $info = db($this->table)->where('id',$id)->find();
+        if($info['parent_id'] == 0){
+            if(db($this->table)->where('parent_id',$id)->where('del',0)->find()){
+                $this->error('有任务项绑定该类型,暂不能删除');
+            }
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    public function batchSort(){
+        $data = input('data','','trim');
+        if(!$data){
+            $this->error('参数错误');
+        }
+        $data = json_decode($data,true);
+        if(!$data){
+            $this->error('参数错误');
+        }
+
+        Db::startTrans();
+        try{
+            foreach ($data as $k=>$v){
+                Db::name('clean_type')->where('id',$v['id'])->setField('sort',$v['sort']);
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+}

+ 375 - 0
application/admin/controller/CockpitStatistics.php

@@ -0,0 +1,375 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+use think\Exception;
+
+class CockpitStatistics extends Auth
+{
+
+    public function index(){
+
+        return $this->fetch();
+    }
+
+    public function todoCompletion(){
+        $mode = input('mode',1);
+        $month = date('Ym');
+        //总工单
+        $totalCount = Db::name('todo')
+            ->where('del',0)
+            ->where('org_id',$this->orgId)
+            ->where('create_yyyymm',$month)
+            ->where('work_type_mode',$mode)
+            ->count();
+        //完成的工单
+        $count1 = Db::name('todo')
+            ->where('del',0)
+            ->where('org_id',$this->orgId)
+            ->where('create_yyyymm',$month)
+            ->where('work_type_mode',$mode)
+            ->where('todo_mode',3)
+            ->count();
+
+        //主动完成工单
+        $count2 = Db::name('todo')
+            ->alias('t')
+            ->join('orders o','o.id=t.order_id')
+            ->where('o.del',0)
+            ->where('o.source_type',3)
+            ->where('o.create_yyyymm',$month)
+            ->where('o.org_id',$this->orgId)
+            ->where('t.del',0)
+            ->where('t.org_id',$this->orgId)
+            ->where('t.create_yyyymm',$month)
+            ->where('t.work_type_mode',$mode)
+            ->where('t.todo_mode',3)
+            ->count();
+        //被动完成的工单
+        $count3 = Db::name('todo')
+            ->alias('t')
+            ->join('orders o','o.id=t.order_id')
+            ->where('o.del',0)
+            ->whereIn('o.source_type',[1,2])
+            ->where('o.create_yyyymm',$month)
+            ->where('o.org_id',$this->orgId)
+            ->where('t.del',0)
+            ->where('t.org_id',$this->orgId)
+            ->where('t.create_yyyymm',$month)
+            ->where('t.work_type_mode',$mode)
+            ->where('t.todo_mode',3)
+            ->count();
+
+        $bl1 = $bl3 = $bl5 = 0;
+        $bl2 = $bl4 = $bl6 = 100;
+
+        if($totalCount > 0){
+            $remain = $totalCount-$count1;
+            $bl1 = round($count1/$totalCount*100,2);
+            $bl2 = round($remain/$totalCount*100,2);
+
+            $remain2 = $totalCount-$count2;
+            $bl3 = round($count2/$totalCount*100,2);
+            $bl4 = round($remain2/$totalCount*100,2);
+
+            $remain3 = $totalCount-$count3;
+            $bl5 = round($count3/$totalCount*100,2);
+            $bl6 = round($remain3/$totalCount*100,2);
+        }
+
+        $data =[
+            'count1'=>['title'=>'总完成率','bl1'=>$bl1,'bl2'=>$bl2],
+            'count2'=>['title'=>'主动完成率','bl1'=>$bl3,'bl2'=>$bl4],
+            'count3'=>['title'=>'被动完成率','bl1'=>$bl5,'bl2'=>$bl6],
+            'title'=>['总完成率','主动完成率','被动完成率'],
+        ];
+        $this->success('','',$data);
+    }
+
+    public function todoResponseTime(){
+        $mode = input('mode',1);
+        $month = date('Ym');
+        $lastMonth = date('Ym',strtotime("-1 month"));
+
+        $todo = Db::name('todo')
+            ->field('xy_time')
+            ->where('del',0)
+            ->where('org_id',$this->orgId)
+            ->where('create_yyyymm',$month)
+            ->where('work_type_mode',$mode)
+            ->select();
+        $nums = 0;
+        foreach ($todo as $k=>$v){
+            $nums +=$v['xy_time'];
+        }
+        $count = round($nums/60/60,1);
+
+        $lastTodo = Db::name('todo')
+            ->field('xy_time')
+            ->where('del',0)
+            ->where('org_id',$this->orgId)
+            ->where('create_yyyymm',$lastMonth)
+            ->where('work_type_mode',$mode)
+            ->select();
+
+        $nums2 = 0;
+        foreach ($lastTodo as $k=>$v){
+            $nums2 +=$v['xy_time'];
+        }
+        $count2 = round($nums2/60/60,1);
+
+        $data = [
+            'count'=>$count,
+            'count2'=>$count-$count2,
+        ];
+        $this->success('','',$data);
+    }
+
+    public function repairTodo(){
+        $list = Db::name('order_type')
+            ->field('id,title as name')
+            ->where('org_id',$this->orgId)
+            ->where('parent_id',0)
+            ->where('del',0)
+            ->where('enable',1)
+            ->limit(5)
+            ->select();
+        foreach ($list as $k=>$v){
+            $repair = Db::name('order_type')
+                ->field('id')
+                ->where('org_id',$this->orgId)
+                ->where('parent_id',$v['id'])
+                ->where('del',0)
+                ->where('enable',1)
+                ->select();
+            $ids = [];
+            foreach ($repair as $kk=>$vv){
+                $ids[] = $vv['id'];
+            }
+            $todo = Db::name('todo')
+                ->alias('t')
+                ->field('t.wc_time')
+                ->join('order_repair or','or.order_id=t.order_id')
+                ->whereIn('or.type_id',$ids)
+                ->where('t.del',0)
+                ->where('t.org_id',$this->orgId)
+                ->where('t.create_yyyymm',date('Ym'))
+                ->select();
+            $nums = 0;
+            foreach ($todo as $key=>$val){
+                $nums +=$val['wc_time'];
+            }
+
+            $list[$k]['value'] = round($nums/60/60,1);
+        }
+        $this->success('','',$list);
+    }
+
+    public function cleanTypeTask(){
+        $list = Db::name('clean_type')
+            ->field('id,title')
+            ->where('parent_id',0)
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('enable',1)
+            ->limit(5)
+            ->select();
+        $title = [];
+        foreach ($list as $k=>$v){
+            $title[] = $v['title'];
+            $type = Db::name('clean_type')
+                ->where('parent_id',$v['id'])
+                ->where('org_id',$this->orgId)
+                ->where('del',0)
+                ->where('enable',1)
+                ->column('id');
+
+            $form = Db::name('clean_form')
+                ->where('org_id',$this->orgId)
+                ->where('del',0)
+                ->where('enable',1)
+                ->whereIn('type_id',$type)
+                ->column('id');
+
+//            $task = Db::name('clean_task')
+//                ->alias('ct')
+//                ->join('clean_task_form ctf','ctf.task_id=ct.id')
+//                ->whereIn('ctf.form_id',$form)
+//                ->where('ct.org_id',$this->orgId)
+//                ->where('ct.del',0)
+//                ->count();
+            $taskCount = Db::name('clean_task')
+                ->alias('ct')
+                ->join('clean_task_form ctf','ctf.task_id=ct.id')
+                ->whereIn('ctf.form_id',$form)
+                ->where('ct.org_id',$this->orgId)
+                ->where('ct.del',0)
+                ->whereIn('ct.status',[2,3])
+                ->count();
+
+            $list[$k]['value'] =$taskCount;
+        }
+        $data = [
+            'list'=>$list,
+            'title'=>$title,
+        ];
+        $this->success('','',$data);
+    }
+
+    public function mateGoods(){
+        $where[] = ['create_time','>=',date('Y-m').'-01 00:00:00'];
+        $where[] = ['create_time','<=',date('Y-m').'-31 00:00:00'];
+
+        $list = Db::name('mate_goods')
+            ->field('id,title')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('enable',1)
+            ->limit(6)
+            ->select();
+        $title = $count = [];
+        foreach ($list as $k=>$v){
+            $title[]= $v['title'];
+            $nums = Db::name('todo_mate_item')
+                ->where('items_id',$v['id'])
+                ->where($where)
+                ->sum('total');
+            $count[] = $nums;
+        }
+
+        $data = [
+            'list'=>$count,
+            'title'=>$title,
+        ];
+        $this->success('','',$data);
+    }
+
+    public function orgUser(){
+        $list = [
+            ['id'=>3,'name'=>'客户'],
+            ['id'=>4,'name'=>'综合'],
+            ['id'=>5,'name'=>'保安'],
+            ['id'=>6,'name'=>'运送'],
+            ['id'=>7,'name'=>'维修'],
+            ['id'=>8,'name'=>'保洁'],
+            ['id'=>9,'name'=>'调度'],
+            ['id'=>10,'name'=>'管理层'],
+        ];
+        foreach ($list as $k=>$v){
+            $roles = Db::name('roles')
+                ->where('org_id',$this->orgId)
+                ->where('enable',1)
+                ->where('del',0)
+                ->where('parent_id',$v['id'])
+                ->column('id');
+            $user = Db::name('user')
+                ->alias('u')
+                ->join('user_org uo','uo.user_id=u.id')
+                ->join('user_roles ur','ur.user_id=uo.user_id')
+                ->whereIn('ur.roles_id',$roles)
+                ->where('uo.org_id',$this->orgId)
+                ->where('u.enable',1)
+                ->where('u.del',0)
+                ->count();
+            $list[$k]['value'] = $user;
+        }
+
+        $this->success('','',$list);
+    }
+
+    public function wasteCount(){
+        $waste = Db::name('waste_record')
+            ->where('org_id',$this->orgId)
+            ->where('create_yyyymm',date('Ym'))
+            ->where('status',2)
+            ->where('del',0)
+            ->column('weight');
+        $nums = 0;
+        foreach ($waste as $k=>$v){
+            $nums +=$v;
+        }
+        $count = round($nums/1000,2);
+        $type = 0;
+        $record = Db::name('waste_record')->where('org_id',$this->orgId)->where('del',0)->find();
+        if(!$record){
+            $type = 1; //功能未应用
+        }
+
+        $sdate = date('Y-m-d H:i:s',strtotime("-3 day"));
+        $edate = date('Y-m-d H:i:s');
+
+
+        $record3 = Db::name('waste_record')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('create_time','>',$sdate)
+            ->where('create_time','<',$edate)
+            ->order('id desc')
+            ->find();
+        if($record3){
+            $type = 3; //绿色
+        }
+        $record2 = Db::name('waste_record')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('create_time','>',$sdate)
+            ->order('id desc')
+            ->find();
+        if(!$record3 && !$record2){
+            $type = 2; //红色
+        }
+
+        $data = [
+            'count' =>$count,
+            'type' =>$type,
+
+        ];
+        $this->success('','',$data);
+    }
+
+    public function dailyDataCount(){
+        $sDate = date('Ymd',strtotime( "-3 month"));
+        $eDate = date('Ymd');
+
+        $count = Db::name('daily_record')
+            ->where('org_id',$this->orgId)
+            ->where('create_yyyymmdd','>',$sDate)
+            ->where('create_yyyymmdd','<=',$eDate)
+            ->count();
+
+        $count2 = Db::name('comment')
+            ->where('org_id',$this->orgId)
+            ->where('type',0)
+            ->where('create_yyyymmdd','>',$sDate)
+            ->where('create_yyyymmdd','<=',$eDate)
+            ->count();
+
+        $count3 = Db::name('comment')
+            ->where('org_id',$this->orgId)
+            ->where('type',0)
+            ->where('create_yyyymm',date('Ym'))
+            ->count();
+
+        $count4 = Db::name('comment')
+            ->where('org_id',$this->orgId)
+            ->where('type',0)
+            ->where('create_yyyymm',date('Ym'))
+            ->avg('score');
+
+        $bl = '100%';
+        if($count > 0){
+            $bl = round($count2/$count*100,1).'%';
+        }
+
+        $data = [
+            'bl'=>$bl,
+            'count2'=>$count2.'/'.$count,
+            'count3'=>$count3,
+            'count4'=>round($count4,1),
+
+        ];
+        $this->success('','',$data);
+    }
+
+
+}

+ 52 - 0
application/admin/controller/Comment.php

@@ -0,0 +1,52 @@
+<?php
+namespace app\admin\controller;
+use think\Db;
+
+class Comment extends Auth
+{
+
+    public function index(){
+        $type = input('type', 0);
+
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['content','like','%'.$title.'%'];
+            }
+
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['type','=',$type];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('comment')->limit($start,$length)->where($map)->order(['id'=>'desc'])->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['userName'] = Db::name('user')
+                    ->where('id',$v['user_id'])->value('real_name');
+            }
+
+            //数据返回
+            $totalCount = Db::name('comment')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            $this->assign('type',$type);
+            return $this->fetch();
+        }
+
+    }
+
+}

+ 158 - 0
application/admin/controller/Common.php

@@ -0,0 +1,158 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\model\Seeker;
+use think\Controller;
+use think\Db;
+use think\Exception;
+
+class Common extends Controller
+{
+    public function initialize()
+    {
+        parent::initialize();
+    }
+
+    public function login(){
+        if(request()->isPost()){
+            $username = input('?post.account')?input('post.account','','trim'):'';
+            $password = input('?post.password')?input('post.password','','trim'):'';
+            if(!$username||!$password){
+                $this->error('用户名或密码错误');
+            }
+
+            $ret = (new \app\common\util\ThrottlesUtil(config('app.login_throttles')))->tooManyAttempts($username); // 登录限流
+            if($ret){
+                $this->error('账号已被锁定,请稍后重试');
+            }
+
+            $info = Db::name('user')->where('account',$username)->where('del',0)->find();
+            if(empty($info))  $this->error('用户信息不存在');
+            if($info['enable']==0) $this->error('该账号被禁用');
+
+            if(!password_verify($password,$info['password'])){
+                $this->error('用户名或密码错误');
+            }
+
+            $rolesId = Db::name('user_roles')->where('user_id',$info['id'])->value('roles_id');
+            if(!$rolesId){
+                $this->error('用户未设置角色,无法登陆');
+            }
+            $orgs = model('Org')->getListByRoles($info['id']);
+            if(empty($orgs)){
+                $this->error('用户没有组织,无法登陆');
+            }
+
+            /* 更新登录信息 */
+            $data = array(
+                'last_login_time' => date('Y-m-d H:i:s')
+            );
+            Db::name('user')->where('id',$info['id'])->update($data);
+
+            /* 记录登录SESSION和COOKIES */
+            $auth = array(
+                'id'                => $info['id'],
+                'account'           => $info['account'],
+                'real_name'         => $info['real_name'],
+                'last_login_time'   => $data['last_login_time'],
+                'rolesId'           => $rolesId?$rolesId:0
+            );
+            session('user_auth',$auth);
+            session('user_auth_sign',data_auth_sign($auth));
+
+            session('orgId',$orgs[0]['id']);
+            session('orgName',$orgs[0]['name']);
+
+            (new \app\common\util\ThrottlesUtil(config('app.login_throttles')))->resetAttempts($username); // 登录成功,重置限流
+
+            $url = $_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:url('Index/index');
+            $this->success('登录成功',$url);
+        }else{
+            $config = Db::name('config')
+                ->where('name','web_site_title')
+                ->value('value');
+            if(is_login()){
+                $this->redirect(url('Index/index'));
+            }
+            $this->assign('title',$config);
+            return $this->fetch();
+        }
+    }
+
+    public function forget(){
+        if(request()->isPost()) {
+            $username = input('?post.account')?input('post.account','','trim'):'';
+            $password = input('?post.password')?input('post.password','','trim'):'';
+            $code = input('?post.code')?input('post.code','','trim'):'';
+
+            if(!$username){
+                $this->error('手机号不能为空');
+            }
+            if(!$code){
+                $this->error('验证码不能为空');
+            }
+            if(!$password){
+                $this->error('新密码不能为空');
+            }
+            if(!verify_sms($username,$code)){
+                $this->error('验证码信息错误');
+            }
+            $info = Db::name('user')
+                ->where('mobile',$username)
+                ->where('del',0)->find();
+            if(empty($info))  $this->error('用户信息不存在');
+            if($info['enable']==0) $this->error('该账号被禁用');
+
+            $pas =  password_hash($password, PASSWORD_DEFAULT);
+            $sdata = [
+                'update_time' => date('Y-m-d H:i:s'),
+                'password' =>$pas
+            ];
+            $res = Db::name('user')
+                ->where('id',$info['id'])
+                ->update($sdata);
+            $res?$this->success('修改成功',url('common/login')):$this->error('修改失败');
+        }else{
+            $config = Db::name('config')
+                ->where('name', 'web_site_title')
+                ->value('value');
+            $this->assign('title',$config);
+            return $this->fetch();
+        }
+
+    }
+
+    public function sms(){
+        $phone = input('mobile');
+        if(empty($phone)){
+            $this->error('手机号不能为空');
+        }
+        $res = send_verify_sms($phone);
+        if(!$res){
+            $this->error('发送失败');
+        }
+        $this->success('发送成功');
+    }
+    /**
+     * 退出登录
+     */
+    public function logout(){
+        session('user_auth',null);
+        session('user_auth_sign',null);
+        $this->redirect(url('Common/login'));
+    }
+
+    /**
+     * 无权限跳转页面
+     */
+    public function access(){
+        return $this->fetch();
+    }
+
+    /**
+     * 403页面
+     */
+    public function forbid(){
+        return $this->fetch('403');
+    }
+}

+ 93 - 0
application/admin/controller/CompanyDispatch.php

@@ -0,0 +1,93 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\model\MateGoodsLog;
+use think\App;
+use think\Db;
+use think\Exception;
+
+class CompanyDispatch extends Auth
+{
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model = new \app\common\model\MateApply();
+        $this->table = $this->model->table;
+    }
+    /**
+     * 公司仓库入库记录
+     *
+     * @author wst
+     * @date   2021/9/10 8:37
+     */
+    public function show(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['sn','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['type','=',1];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists =db($this->table)
+                ->where($map)->limit($start,$length)
+                ->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['userName'] = db('user')
+                    ->where('id',$v['user_id'])
+                    ->value('real_name');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','入库记录');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增入库
+     */
+    public function add(){
+        if(request()->isPost()){
+            $res = $this->model->updates($this->userId);
+            if($res){
+                $this->success('操作成功',url('show'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            $meta_title = '新增入库';
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    //详情
+    public function info($id){
+        $info = $this->model->getInfo($id);
+        if(!$info) $this->error('记录不存在');
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+}

+ 359 - 0
application/admin/controller/CompanyGoods.php

@@ -0,0 +1,359 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\model\MateGoodsLog;
+use think\App;
+use think\Db;
+use think\Exception;
+
+class CompanyGoods extends Auth
+{
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model = new \app\common\model\MateGoods();
+        $this->table = $this->model->table;
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $cate_id = input('cate_id','','trim');
+            if($cate_id != ''){
+                $map[] = ['cate_id','=',$cate_id];
+            }
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists =db($this->table)
+                ->where($map)->limit($start,$length)
+                ->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['cate_name'] = Db::name('mate_cate')->where('id',$v['cate_id'])->value('title');
+            }
+
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','物品管理');
+            $cate  = Db::name('mate_cate')
+                ->where('enable',1)
+                ->where('del',0)
+                ->where('org_id',$this->orgId)
+                ->select();
+            $this->assign('cate',$cate);
+            return $this->fetch();
+        }
+    }
+
+    public function selectGoods(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $map[] = ['enable','=',1];
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists =db($this->table)
+                ->where($map)->limit($start,$length)
+                ->order($order)->select();
+
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        $model = $this->model;
+        if(request()->isPost()){
+            $res = $model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($model->getError());
+            }
+        }else{
+            $meta_title = '新增物品';
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+                $meta_title = '编辑物品';
+            }
+            $cate = Db::name('mate_cate')->where('del',0)->where('org_id',$this->orgId)->select();
+            $this->assign('cate',$cate);
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        if(db('mate_apply_goods')->where('goods_id',$id)->find()){
+            $this->error('该商品有入库或出库记录,暂不能删除');
+        }
+        $res = db($this->table)->where('id',$id)->update(['del'=>1]);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->update([$fn => $fv]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    /**
+     * 处置
+     */
+    public function option($id=0){
+        $model = new MateGoodsLog();
+        if(request()->isPost()){
+            $data = request()->post();
+            if(empty($data['nums'])) $this->error('请输入数量');
+            if(empty($data['remark'])) $this->error('请输入备注');
+            $info = db('mate_goods')
+                ->where('id',$id)
+                ->find();
+            if($info['nums'] <$data['nums']) $this->error('库存数量不足');
+            $sData = [
+                'org_id'=>$this->orgId,
+                'goods_id'=>$id,
+                'nums'=>$data['nums'],
+                'remark'=>$data['remark'],
+                'price'=>$info['price'],
+            ];
+            Db::startTrans();
+            try{
+                $res = $model->saveData($sData);
+                if(!$res){
+                    \exception($model->getError());
+                }
+                $ret = Db::name('mate_goods')->where('id',$id)->setDec('nums',$data['nums']);
+                if(!$ret){
+                    \exception('操作失败');
+                }
+                Db::commit();
+            }catch (Exception $e){
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+            $this->success('操作成功');
+        }else{
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+    public function import(){
+        return $this->fetch();
+    }
+    /**
+     * 下载点模板
+     */
+    public function downloadtem(){
+        set_time_limit(0);
+        ini_set("memory_limit","512M");
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+        $types = model('Address')->getTypes();
+        ksort($types);
+        $fileName = '物品模板.xlsx';
+        $excel = new \PHPExcel();
+        $sheet = $excel->setActiveSheetIndex(0);
+        $arr = array('A','B','C','D','E','F');
+        foreach($arr as $k=>$v){
+            $excel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(true);//换行
+            $excel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
+            $excel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
+
+        }
+        $sheet->setCellValueByColumnAndRow(0,1,'名称');
+        $sheet->setCellValueByColumnAndRow(1,1,'分类');
+        $sheet->setCellValueByColumnAndRow(2,1,'单位');
+        $sheet->setCellValueByColumnAndRow(3,1,'品牌');
+        $sheet->setCellValueByColumnAndRow(4,1,'规格');
+        $sheet->setCellValueByColumnAndRow(5,1,'类型(固定资产/耗材)');
+        $sheet->setCellValueByColumnAndRow(6,1,'备注');
+
+
+        $excel->getActiveSheet()->setCellValue('A2', '测试物品');
+        $excel->getActiveSheet()->setCellValue('B2', '测试分类编号(2)');
+        $excel->getActiveSheet()->setCellValue('C2', '个');
+        $excel->getActiveSheet()->setCellValue('D2', '格力');
+        $excel->getActiveSheet()->setCellValue('E2', '10个/包');
+        $excel->getActiveSheet()->setCellValue('F2', '固定资产');
+        $excel->getActiveSheet()->setCellValue('G2', 'xxxx');
+
+        ob_end_clean();//清除缓冲区,避免乱码
+        header('Content-Type: application/vnd.ms-excel');
+        header('Content-Disposition: attachment;filename="'.$fileName.'"');
+        header('Cache-Control: max-age=0');
+
+        $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
+        $objWriter->save('php://output'); //文件通过浏览器下载
+
+    }
+
+
+    /**
+     * 导入
+     */
+    public function importexcel(){
+        set_time_limit(0);
+        ini_set("memory_limit", -1);
+        ob_flush();//清空缓存
+        flush();//刷新缓存
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+        $orgId = $this->orgId;
+        if(request()->file()) {
+            $file = request()->file('file');
+            //获取文件后缀
+            $e = explode('.',$_FILES['file']['name']);
+            $ext = $e[count($e)-1];
+            if($ext == 'xls'){
+                \PHPExcel_IOFactory::createReader( 'Excel5');
+            }else{
+                \PHPExcel_IOFactory::createReader('Excel2007');
+            }
+            $newArr=['xls','xlsx'];
+            if(!in_array($ext,$newArr)){
+                exit('文件格式不正确');
+            }
+            // 移动到框架应用根目录/uploads/ 目录下
+            $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
+                ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
+            if(!$info){
+                exit('文件上传失败');
+            }
+            $img = './uploads/files/' . $info->getSaveName();
+            $filePath = str_replace('\\', '/', $img);
+            $newPath = \PHPExcel_IOFactory::load($filePath);
+
+            $excelArray = $newPath->getsheet(0)->toArray();   //转换为数组格式
+
+            array_shift($excelArray);  //删除第一个数组(标题);
+            $a = [
+                '固定资产'=>1,
+                '耗材'=>2,
+            ];
+            if(empty($excelArray)){
+                exit('文件内容为空');
+            }
+
+            foreach ($excelArray as $k => $v) {
+
+                if(!$v[0]){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称为空,未导入</font><br />";
+                    continue;
+                }
+                $cateId = 0;
+                if(trim($v[1])){
+                   $cateId = Db::name('mate_cate')->where('id',$v[1])->value('id');
+                }
+
+                if(!$v[5]){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型为空,未导入</font><br />";
+                    continue;
+                }
+                $check = Db::name('mate_goods')
+                    ->where('del',0)
+                    ->where('title',$v[0])
+                    ->find();
+                if($check){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,名称已存在,未导入</font><br />";
+                    continue;
+                }
+                if(!isset($a[$v[5]])){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型格式错误,未导入</font><br />";
+                    continue;
+                }
+                $rData = [
+                    'org_id'=>$this->orgId,
+                    'title'=>$v[0],
+                    'cate_id'=>$cateId?$cateId:0,
+                    'unit'=>$v[2],
+                    'brand'=>$v[3],
+                    'spec'=>$v[4],
+                    'type'=>$a[$v[5]],
+                    'remark'=>$v[6],
+                    'create_time'=>getTime(),
+                    'buy_time'=>date('Y-m-d')
+                ];
+                $ret=Db::name('mate_goods')->insert($rData);
+
+                if(!$ret){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,导入失败</font><br />";
+                }else{
+                    echo "<font color=\"green\" style='margin-left:20px;font-size: 17px'>第".($k+1)."行,导入成功</font><br />";
+                }
+
+            }
+        }else{
+            exit('请上传文件');
+        }
+
+    }
+}

+ 65 - 0
application/admin/controller/CompanyGoodsLog.php

@@ -0,0 +1,65 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class CompanyGoodsLog extends Auth
+{
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model = new \app\common\model\MateGoodsLog();
+        $this->table = $this->model->table;
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $goods_id = db('mate_goods')
+                    ->where('title','like','%'.$title.'%')
+                    ->column('id');
+                $map[] = ['goods_id','in',$goods_id];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists =db($this->table)
+                ->where($map)->limit($start,$length)
+                ->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['title'] = db('mate_goods')
+                    ->where('id',$v['goods_id'])
+                    ->value('title');
+                $lists[$k]['userName'] = db('user')
+                    ->where('id',$v['user_id'])
+                    ->value('real_name');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','处置记录');
+            return $this->fetch();
+        }
+    }
+
+
+}

+ 640 - 0
application/admin/controller/Complain.php

@@ -0,0 +1,640 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\model\Config;
+use think\App;
+use think\Db;
+use think\Exception;
+use think\Model;
+
+class Complain extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\Complain();
+        $this->table = 'complain';
+    }
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+            $content = input('content','','trim');
+            if($content){
+                $map[] = ['content','like','%'.$content.'%'];
+            }
+
+            $user = input('user','','trim');
+            if($user != ''){
+                $userIds = Db::name('user')->where('del',0)->where('real_name','like','%'.$user.'%')->column('id');
+                $map[] = ['create_user_id','in',$userIds];
+            }
+
+            $st = input('start','','trim');
+            if($st !=''){
+                $map[] = ['create_time','>=',$st.' 00:00:00'];
+            }
+
+            $et = input('end','','trim');
+            if($et !=''){
+                $map[] = ['create_time','<=',$et.' 23:59:59'];
+            }
+
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+
+            $hour = (new Config())->getConfig('org_complain_hour',$this->orgId);
+            $hour = $hour>0?$hour:0;
+            $endTime = date('Y-m-d H:i:s',time() - $hour*60*60);
+//            $type = input('type/d',0);
+//            if($hour > 0 && $type == 1){
+//                $map[] = ['create_time','<',$endTime];
+//                $map[] = ['status','=',0];
+//            }
+            $from = input('from', '', 'trim');
+            if ($from!='') {
+                if($from == 1){
+                    $map[] = ['order_id','>',0];
+                    $map[] = ['bus_type','<>',0];
+                    $map[] = ['to_from','=',0];
+                }else{
+                    $map[] = ['order_id','>',0];
+                    $map[] = ['bus_type','<>',0];
+                    $map[] = ['to_from','<>',0];
+                }
+            }
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)
+                ->where($map)
+                ->limit($start,$length)
+                ->order($order)
+                ->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['depName'] = Db::name('dep')
+                    ->where('id',$v['dep_id'])
+                    ->value('title');
+//                $lists[$k]['fromName'] =$this->model->from[$v['from']];
+                $lists[$k]['fromName'] = '';
+
+                if($v['order_id'] > 0 && $v['bus_type'] != 0){
+                    if($v['to_from'] == 0){
+                        $lists[$k]['fromName'] = '一键呼叫';
+                    }else{
+                        $lists[$k]['fromName'] = '隐患';
+                    }
+                }
+                $lists[$k]['worktypemode'] = '';
+                if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
+                    $worktype = Db::name('orders')
+                        ->alias('o')
+                        ->join('work_type_mode w','o.work_type_mode = w.id')
+                        ->where('o.id',$v['order_id'])
+                        ->value('w.name');
+                    $lists[$k]['worktypemode'] = $worktype?$worktype:'';
+                }
+
+                if($v['hide'] == 1){
+                    $lists[$k]['realName'] = '匿名';
+                }else{
+                    $lists[$k]['realName'] = Db::name('user')
+                        ->where('id',$v['create_user_id'])
+                        ->value('real_name');
+                }
+
+
+                $orderMode = 0;
+                if($v['order_id'] > 0){
+                    $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
+                }
+
+                $lists[$k]['statusTxt'] = model('Complain')->formatStatus($v['status'],$v['order_id'],$v['id']);
+                $lists[$k]['order_mode'] = $orderMode;
+
+                if($v['create_time'] < $endTime && $v['status']==0){
+                    $lists[$k]['statusTxt'] = $lists[$k]['statusTxt'].'<span style="color:red;">(已超时)</span>';
+                }
+
+            }
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch('index');
+
+        }
+    }
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name($this->table)
+            ->where('id',$id)
+        ->update([
+            'del'=>1,
+            'del_user_id'=>$this->userId,
+            'del_time'=>getTime(),
+        ]);
+        if(!$res){
+            $this->error('删除失败');
+        }
+        $this->success('删除成功');
+    }
+
+    public function edit($id){
+        if(request()->isGet()){
+
+            $this->assign('id',$id);
+            return $this->fetch();
+        }else{
+            $info = Db::name('complain')
+            ->where('id',$id)
+            ->find();
+            if(!$info){
+                $this->error('记录不存在');
+            }
+            if($info['status'] == 1){
+                $this->error('该记录已处理');
+            }
+            $curRoles = Db::name('user_roles')
+                ->where('user_id',$this->userId)
+                ->value('roles_id');
+            $data = array(
+                'curr_roles_id' => $curRoles,
+                'note' => input('note','','trim'),
+                'status' => 1,
+                'update_time' => date('Y-m-d H:i:s'),
+                'hand_user_id' => $this->userId
+            );
+            $res =Db::name('complain')
+                ->where(array('id'=>$id))
+                ->update($data);
+            if($res){
+                model('Complain')->pushCreateUser(0,$info['create_user_id']);
+                $this->success('处理成功');
+            }else{
+                $this->error('处理失败');
+            }
+        }
+    }
+    public function detail($id){
+
+        $info = Db::name('complain')
+            ->where('id',$id)
+            ->find();
+        $info['depName'] = Db::name('dep')
+            ->where('id',$info['dep_id'])
+            ->value('title');
+        if($info['hide']==1){
+            $info['realName'] = '匿名';
+        }else{
+            $info['realName'] = Db::name('user')
+                ->where('id',$info['create_user_id'])
+                ->value('real_name');;
+        }
+//        $info['statusTxt'] = $info['status']==1?'已处理':"未处理";
+        $info['images'] = !empty($info['images'])?explode(',',$info['images']):'';
+
+        $orderMode = 0;
+        if($info['order_id'] > 0){
+            $orderMode = Db::name('orders')->where('id',$info['order_id'])->value('order_mode');
+        }
+
+        $info['statusTxt'] = model('Complain')->formatStatus($info['status'],$info['order_id'],$info['id']);
+        $info['order_mode'] = $orderMode;
+        $comment = Db::name('comment')
+            ->alias('c')
+            ->join('user u','u.id = c.user_id')
+            ->where('c.from_id',$id)
+            ->where('c.type',16)
+            ->field('c.id,c.score,c.content,c.create_time,u.real_name,u.head_image')
+            ->order('c.id desc')
+            ->find();
+        $info['comment'] = $comment?$comment:[];
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+    public function tsDetail($id){
+
+        $info = Db::name('complain')
+            ->where('id',$id)
+            ->find();
+        $info['depName'] = Db::name('dep')
+            ->where('id',$info['dep_id'])
+            ->value('title');
+        if($info['hide']==1){
+            $info['realName'] = '匿名';
+        }else{
+            $info['realName'] = Db::name('user')
+                ->where('id',$info['create_user_id'])
+                ->value('real_name');;
+        }
+//        $info['statusTxt'] = $info['status']==1?'已处理':"未处理";
+        $info['images'] = !empty($info['images'])?explode(',',$info['images']):'';
+
+        $orderMode = 0;
+        if($info['order_id'] > 0){
+            $orderMode = Db::name('orders')->where('id',$info['order_id'])->value('order_mode');
+        }
+
+        $info['statusTxt'] = model('Complain')->formatStatus($info['status'],$info['order_id'],$info['id']);
+        $info['order_mode'] = $orderMode;
+
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+    //派单
+    public function send($id) {
+        if (request()->isGet()) {
+            $this->assign('id', $id);
+            $complainInfo = Db::name($this->table)->where('id',$id)->find();
+            $this->assign('complain',$complainInfo);
+            $order_type = (new \app\common\model\OrderType())->getList();
+            $address = (new \app\common\model\Address())->getListByType(1);
+            $this->assign('order_type_list', $order_type);
+            $this->assign('address_list', $address);
+            $order_repair = Db::name('order_repair')
+                ->where('order_id', $id)
+                ->find();
+            $this->assign('order_repair', $order_repair);
+
+            $workType = Db::name('work_type_mode')
+                ->where('type',1)
+                ->select();
+            $config = Db::name('config')
+                ->where('name','web_order_transfer_type')
+                ->value('value');
+            if(empty($config)){
+                $workType = [];
+            }else{
+                $ll = explode('|',$config);
+                foreach ($workType as $kk=>$vv){
+                    if(!in_array($vv['id'],$ll)){
+                        unset($workType[$kk]);
+                    }
+                }
+            }
+            foreach ($workType as $k=>$v){
+                $this->assign('send_user_num'.$v['id'], model('Orders')->sendUserNum($v['id'], $this->orgId));
+                $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
+                $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
+                $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
+            }
+
+            $this->assign('dispatch_type', check_two_dispatch($this->userId));
+            $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
+            $this->assign('workType', $workType);
+            $address = (new \app\common\model\Address())->getListByType(2);
+            $conveyCate = (new \app\common\model\ConveyCate());
+            $priority = $conveyCate->priority;
+            $order_convey = $conveyCate->getList();
+            $order_device = (new \app\common\model\ConveyDevice())->getList();
+            $this->assign('address', $address);
+            $this->assign('priority', $priority);
+            $this->assign('order_convey_type', $order_convey);
+            $this->assign('order_device', $order_device);
+            $oCid = Db::name('order_convey')
+                ->where('order_id',$id)
+                ->find();
+            $opt = Db::name('order_convey_patient')
+                ->where('order_id',$id)
+                ->find();
+
+            $this->assign('ocid',$oCid);
+            $this->assign('opt',$opt);
+            $this->assign('ps',empty($opt)?1:0);
+            $auths = [1,2,3,4,15,0];
+            if(!is_admin($this->userId)){
+                $auth = get_dispatch_auth($this->userId);
+                if($auth){
+                    $auths = array_intersect($auths,$auth);
+                }else{
+                    $auths = [];
+                }
+            }
+            $this->assign('auths',$auths);
+            return $this->fetch();
+        }
+        else {
+            $data = request()->post();
+            $data['org_id'] = $this->orgId;
+            $res = model('Complain')->send($id, $this->userId, $data);
+
+            if (!$res) {
+                $this->error(model('Complain')->getError());
+            }
+            $this->success('操作成功');
+        }
+    }
+    //转单
+    public function ts_send($id) {
+        if (request()->isGet()) {
+            $this->assign('id', $id);
+            $complainInfo = Db::name($this->table)->where('id',$id)->find();
+            $this->assign('complain',$complainInfo);
+            $order_type = (new \app\common\model\OrderType())->getList();
+            $address = (new \app\common\model\Address())->getListByType(1);
+            $this->assign('order_type_list', $order_type);
+            $this->assign('address_list', $address);
+//            $order_repair = Db::name('order_repair')
+//                ->where('order_id', $id)
+//                ->find();
+            $this->assign('order_repair', []);
+
+            $workType = Db::name('work_type_mode')
+                ->where('type',1)
+                ->select();
+            $config = Db::name('config')
+                ->where('name','web_order_transfer_type')
+                ->value('value');
+            if(empty($config)){
+                $workType = [];
+            }else{
+                $ll = explode('|',$config);
+                foreach ($workType as $kk=>$vv){
+                    if(!in_array($vv['id'],$ll)){
+                        unset($workType[$kk]);
+                    }
+                }
+            }
+            foreach ($workType as $k=>$v){
+                $this->assign('send_user_num'.$v['id'], model('Orders')->sendUserNum($v['id'], $this->orgId));
+                $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
+                $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
+                $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
+            }
+            foreach ($workType as $k=>$v){
+                if($v['id']!==0){
+                    unset($workType[$k]);
+                }
+            }
+            $this->assign('dispatch_type', check_two_dispatch($this->userId));
+            $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
+            $this->assign('workType', $workType);
+            $address = (new \app\common\model\Address())->getListByType(2);
+            $conveyCate = (new \app\common\model\ConveyCate());
+            $priority = $conveyCate->priority;
+            $order_convey = $conveyCate->getList();
+            $order_device = (new \app\common\model\ConveyDevice())->getList();
+            $this->assign('address', $address);
+            $this->assign('priority', $priority);
+            $this->assign('order_convey_type', $order_convey);
+            $this->assign('order_device', $order_device);
+            $oCid = Db::name('order_convey')
+                ->where('order_id',-1)
+                ->find();
+            $opt = Db::name('order_convey_patient')
+                ->where('order_id',-1)
+                ->find();
+
+
+            $this->assign('ocid',$oCid);
+            $this->assign('opt',$opt);
+            $this->assign('ps',empty($opt)?1:0);
+            $auths = [1,2,3,4,15,0];
+            if(!is_admin($this->userId)){
+                $auth = get_dispatch_auth($this->userId);
+                if($auth){
+                    $auths = array_intersect($auths,$auth);
+                }else{
+                    $auths = [];
+                }
+            }
+            $this->assign('auths',$auths);
+            return $this->fetch();
+        }
+        else {
+            $data = request()->post();
+            $data['org_id'] = $this->orgId;
+            $res = model('complain')->zd_send($id, $data,$this->userId);
+            if (!$res) {
+                $this->error(model('complain')->getError());
+            }
+            $this->success('操作成功');
+        }
+    }
+
+    public function summary($id){
+        if(request()->isGet()){
+            $info = Db::name('complain')
+                ->where('id',$id)
+                ->find();
+            $this->assign('info',$info);
+            $this->assign('id',$id);
+            return $this->fetch();
+        }else{
+
+            $data = array(
+                'summary' => input('summary','','trim'),
+                'update_time' => date('Y-m-d H:i:s'),
+            );
+            $res =Db::name('complain')
+                ->where(array('id'=>$id))
+                ->update($data);
+            $res?$this->success('操作成功'):$this->error('操作失败');
+        }
+    }
+
+    public function export(){
+        $meta_title = '投诉订单';
+        if (request()->isGet()) {
+            $content = input('content','','trim');
+            if($content){
+                $map[] = ['content','like','%'.$content.'%'];
+            }
+
+            $user = input('user','','trim');
+            if($user != ''){
+                $userIds = Db::name('user')->where('del',0)->where('real_name','like','%'.$user.'%')->column('id');
+                $map[] = ['create_user_id','in',$userIds];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+
+            $st = input('start','','trim');
+            if($st !=''){
+                $map[] = ['create_time','>=',$st.' 00:00:00'];
+            }
+
+            $et = input('end','','trim');
+            if($et !=''){
+                $map[] = ['create_time','<=',$et.' 23:59:59'];
+            }
+
+            $hour = (new Config())->getConfig('org_complain_hour',$this->orgId);
+            $hour = $hour>0?$hour:0;
+            $endTime = date('Y-m-d H:i:s',time() - $hour*60*60);
+//            $type = input('type/d',0);
+//            if($hour > 0 && $type == 1){
+//                $map[] = ['create_time','<',$endTime];
+//                $map[] = ['status','=',0];
+//            }
+            $from = input('from', '', 'trim');
+            if ($from!='') {
+                if($from == 1){
+                    $map[] = ['order_id','>',0];
+                    $map[] = ['bus_type','<>',0];
+                    $map[] = ['to_from','=',0];
+                }else{
+                    $map[] = ['order_id','>',0];
+                    $map[] = ['bus_type','<>',0];
+                    $map[] = ['to_from','<>',0];
+                }
+            }
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)
+               ->order('id','desc')->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['depName'] = Db::name('dep')
+                    ->where('id',$v['dep_id'])
+                    ->value('title');
+//                $lists[$k]['fromName'] =$this->model->from[$v['from']];
+                $lists[$k]['fromName'] = '';
+                if($v['order_id'] > 0 && $v['bus_type'] != 0){
+                    if($v['to_from'] == 0){
+                        $lists[$k]['fromName'] = '一键呼叫';
+                    }else{
+                        $lists[$k]['fromName'] = '隐患';
+                    }
+                }
+                if($v['hide'] == 1){
+                    $lists[$k]['realName'] = '匿名';
+                }else{
+                    $lists[$k]['realName'] = Db::name('user')
+                        ->where('id',$v['create_user_id'])
+                        ->value('real_name');
+                }
+
+
+                $orderMode = 0;
+                if($v['order_id'] > 0){
+                    $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
+                }
+
+                $lists[$k]['statusTxt'] = model('Complain')->formatStatus($v['status'],$v['order_id'],$v['id']);
+                $lists[$k]['order_mode'] = $orderMode;
+
+//                if($v['create_time'] < $endTime){
+//                    $lists[$k]['statusTxt'] = $lists[$k]['statusTxt'].'<span style="color:red;">(已超时)</span>';
+//                }
+                $lists[$k]['jdsc'] = $v['update_time']?getM1($v['update_time'],$v['create_time']):'';
+                $lists[$k]['clsc'] = $v['finish_time'] && $v['update_time']?getM1($v['finish_time'],$v['update_time']):'';
+
+            }
+            include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+            //实例化PHPExcel类
+            $objPHPExcel = new \PHPExcel();
+            //激活当前的sheet表
+            $objPHPExcel->setActiveSheetIndex(0);
+            //设置表格头(即excel表格的第一行)
+            $objPHPExcel->setActiveSheetIndex(0)
+                ->setCellValue('A1', '编号')
+                ->setCellValue('B1', '时间')
+                ->setCellValue('C1', '处理时间')
+                ->setCellValue('D1', '完成时间')
+                ->setCellValue('E1', '内容')
+                ->setCellValue('F1', '部门')
+                ->setCellValue('G1', '用户')
+                ->setCellValue('H1', '状态')
+                ->setCellValue('I1', '来源')
+                ->setCellValue('J1', '去向')
+                ->setCellValue('K1', '接单反应时长')
+                ->setCellValue('L1', '处理时长');
+            // 设置表格头水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置列水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置单元格宽度
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
+            //循环刚取出来的数组,将数据逐一添加到excel表格。
+            for ($i = 0; $i < count($lists); $i++) {
+                $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['id']);
+                $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
+                $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['update_time']);
+                $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['finish_time']);
+                $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['content']);
+                $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['depName']);
+                $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['realName']);
+                $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['statusTxt']);
+                if($lists[$i]['from'] > 0){
+                    $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), '投诉');
+                }else{
+                    $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), '');
+                }
+                $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['fromName']);
+                $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['jdsc']);
+                $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['clsc']);
+
+            }
+            //设置保存的Excel表格名称
+            $filename = $meta_title.'_' . date('YmdHis', time()) . '.xls';
+            //设置当前激活的sheet表格名称
+            $objPHPExcel->getActiveSheet()->setTitle($meta_title);
+            //设置浏览器窗口下载表格
+            ob_end_clean();
+            header("Content-Type: application/force-download");
+            header("Content-Type: application/octet-stream");
+            header("Content-Type: application/download");
+            header('Content-Disposition:inline;filename="' . $filename);
+            //生成excel文件
+            $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+            //下载文件在浏览器窗口
+            return $objWriter->save('php://output');
+       }
+    }
+}

+ 213 - 0
application/admin/controller/Config.php

@@ -0,0 +1,213 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class Config extends Auth
+{
+    /**
+     * 系统网站设置
+     */
+    public function group($id=1){
+        $type = model('Config')->getConfig('config_group_list');
+        $list = Db::name("config")
+            ->where(['status'=>1,'group'=>$id,'cate'=>1])
+            ->field('id,name,title,extra,value,remark,type')
+            ->order('sort asc')
+            ->select();
+        $list = $list?$list:[];
+        $this->assign('list',$list);
+        $this->assign('id',$id);
+        $this->assign('type',$type);
+        $this->assign('meta_title',$type[$id].'设置');
+        return $this->fetch();
+    }
+
+    /**
+     * 组织配置
+     */
+    public function org($id=1){
+        $type = model('Config')->getConfig('config_org_group_list');
+        $list = Db::name("config")
+            ->where(['status'=>1,'group'=>$id,'cate'=>2])
+            ->field('id,name,title,extra,value,remark,type')
+            ->order('sort asc')
+            ->select();
+        $list = $list?$list:[];
+        $user = model('WorkTypeMode')->getWorkerUserApp($this->orgId);
+        $nuser = [];
+        foreach ($user as $kk=>$vv){
+            $nuser[] = [
+                'id' => $vv['id'],
+                'title' => $vv['real_name']
+            ];
+        }
+        foreach ($list as $k=>$v){
+            $value = Db::name('config_org')->where('config_id',$v['id'])->where('org_id',$this->orgId)->find();
+            $list[$k]['value'] = $value?$value['value']:'';
+            if($v['type'] == 5){ // 工人
+                $list[$k]['user'] = $nuser;
+                $list[$k]['value'] = $list[$k]['value']?explode(',',$list[$k]['value']):[];
+            }
+        }
+        $this->assign('list',$list);
+        $this->assign('type',$type);
+        $this->assign('id',$id);
+        return $this->fetch();
+    }
+
+    /**
+     * 批量保存配置
+     */
+    public function save(){
+        $config = request()->post();
+        if($config && is_array($config)){
+            foreach ($config as $name => $value) {
+                Db::name('config')->where('name',$name)->update(['value' => $value]);
+            }
+        }
+        $this->success('保存成功');
+    }
+
+    /**
+     * 批量保存项目配置
+     */
+    public function orgSave(){
+        $config = request()->post();
+        if($config && is_array($config)){
+            foreach ($config as $name => $value) {
+                $info = Db::name('config')->where('name',$name)->find();
+                if(!$info){
+                    continue;
+                }
+                $oinfo = Db::name('config_org')->where('config_id',$info['id'])->where('org_id',$this->orgId)->find();
+                if($oinfo){
+                    Db::name('config_org')->where('id',$oinfo['id'])->update(['value'=>$value]);
+                }else{
+                    Db::name('config_org')->insert([
+                        'config_id' => $info['id'],
+                        'org_id' => $this->orgId,
+                        'value' => $value
+                    ]);
+                }
+            }
+        }
+        $this->success('保存成功');
+    }
+
+    /**
+     * 配置列表
+     */
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $name = input('name','','trim');
+            $type = input('type','','trim');
+            $cate = input('cate','','trim');
+            $group = input('group','','trim');
+            if($name != ''){
+                $map['name'] = ['like','%'.$name.'%'];
+            }
+            if($type != ''){
+                $map['type'] = $type;
+            }
+            if($group != ''){
+                $map['group'] = $group;
+            }
+            if($cate != ''){
+                $map['cate'] = $cate;
+            }
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('config')
+                ->where($map)
+                ->limit($start,$length)
+                ->order($order)
+                ->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['type'] = model('Config')->getConfigType($v['type']);
+                if($v['cate'] == 1){
+                    $lists[$k]['group'] = model('Config')->getConfigGroup($v['group']);
+                }else{
+                    $lists[$k]['group'] = model('Config')->getConfigOrgGroup($v['group']);
+                }
+            }
+            //数据返回
+            $totalCount = Db::name('config')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $type_list = model('Config')->getConfig('config_type_list');
+            $group_list = model('Config')->getConfig('config_group_list');
+            $this->assign('type_list',$type_list);
+            $this->assign('group_list',$group_list);
+            $this->assign('meta_title','配置列表');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('Config')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('Config')->getError());
+            }
+        }else{
+            $meta_title = '新增配置';
+            if($id){
+                $info = Db::name('config')->where('id',$id)->find();
+                $this->assign('info',$info);
+                $meta_title = '编辑配置';
+            }
+            $type_list = model('Config')->getConfig('config_type_list');
+            $group_list = model('Config')->getConfig('config_group_list');
+
+            $org_group_list = model('Config')->getConfig('config_org_group_list');
+
+            $this->assign('type_list',$type_list);
+            $this->assign('group_list',$group_list);
+            $this->assign('org_group_list',$org_group_list);
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        $name = Db::name('config')->where('id',$id)->value('name');
+        if(!$name){
+            $this->error('该记录不存在');
+        }
+        if(in_array($name,['config_group_list','config_type_list'])){
+            $this->error('该配置不能删除');
+        }
+        $res = Db::name('config')->delete($id);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+
+}

+ 153 - 0
application/admin/controller/ConveyCate.php

@@ -0,0 +1,153 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class ConveyCate extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\ConveyCate();
+        $this->table= $this->model->table;
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)
+                ->order([$sortRow=>$sort,'id'=>'asc'])
+                ->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['cateName'] = $this->model->cate[$v['cate']];
+                $lists[$k]['priorityName'] = $this->model->priority[$v['priority']];
+                $lists[$k]['timeName'] = db('time')
+                    ->where('id',$v['time_id'])->value('title');
+                $lists[$k]['endsName'] =!empty($v['ends'])?implode(',',db('address')
+                    ->whereIn('id',$v['ends'])->column('title')):'';
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name','运送类型');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                if($info){
+                    $info['ends'] = $info['ends']?explode(',',$info['ends']):[];
+                }
+                $this->assign('info',$info);
+            }
+            $time = (new \app\common\model\Time())->getByOrgIdList();
+            $ends = (new \app\common\model\Address())->getListByType(2);
+            $this->assign('time',$time);
+            $this->assign('ends',$ends);
+            $this->assign('cate',$this->model->cate);
+            $this->assign('priority',$this->model->priority);
+            $this->assign('time',$time);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    public function batchSort(){
+        $data = input('data','','trim');
+        if(!$data){
+            $this->error('参数错误');
+        }
+        $data = json_decode($data,true);
+        if(!$data){
+            $this->error('参数错误');
+        }
+
+        Db::startTrans();
+        try{
+            foreach ($data as $k=>$v){
+                Db::name('convey_cate')->where('id',$v['id'])->setField('sort',$v['sort']);
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+}

+ 135 - 0
application/admin/controller/ConveyDevice.php

@@ -0,0 +1,135 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class ConveyDevice extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='convey_device';
+        $this->model= new \app\common\model\ConveyDevice();
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)
+                ->order([$sortRow=>$sort,'id'=>'asc'])
+                ->select();
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function batchSort(){
+        $data = input('data','','trim');
+        if(!$data){
+            $this->error('参数错误');
+        }
+        $data = json_decode($data,true);
+        if(!$data){
+            $this->error('参数错误');
+        }
+
+        Db::startTrans();
+        try{
+            foreach ($data as $k=>$v){
+                Db::name('convey_device')->where('id',$v['id'])->setField('sort',$v['sort']);
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+}

+ 160 - 0
application/admin/controller/ConveyPlan.php

@@ -0,0 +1,160 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class ConveyPlan extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='convey_plan';
+        $this->model= new \app\common\model\ConveyPlan();
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['name','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['real_name'] = Db::name('user')
+                    ->where('id',$v['user_id'])
+                    ->value('real_name');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $info['weeks'] = explode(',',$info['weeks']);
+                $this->assign('info',$info);
+            }
+
+            $options= [
+                [
+                    'id'=>1,
+                    'title'=>'星期一'
+                ],
+
+                [
+                    'id'=>2,
+                    'title'=>'星期二'
+                ],
+                [
+                    'id'=>3,
+                    'title'=>'星期三'
+                ],
+                [
+                    'id'=>4,
+                    'title'=>'星期四'
+                ],
+                [
+                    'id'=>5,
+                    'title'=>'星期五'
+                ],
+                [
+                    'id'=>6,
+                    'title'=>'星期六'
+                ], [
+                    'id'=>0,
+                    'title'=>'星期日'
+                ]
+
+            ];
+            $user = (new \app\common\model\WorkTypeMode())->getRolesUser(3, $this->orgId,1);
+            $newUser = [];
+            foreach ($user as $k => $v) {
+                foreach ($v['user'] as $k1 => $v1) {
+                    $newUser[] = [
+                        'id'=>$v1['id'],
+                        'title'=>$v1['real_name'],
+                    ];
+                }
+            }
+
+            $this->assign('user',$newUser);
+            $this->assign('option',$options);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+}

+ 148 - 0
application/admin/controller/ConveyPlanAddr.php

@@ -0,0 +1,148 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class ConveyPlanAddr extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='convey_plan_addr';
+        $this->model= new \app\common\model\ConveyPlanAddr();
+    }
+    public function index($id){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+
+                $map1[] = ['org_id','=',$this->orgId];
+                $map1[] = ['del','=',0];
+                $map1[] = ['enable','=',1];
+                $map1[] = ['title','like','%'.$title.'%'];
+                $map1[]=['','exp',Db::raw("FIND_IN_SET(2,types)")];
+                $address = Db::name('address')
+                    ->where($map1)
+                    ->column('id');
+                if(empty($address)){
+                    $map[] = ['addr_id','=',0];
+
+                }else{
+                    $map[] = ['addr_id','in',$address];
+
+                }
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['plan_id','=',$id];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)
+                ->limit($start,$length)->order($order)->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['address_title'] = Db::name('address')
+                    ->where('id',$v['addr_id'])
+                    ->value('title');
+                $count = Db::name('convey_plan_record')
+                    ->where('addr_id',$v['addr_id'])
+                    ->where('CREATE_YYYYMMDD',date('Ymd'))
+                    ->count();
+                $lists[$k]['count'] = $count;
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $info = Db::name('convey_plan')
+                ->where('id',$id)
+                ->find();
+            $this->assign('info',$info);
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        $pid = input('pid','');
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                if($info){
+                    $pid = $info['plan_id'];
+                }
+                $this->assign('info',$info);
+            }
+            $address = (new \app\common\model\Address())->getListByType(2,$this->orgId);
+            $this->assign('address',$address);
+            $this->assign('pid',$pid);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+}

+ 225 - 0
application/admin/controller/ConveyPlanRecord.php

@@ -0,0 +1,225 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class ConveyPlanRecord extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table = 'convey_plan_record';
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('real_name','','trim');
+            if($title){
+                 $user = Db::name('user')
+                     ->alias('u')
+                     ->join('user_org o','o.user_id=u.id')
+                     ->where('u.del',0)
+                     ->where('u.enable',1)
+                     ->where('u.real_name','like','%'.$title.'%')
+                     ->where('o.org_id',$this->orgId)
+                     ->column('u.id');
+                 if(empty($user)){
+                     $map[] = ['user_id','=',0];
+                 }else{
+                     $map[] = ['user_id','in',$user];
+
+                 }
+            }
+
+            $addr = input('addr','','trim');
+            if($addr){
+                $map[] = ['addr_id','=',$addr];
+
+            }
+            $s = input('start','','trim');
+            if($s){
+                $ss = date('Ymd',strtotime($s));
+                $map[] = ['create_yyyymmdd','>=',$ss];
+            }
+            $e = input('end','','trim');
+            if($e){
+                $ee = date('Ymd',strtotime($e));
+                $map[] = ['create_yyyymmdd','<=',$ee];
+            }
+
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['real_name'] = Db::name('user')
+                    ->where('id',$v['user_id'])
+                    ->value('real_name');
+                $lists[$k]['address_title'] = Db::name('address')
+                    ->where('id',$v['addr_id'])
+                    ->value('title');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            $address = (new \app\common\model\Address())->getListByType(2,$this->orgId);
+            $this->assign('address',$address);
+            return $this->fetch();
+        }
+    }
+
+
+    //excel导出
+    public function export() {
+        $meta_title = '循环签到记录';
+        if (request()->isGet()) {
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('real_name','','trim');
+            if($title){
+                $user = Db::name('user')
+                    ->alias('u')
+                    ->join('user_org o','o.user_id=u.id')
+                    ->where('u.del',0)
+                    ->where('u.enable',1)
+                    ->where('u.real_name','like','%'.$title.'%')
+                    ->where('o.org_id',$this->orgId)
+                    ->column('u.id');
+                if(empty($user)){
+                    $map[] = ['user_id','=',0];
+                }else{
+                    $map[] = ['user_id','in',$user];
+
+                }
+            }
+
+            $addr = input('addr','','trim');
+            if($addr){
+                $map[] = ['addr_id','=',$addr];
+
+            }
+            $s = input('start','','trim');
+            if($s){
+                $ss = date('Ymd',strtotime($s));
+                $map[] = ['create_yyyymmdd','>=',$ss];
+            }
+            $e = input('end','','trim');
+            if($e){
+                $ee = date('Ymd',strtotime($e));
+                $map[] = ['create_yyyymmdd','<=',$ee];
+            }
+
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->order($order)->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['real_name'] = Db::name('user')
+                    ->where('id',$v['user_id'])
+                    ->value('real_name');
+                $lists[$k]['address_title'] = Db::name('address')
+                    ->where('id',$v['addr_id'])
+                    ->value('title');
+            }
+            include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+            //实例化PHPExcel类
+            $objPHPExcel = new \PHPExcel();
+            //激活当前的sheet表
+            $objPHPExcel->setActiveSheetIndex(0);
+            //设置表格头(即excel表格的第一行)
+            $objPHPExcel->setActiveSheetIndex(0)
+                ->setCellValue('A1', 'id')
+                ->setCellValue('B1', '签到人')
+                ->setCellValue('C1', '位置')
+                ->setCellValue('D1', '时间');
+            // 设置表格头水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置列水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置单元格宽度
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
+            //循环刚取出来的数组,将数据逐一添加到excel表格。
+            for ($i = 0; $i < count($lists); $i++) {
+                $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['id']);
+                $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['real_name']);
+                $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['address_title']);
+                $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['create_time']);
+            }
+            //设置保存的Excel表格名称
+            $filename = $meta_title.'_' . date('YmdHis', time()) . '.xls';
+            //设置当前激活的sheet表格名称
+            $objPHPExcel->getActiveSheet()->setTitle($meta_title);
+            //设置浏览器窗口下载表格
+            ob_end_clean();
+            header("Content-Type: application/force-download");
+            header("Content-Type: application/octet-stream");
+            header("Content-Type: application/download");
+            header('Content-Disposition:inline;filename="' . $filename);
+            //生成excel文件
+            $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+            //下载文件在浏览器窗口
+            return $objWriter->save('php://output');
+        }
+
+    }
+
+
+
+}

+ 223 - 0
application/admin/controller/ConveyStatistics.php

@@ -0,0 +1,223 @@
+<?php
+namespace app\admin\controller;
+
+
+use think\Db;
+use think\Exception;
+
+
+class ConveyStatistics extends Auth
+{
+
+    public function urgencyOrder(){
+        $start = input('start',date('Y-m-d',strtotime('-1 month')));
+        $end = input('end',date('Y-m-d'));
+
+        $rolesId = Db::name('roles')
+            ->whereIn('parent_id',6)
+            ->where('del',0)
+            ->where('type',1)
+            ->where('enable',1)
+            ->where('org_id',$this->orgId)
+            ->column('id');
+        $user = Db::name('user')
+            ->alias('u')
+            ->field('u.*')
+            ->join('user_roles ur','ur.user_id=u.id')
+            ->whereIn('ur.roles_id',$rolesId)
+            ->where('u.del',0)
+            ->where('u.enable',1)
+            ->select();
+
+        $data = [];
+        foreach ($user as $k=>$v){
+            $data[$k]['user_name'] = $v['real_name'];
+            $count = Db::name('todo')
+                ->alias('t')
+                ->join('order_convey oc','oc.order_id=t.order_id')
+                ->where('t.to_user_id',$v['id'])
+                ->where('t.org_id',$this->orgId)
+                ->where('t.del',0)
+                ->where('t.work_type_mode',3)
+                ->where('t.todo_mode',3)
+                ->where('t.create_yyyymmdd','>=',date('Ymd',strtotime($start)))
+                ->where('t.create_yyyymmdd','<=',date('Ymd',strtotime($end)))
+                ->where('oc.priority',3)
+                ->count();
+            $data[$k]['count'] = $count;
+
+            $list = Db::name('todo')
+                ->alias('t')
+                ->field('t.id,t.order_id,t.done_time,oc.ywc_time')
+                ->join('order_convey oc','oc.order_id=t.order_id')
+                ->where('t.to_user_id',$v['id'])
+                ->where('t.org_id',$this->orgId)
+                ->where('t.del',0)
+                ->where('t.work_type_mode',3)
+                ->where('t.todo_mode',3)
+                ->where('t.create_yyyymmdd','>=',date('Ymd',strtotime($start)))
+                ->where('t.create_yyyymmdd','<=',date('Ymd',strtotime($end)))
+                ->where('oc.priority',3)
+                ->select();
+            $hg = 0;
+            foreach ($list as $kk=>$vv){
+                if($vv['done_time'] && $vv['ywc_time'] >= $vv['done_time']){
+                    $hg+=1;
+                }
+            }
+            $data[$k]['hg_num'] = $hg;
+            $data[$k]['no_hg_num'] = $count -$hg;
+            if($count > 0){
+                $bl = round($hg/$count*100,2).'%';
+            }else{
+                $bl = '0%';
+            }
+            $data[$k]['bl'] = $bl;
+        }
+
+        $this->assign('data',$data);
+
+
+        $this->assign('start',$start);
+        $this->assign('end',$end);
+        return $this->fetch();
+    }
+
+
+    public function urgencyOrderExport(){
+
+        $start = input('start',date('Y-m-d',strtotime('-1 month')));
+        $end = input('end',date('Y-m-d'));
+
+        $rolesId = Db::name('roles')
+            ->whereIn('parent_id',6)
+            ->where('del',0)
+            ->where('type',1)
+            ->where('enable',1)
+            ->where('org_id',$this->orgId)
+            ->column('id');
+        $user = Db::name('user')
+            ->alias('u')
+            ->field('u.*')
+            ->join('user_roles ur','ur.user_id=u.id')
+            ->whereIn('ur.roles_id',$rolesId)
+            ->where('u.del',0)
+            ->where('u.enable',1)
+            ->select();
+
+        $data = [];
+        foreach ($user as $k=>$v){
+            $data[$k]['user_name'] = $v['real_name'];
+            $count = Db::name('todo')
+                ->alias('t')
+                ->join('order_convey oc','oc.order_id=t.order_id')
+                ->where('t.to_user_id',$v['id'])
+                ->where('t.org_id',$this->orgId)
+                ->where('t.del',0)
+                ->where('t.work_type_mode',3)
+                ->where('t.todo_mode',3)
+                ->where('t.create_yyyymmdd','>=',date('Ymd',strtotime($start)))
+                ->where('t.create_yyyymmdd','<=',date('Ymd',strtotime($end)))
+                ->where('oc.priority',3)
+                ->count();
+            $data[$k]['count'] = $count;
+
+            $list = Db::name('todo')
+                ->alias('t')
+                ->field('t.id,t.order_id,t.done_time,oc.ywc_time')
+                ->join('order_convey oc','oc.order_id=t.order_id')
+                ->where('t.to_user_id',$v['id'])
+                ->where('t.org_id',$this->orgId)
+                ->where('t.del',0)
+                ->where('t.work_type_mode',3)
+                ->where('t.todo_mode',3)
+                ->where('t.create_yyyymmdd','>=',date('Ymd',strtotime($start)))
+                ->where('t.create_yyyymmdd','<=',date('Ymd',strtotime($end)))
+                ->where('oc.priority',3)
+                ->select();
+            $hg = 0;
+            foreach ($list as $kk=>$vv){
+                if($vv['done_time'] && $vv['ywc_time'] >= $vv['done_time']){
+                    $hg+=1;
+                }
+            }
+            $data[$k]['hg_num'] = $hg;
+            $data[$k]['no_hg_num'] = $count -$hg;
+            if($count > 0){
+                $bl = round($hg/$count*100,2).'%';
+            }else{
+                $bl = '0%';
+            }
+            $data[$k]['bl'] = $bl;
+        }
+
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+        //实例化PHPExcel类
+        $objPHPExcel =new \PHPExcel();
+        //激活当前的sheet表
+        $objPHPExcel->setActiveSheetIndex(0);
+        //设置表格头(即excel表格的第一行)
+        $objPHPExcel->setActiveSheetIndex(0)
+            ->setCellValue('A1', '姓名')
+            ->setCellValue('B1', '总数')
+            ->setCellValue('C1', '合格数')
+            ->setCellValue('D1', '不合格数')
+            ->setCellValue('E1', '合格率');
+        // 设置表格头水平居中
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+
+        //设置列水平居中
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+
+        //设置单元格宽度
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(30);
+
+
+        //循环刚取出来的数组,将数据逐一添加到excel表格。
+        for ($i = 0; $i < count($data); $i++) {
+            $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $data[$i]['user_name']);
+            $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $data[$i]['count']);
+            $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $data[$i]['hg_num']);
+            $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $data[$i]['no_hg_num']);
+            $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $data[$i]['bl']);
+
+        }
+        //设置保存的Excel表格名称
+        $filename = '运送急查订单统计报表_' . date('YmdHis', time()) . '.xls';
+        //设置当前激活的sheet表格名称
+        $objPHPExcel->getActiveSheet()->setTitle('运送急查订单统计报表');
+        //设置浏览器窗口下载表格
+        ob_end_clean();
+        header("Content-Type: application/force-download");
+        header("Content-Type: application/octet-stream");
+        header("Content-Type: application/download");
+        header('Content-Disposition:inline;filename="' . $filename);
+        //生成excel文件
+        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+        //下载文件在浏览器窗口
+        return $objWriter->save('php://output');
+    }
+
+}

+ 311 - 0
application/admin/controller/Daily.php

@@ -0,0 +1,311 @@
+<?php
+
+namespace app\admin\controller;
+use think\App;
+use think\Db;
+
+class Daily extends Auth {
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model = new \app\common\model\Daily();
+    }
+    public function index() {
+        if (request()->isAjax()) {
+            //分页参数
+            $length = input('rows', 10, 'intval');   //每页条数
+            $page = input('page', 1, 'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx', 'sort', 'trim');      //排序列
+            $sort = input('sord', 'asc', 'trim');        //排序方式
+            $order = $sortRow . ' ' . $sort . ' ,id desc';
+            $title = input('title', '', 'trim');
+            if ($title) {
+                $map[] = ['title', 'like', '%' . $title . '%'];
+            }
+            $enable = input('enable', '', 'trim');
+            if ($enable != '') {
+                $map[] = ['enable', '=', $enable];
+            }
+            $map[] = ['org_id', '=', $this->orgId];
+            $map[] = ['del', '=', 0];
+            $map = empty($map) ? true : $map;
+            //数据查询
+            $lists = Db::name('daily')->where($map)->limit($start, $length)->order($order)->select();
+//            foreach ($lists as $k => $v) {
+//                $rolesName = $this->model->getRoles($v['roles']);
+//                $lists[$k]['user_name'] = implode(',', $rolesName);
+//            }
+            //数据返回
+            $totalCount = Db::name('daily')->where($map)->count();
+            $totalPage = ceil($totalCount / $length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }
+        else {
+            $this->assign('meta_title', '任务列表');
+            return $this->fetch();
+        }
+    }
+    /**
+     * 新增/编辑
+     */
+    public function add($id = 0) {
+        if (request()->isPost()) {
+            $model = $this->model;
+            $res = $model->updates();
+            if ($res) {
+                $this->success('操作成功', url('index'));
+            }
+            else {
+                $this->error($model->getError());
+            }
+        }
+        else {
+            $meta_title = '新增工作地点';
+            $formModel = new \app\common\model\DailyForm();
+            if ($id) {
+                $info = Db::name('daily')->where('id', $id)->find();
+                $info['daily_form'] = $formModel->getByIdList($info['daily_form']);
+              //  $info['roles'] = explode(',', $info['roles']);
+                $this->assign('info', $info);
+                $daily_user = Db::name('daily_user')
+                    ->where('daily_id',$info['id'])->column('user_id');
+                $info['daily_user'] = isset($daily_user)?implode(',',$daily_user):'';
+                $this->assign('info',$info);
+                $meta_title = '编辑工作地点';
+            }
+            //获取检查项
+            $dailyForm = $formModel->list();
+            //角色
+            $roles = $this->model->getRolesList();
+            $dailyUser = model('WorkTypeMode')->getRolesUser(9,cur_org_id());
+            $this->assign('daily_form', $dailyForm);
+            $this->assign('dailyUser',$dailyUser);
+            $this->assign('meta_title', $meta_title);
+            $this->assign('send_user_num',0);
+            return $this->fetch();
+        }
+    }
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id = 0) {
+        if (!$id) {
+            $this->error('参数错误');
+        }
+        $res = Db::name('daily')->where('id', $id)->update(['del' => 1]);
+        if ($res) {
+            $this->success('删除成功');
+        }
+        else {
+            $this->error('删除失败');
+        }
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id = 0, $fn = '', $fv = 0) {
+        if (!$fn || !$id) {
+            $this->error('参数错误');
+        }
+        $res = Db::name('daily')->where('id', $id)->update([$fn => $fv]);
+        if ($res) {
+            $this->success('操作成功');
+        }
+        else {
+            $this->error('操作失败');
+        }
+    }
+    //二维码
+    public function qrcode($id = 0) {
+        $info = Db::name('daily')->where('id', $id)->find();
+        if (!$info) {
+            exit('数据不存在');
+        }
+        $code = get_qrcode_str('daily', $id);
+        $this->assign('code', $code);
+        $this->assign('info', $info);
+        return $this->fetch();
+    }
+    public function allPrint(){
+        $ids = input('ids');
+        if(!$ids){
+            $list = Db::name('daily')
+                ->where('org_id',cur_org_id())
+                ->where('enable',1)
+                ->where('del',0)
+                ->select();
+        }else{
+            $ids = explode(',',$ids);
+            $list = Db::name('daily')
+                ->where('org_id',cur_org_id())
+                ->where('enable',1)
+                ->where('id','in',$ids)
+                ->where('del',0)
+                ->select();
+        }
+
+        foreach ($list as $k=>$v){
+            $list[$k]['qCode'] = get_qrcode_str('daily',$v['id']);
+        }
+
+        $this->assign('list',$list);
+        return $this->fetch();
+
+    }
+
+    public function group() {
+
+        $title = input('title', '', 'trim');
+        if ($title) {
+            $map[] = ['title', 'like', '%' . $title . '%'];
+        }
+        $map[] = ['enable', '=', 1];
+        $map[] = ['org_id', '=', $this->orgId];
+        $map[] = ['del', '=', 0];
+        $lists = Db::name('daily')->where($map)->field('id,title')->order('id desc')->select();
+        $hours = model('Daily')->getTimeDaily($this->orgId);
+        foreach ($lists as $k=>$v){
+            $users = Db::name('daily_user')
+                ->alias('du')
+                ->join('user u','u.id = du.user_id')
+                ->where('du.daily_id',$v['id'])
+                ->column('real_name');
+            $users = $users?$users:[];
+            $lists[$k]['users'] = $users?implode(',',$users):'';
+            $m = [];
+            $m[] = ['org_id','=',$this->orgId];
+            $m[] = ['daily_id','=',$v['id']];
+            $m[] = ['create_time','>=',$hours['start']];
+            $m[] = ['create_time','<',$hours['end']];
+            $count = Db::name('daily_record')->where($m)->count();
+            $lists[$k]['count'] = $count;
+
+            $lists[$k]['zc'] = 0;
+            if($count > 0){
+                $lists[$k]['zc'] = 1;
+            }
+            $m[] = ['order_id','>',0];
+            $orderIds = Db::name('daily_record')->where($m)->column('order_id');
+            if($orderIds){
+                $res = Db::name('orders')->where('id','in',$orderIds)->where('del',0)->where('order_mode','in',[1,4])->find();
+                if($res){
+                    $lists[$k]['zc'] = 2;
+                }
+            }
+        }
+        $this->assign('hours',$hours);
+        $this->assign('lists',$lists);
+        return $this->fetch();
+    }
+
+    public function record($id=0,$s='',$e='') {
+        if (request()->isAjax()) {
+            //分页参数
+            $length = input('rows', 10, 'intval');   //每页条数
+            $page = input('page', 1, 'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            $order = 'id desc';
+            $map[] = ['dr.daily_id','=',$id];
+            $map[] = ['dr.create_time','>=',$s];
+            $map[] = ['dr.create_time','<',$e];
+            $map[] = ['dr.org_id', '=', $this->orgId];
+            $map = empty($map) ? true : $map;
+            //数据查询
+            $lists = Db::name('daily_record')
+                ->alias('dr')
+                ->join('daily d', 'd.id=dr.daily_id')
+                ->field('dr.*,d.title,d.content as daily_details')
+                ->where($map)
+                ->limit($start, $length)
+                ->order($order)
+                ->select();
+            foreach ($lists as $k => $v) {
+                $lists[$k]['user_name'] = Db::name('user')
+                    ->where('id', $v['user_id'])
+                    ->value('real_name');
+                $lists[$k]['zc'] = 0;
+                if($v['order_id'] > 0){
+                    $lists[$k]['zc'] = 1;
+                    $res = Db::name('orders')->where('id',$v['order_id'])->where('del',0)->where('order_mode','in',[1,4])->find();
+                    if($res){
+                        $lists[$k]['zc'] = 2;
+                    }
+                }
+            }
+            //数据返回
+            $totalCount = Db::name('daily_record')
+                ->alias('dr')
+                ->field('dr.*,d.title,d.content as daily_details')
+                ->join('daily d', 'd.id=dr.daily_id')
+                ->where($map)->count();
+            $totalPage = ceil($totalCount / $length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        } else {
+            $this->assign('id',$id);
+            $this->assign('s',$s);
+            $this->assign('e',$e);
+            $this->assign('meta_title', '检查记录列表');
+            return $this->fetch();
+        }
+    }
+
+    public function addrdown(){
+        $orgid = $this->orgId;
+        $map[] = ['del','=',0];
+        $map[] = ['org_id','=',$this->orgId];
+        $map= empty($map) ? true: $map;
+        //数据查询
+        $lists = db('daily')->where($map)->select();
+
+        foreach ($lists as $k=>$v){
+            $lists[$k]['code'] = get_qrcode_str('daily',$v['id']);
+        }
+        $path = date('Ymd').'_'.$orgid.'_'.time().mt_rand(1000,9999);
+        $dir = './uploads/qrcodeimg/'.$path.'/';
+
+        foreach ($lists as $v1){
+            $name = $v1['title'].'('.$v1['id'].')'.'.jpg';
+            $filepath = $dir.'/'.$name;
+            create_qrcode($v1['code'],$filepath);
+        }
+
+        $zippath = './uploads/qrcodeimg/'.$path.'.zip';
+        $spath = $dir;
+        @unlink($zippath);
+        $zip = new \ZipArchive();
+        if($zip->open($zippath, \ZipArchive::CREATE)=== TRUE){
+            add_file_to_zip($spath,$zip); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
+            $zip->close(); //关闭处理的zip文件
+            if(!file_exists($zippath)){
+                $this->error("打包失败"); //即使创建,仍有可能失败。。。。
+            }
+
+            deldir($dir); // 删除生成的目录
+
+            $downname = session('orgName').'日常工作地点二维码.zip';
+            header("Cache-Control: public");
+            header("Content-Description: File Transfer");
+            header('Content-disposition: attachment; filename='.$downname); //文件名
+            header("Content-Type: application/zip"); //zip格式的
+            header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
+            header('Content-Length: '. filesize($zippath)); //告诉浏览器,文件大小
+            @readfile($zippath);
+
+        }else{
+            $this->error("打包失败");
+        }
+    }
+}

+ 110 - 0
application/admin/controller/DailyForm.php

@@ -0,0 +1,110 @@
+<?php
+
+namespace app\admin\controller;
+use think\App;
+use think\Db;
+
+class DailyForm extends Auth {
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model = new \app\common\model\DailyForm();
+    }
+    public function index() {
+        if (request()->isAjax()) {
+            //分页参数
+            $length = input('rows', 10, 'intval');   //每页条数
+            $page = input('page', 1, 'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx', 'sort', 'trim');      //排序列
+            $sort = input('sord', 'asc', 'trim');        //排序方式
+            $order = $sortRow . ' ' . $sort . ' ,id desc';
+            $title = input('content', '', 'trim');
+            if ($title) {
+                $map[] = ['content', 'like', '%' . $title . '%'];
+            }
+            $enable = input('enable', '', 'trim');
+            if ($enable != '') {
+                $map[] = ['enable', '=', $enable];
+            }
+            $map[] = ['org_id', '=', $this->orgId];
+            $map[] = ['del', '=', 0];
+            $map = empty($map) ? true : $map;
+            //数据查询
+            $lists = Db::name('daily_form')
+                ->where($map)->limit($start, $length)->order($order)->select();
+            //数据返回
+            $totalCount = Db::name('daily_form')->where($map)->count();
+            $totalPage = ceil($totalCount / $length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }
+        else {
+            $this->assign('meta_title', '工作项列表');
+            $this->assign('m_name', '工作项');
+            return $this->fetch();
+        }
+    }
+    /**
+     * 新增/编辑
+     */
+    public function add($id = 0) {
+        if (request()->isPost()) {
+            $model = $this->model;
+            $res = $model->updates();
+            if ($res) {
+                $this->success('操作成功', url('index'));
+            }
+            else {
+                $this->error($model->getError());
+            }
+        }
+        else {
+            $meta_title = '新增工作项';
+            if ($id) {
+                $info = Db::name('daily_form')->where('id', $id)->find();
+                $this->assign('info', $info);
+                $meta_title = '编辑工作项';
+            }
+            $this->assign('meta_title', $meta_title);
+            return $this->fetch();
+        }
+    }
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id = 0) {
+        if (!$id) {
+            $this->error('参数错误');
+        }
+        $res = Db::name('daily_form')->where('id', $id)->update(['del' => 1]);
+        if ($res) {
+            $this->success('删除成功');
+        }
+        else {
+            $this->error('删除失败');
+        }
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id = 0, $fn = '', $fv = 0) {
+        if (!$fn || !$id) {
+            $this->error('参数错误');
+        }
+        $res = Db::name('daily_form')->where('id', $id)->update([$fn => $fv]);
+        if ($res) {
+            $this->success('操作成功');
+        }
+        else {
+            $this->error('操作失败');
+        }
+    }
+}

+ 214 - 0
application/admin/controller/DailyRecord.php

@@ -0,0 +1,214 @@
+<?php
+
+namespace app\admin\controller;
+use think\Db;
+
+class DailyRecord extends Auth {
+    public function index() {
+        if (request()->isAjax()) {
+            //分页参数
+            $length = input('rows', 10, 'intval');   //每页条数
+            $page = input('page', 1, 'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx', 'sort', 'trim');      //排序列
+            $sort = input('sord', 'asc', 'trim');        //排序方式
+            $order = $sortRow . ' ' . $sort . ' ,id desc';
+            $title = input('title', '', 'trim');
+            if ($title) {
+                $map[] = ['d.title', 'like', '%' . $title . '%'];
+            }
+            $map[] = ['dr.org_id', '=', $this->orgId];
+            $map = empty($map) ? true : $map;
+            //数据查询
+            $lists = Db::name('daily_record')
+                ->alias('dr')
+                ->join('daily d', 'd.id=dr.daily_id')
+                ->field('dr.*,d.title,d.content as daily_details')
+                ->where($map)
+                ->limit($start, $length)
+                ->order($order)
+                ->select();
+            foreach ($lists as $k => $v) {
+                $lists[$k]['user_name'] = Db::name('user')
+                    ->where('id', $v['user_id'])
+                    ->value('real_name');
+                $status = 0;
+                if($v['order_id'] > 0 ){
+                    $order =  Db::name('orders')
+                        ->where('id',$v['order_id'])
+                        ->where('quality_type',0)
+                        ->whereIn('order_mode',[5,6])->where('del',0)->find();
+
+                    if($order){
+                        $status = 2;
+                    }else{
+                        $status = 1;
+                    }
+                }
+                $lists[$k]['zg_type'] = $status;
+            }
+            //数据返回
+            $totalCount = Db::name('daily_record')
+                ->alias('dr')
+                ->field('dr.*,d.title,d.content as daily_details')
+                ->join('daily d', 'd.id=dr.daily_id')
+                ->where($map)->count();
+            $totalPage = ceil($totalCount / $length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }
+        else {
+            $this->assign('meta_title', '检查记录列表');
+            return $this->fetch();
+        }
+    }
+    public function details($id) {
+        if (!$id) {
+            $this->error('参数错误');
+        }
+        $ret = Db::name('daily_record')->where('id', $id)->find();
+        $daily = Db::name('daily')->field('title,content')
+            ->where('id', $ret['daily_id'])->find();
+        $ret['daily_name'] = $daily['title'];
+        $ret['images'] = $ret['images']?explode(',',$ret['images']):[];
+        $ret['daily_details'] = $daily['content'];
+        $ret['check_json'] = json_decode($ret['check_json'], true);
+        $ret['user_name'] = Db::name('user')
+            ->where('id', $ret['user_id'])->value('real_name');
+        $status = 0;
+        if($ret['order_id'] > 0 ){
+            $order =  Db::name('orders')
+                ->where('id',$ret['order_id'])
+                ->where('quality_type',0)
+                ->whereIn('order_mode',[5,6])->where('del',0)->find();
+
+            if($order){
+                $status = 2;
+            }else{
+                $status = 1;
+            }
+        }
+        $ret['zg_type'] = $status;
+        $this->assign('info', $ret);
+        $this->assign('meta_title', '日常工作记录详情');
+        return $this->fetch();
+    }
+    //excel导出
+    public function export() {
+        $meta_title = '日常工作记录';
+        if (request()->isPost()) {
+            $start = input('start');
+            $end = input('end');
+            $where[] = ['create_yyyymmdd', '>=', $start];
+            $where[] = ['create_yyyymmdd', '<=', $end];
+            $where[] = ['org_id', '=', $this->orgId];
+            $ret = Db::name('daily_record')->where($where)->select();
+            foreach ($ret as $k => $v) {
+                $daily = Db::name('daily')
+                    ->field('title,content')->where('id', $v['daily_id'])->find();
+                $ret[$k]['user_name'] = Db::name('user')->where('id', $v['user_id'])->value('real_name');
+                $ret[$k]['daily_name'] = $daily['title'];
+                $ret[$k]['daily_details'] = $daily['content'];
+            }
+            include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+            //实例化PHPExcel类
+            $objPHPExcel = new \PHPExcel();
+            //激活当前的sheet表
+            $objPHPExcel->setActiveSheetIndex(0);
+            //设置表格头(即excel表格的第一行)
+            $objPHPExcel->setActiveSheetIndex(0)
+                ->setCellValue('A1', '编号')
+                ->setCellValue('B1', '任务地点名称')
+                ->setCellValue('C1', '任务详情')
+                ->setCellValue('D1', '工作人员')
+                ->setCellValue('E1', '时间')
+                ->setCellValue('F1', '内容')
+                ->setCellValue('G1', '工作表单');
+            // 设置表格头水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置列水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置单元格宽度
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(50);
+            //循环刚取出来的数组,将数据逐一添加到excel表格。
+            for ($i = 0; $i < count($ret); $i++) {
+                $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['id']);//ID
+                $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['daily_name']);//日常工作名称
+                $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['daily_details']);//日常工作详情
+                $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $ret[$i]['user_name']);//工作人员
+                $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $ret[$i]['create_time']);//时间
+                $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $ret[$i]['content']);//content
+                $result = json_decode($ret[$i]['check_json'], true);
+                $str = array();
+                foreach ($result as $kk => $vv) {
+                    $ss = $vv['title'] . ":";
+                    if ($vv['result'] == 1) {
+                        $ss .= '☑';
+                    }
+                    else {
+                        $ss .= '□';
+                    }
+                    $str[] = $ss;
+                }
+                $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), implode(' ; ', $str));//工作项
+            }
+            //设置保存的Excel表格名称
+            $filename = '日常工作记录_' . date('YmdHis', time()) . '.xls';
+            //设置当前激活的sheet表格名称
+            $objPHPExcel->getActiveSheet()->setTitle('日常工作记录');
+            //设置浏览器窗口下载表格
+            ob_end_clean();
+            header("Content-Type: application/force-download");
+            header("Content-Type: application/octet-stream");
+            header("Content-Type: application/download");
+            header('Content-Disposition:inline;filename="' . $filename);
+            //生成excel文件
+            $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+            //下载文件在浏览器窗口
+            return $objWriter->save('php://output');
+        }
+        $this->assign('meta_title', $meta_title);
+        return $this->fetch();
+    }
+}

+ 126 - 0
application/admin/controller/DailyStatistics.php

@@ -0,0 +1,126 @@
+<?php
+
+namespace app\admin\controller;
+use think\App;
+use think\Db;
+
+class DailyStatistics extends Auth {
+    public function work() {
+        $cur = date('Y-m-d');
+        $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
+        $end = input('end', date('Y-m-d'));
+        $start1 = $start . ' 00:00:00';
+        $end1 = $end . ' 00:00:00';
+        $list = $this->workData($start1, $end1);
+        $this->assign('list', $list);
+        $this->assign('start', $start);
+        $this->assign('end', $end);
+        return $this->fetch();
+    }
+    public function workData($start1, $end1) {
+        $map1[] = ['create_time', '>=', $start1];
+        $map1[] = ['create_time', '<=', $end1];
+        $map[] = ['org_id', '=', $this->orgId];
+        $list = Db::name('daily_record')
+            ->where($map)
+            ->group('user_id')
+            ->select();
+        foreach ($list as $k => $v) {
+            $list[$k]['real_name'] = Db::name('user')
+                ->where('id', $v['user_id'])
+                ->value('real_name');
+            $count = Db::name('daily_record')
+                ->where($map)
+                ->where('user_id', $v['user_id'])
+                ->where($map1)
+                ->count();
+            $list[$k]['count'] = $count ? $count : 0;
+        }
+        return $list;
+    }
+    public function workExport() {
+        $cur = date('Y-m-d');
+        $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
+        $end = input('end', date('Y-m-d'));
+        $start1 = $start . ' 00:00:00';
+        $end1 = $end . ' 00:00:00';
+        $ret = $this->workData($start1, $end1);
+        include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
+        //实例化PHPExcel类
+        $objPHPExcel = new \PHPExcel();
+        //激活当前的sheet表
+        $objPHPExcel->setActiveSheetIndex(0);
+        //设置表格头(即excel表格的第一行)
+        $objPHPExcel->setActiveSheetIndex(0)
+            ->setCellValue('A1', 'ID')
+            ->setCellValue('B1', '姓名')
+            ->setCellValue('C1', '工作记录');
+        // 设置表格头水平居中
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        //设置列水平居中
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        //设置单元格宽度
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
+        //循环刚取出来的数组,将数据逐一添加到excel表格。
+        for ($i = 0; $i < count($ret); $i++) {
+            $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['id']);
+            $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['real_name']);
+            $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['count']);
+        }
+        //设置保存的Excel表格名称
+        $filename = '日常工人工作量统计_' . date('YmdHis', time()) . '.xls';
+        //设置当前激活的sheet表格名称
+        $objPHPExcel->getActiveSheet()->setTitle('日常工人工作量统计');
+        //设置浏览器窗口下载表格
+        ob_end_clean();
+        header("Content-Type: application/force-download");
+        header("Content-Type: application/octet-stream");
+        header("Content-Type: application/download");
+        header('Content-Disposition:inline;filename="' . $filename);
+        //生成excel文件
+        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+        //下载文件在浏览器窗口
+        return $objWriter->save('php://output');
+    }
+    public function daily() {
+        $cur = date('Y-m-d');
+        $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
+        $end = input('end', date('Y-m-d'));
+        $start1 = $start . ' 00:00:00';
+        $end1 = $end . ' 00:00:00';
+        $map1[] = ['create_time', '>=', $start1];
+        $map1[] = ['create_time', '<=', $end1];
+        $map[] = ['org_id', '=', $this->orgId];
+        $list = Db::name('daily_record')
+            ->where($map)
+            ->group('daily_id')
+            ->select();
+        foreach ($list as $k => $v) {
+            $list[$k]['title'] = Db::name('daily')
+                ->where('id', $v['daily_id'])
+                ->value('title');
+            $count = Db::name('daily_record')
+                ->where($map)
+                ->where('daily_id', $v['daily_id'])
+                ->where($map1)
+                ->count();
+            $list[$k]['count'] = $count ? $count : 0;
+        }
+        $this->assign('list', $list);
+        $this->assign('start', $start);
+        $this->assign('end', $end);
+        return $this->fetch();
+    }
+}

+ 276 - 0
application/admin/controller/DailyTask.php

@@ -0,0 +1,276 @@
+<?php
+namespace app\admin\controller;
+use app\common\model\Task;
+use think\Db;
+class DailyTask extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $month= input('month','','trim');
+            if($month != ''){
+                $map[] = ['create_yyyymm','=',$month];
+            }
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $status = input('status','','trim');
+            if($status != ''){
+                $map[] = ['status','=',$status];
+            }
+
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] =['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('daily_task')->where($map)
+                ->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['start_time'] = date('Y-m-d H:i',strtotime($v['start_time']));
+                $lists[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time']));
+                $taskUser=Db::name('daily_task_user')
+                    ->alias('dtu')
+                    ->field('u.real_name')
+                    ->join('user u','u.id=dtu.user_id')
+                    ->where('dtu.task_id',$v['id'])
+                    ->select();
+                $userName = [];
+                foreach ($taskUser as $kk=>$vv){
+                    $userName[$kk]=$vv['real_name'];
+                }
+                $lists[$k]['task_user']=implode(',',$userName);
+            }
+            //数据返回
+            $totalCount = Db::name('daily_task')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('DailyTask')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('DailyTask')->getError());
+            }
+        }else{
+            $title = '新增';
+            if($id){
+                $title = '编辑';
+                $info = Db::name('DailyTask')->where('id',$id)->find();
+                $info['daily_addr'] = Db::name('daily_task_addr')->where('task_id',$info['id'])->column('daily_id');
+                $daily_user = Db::name('daily_task_user')->where('task_id',$info['id'])->column('user_id');
+                $info['daily_user'] = isset($daily_user)?implode(',',$daily_user):'';
+                $this->assign('info',$info);
+            }
+            $dailyAddr= Db::name('Daily')->where('org_id',cur_org_id())->where('del',0)->where('enable',1)->select();
+            $dailyUser = model('WorkTypeMode')->getRolesUser(9,cur_org_id());
+            $this->assign('dailyAddr',$dailyAddr);
+            $this->assign('dailyUser',$dailyUser);
+            $this->assign('send_user_num',0);
+            $this->assign('title',$title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = model('DailyTask')->del($id,$this->userId);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    public function info($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $info=Db::name('daily_task')
+            ->field('id,start_time,end_time,status,title')
+            ->where('id',$id)
+            ->find();
+        $info['start_time']=date('Y-m-d H:i',strtotime($info['start_time']));
+        $info['end_time']=date('Y-m-d H:i',strtotime($info['end_time']));
+        //获取执行用户
+        $task_user=Db::name('daily_task_user')
+            ->alias('dtu')
+            ->join('user u','u.id=dtu.user_id')
+            ->where('dtu.task_id',$info['id'])
+            ->column('u.real_name');
+        $info['task_user']=implode(',',$task_user);
+        $task_addr = Db::name('daily_task_addr')
+            ->alias('dta')
+            ->join('daily d','d.id=dta.daily_id')
+            ->where('dta.task_id',$info['id'])
+            ->column('d.title');
+        $info['task_addr']=implode(',',$task_addr);
+
+        $map[] = ['dr.task_id', '=', $info['id']];
+        $map[] = ['dr.org_id', '=', $this->orgId];
+        //数据查询
+        $lists = Db::name('daily_record')
+            ->alias('dr')
+            ->field('dr.*,d.title')
+            ->Leftjoin('daily d', 'd.id=dr.daily_id')
+            ->where($map)
+            ->order('dr.id','desc')
+            ->select();
+        foreach ($lists as $k => $v) {
+            $lists[$k]['task_title'] = Db::name('daily_task')
+                ->where('id', $v['task_id'])->value('title');
+            $lists[$k]['task_user'] = Db::name('user')
+                ->where('id', $v['user_id'])->value('real_name');
+        }
+
+        $this->assign('info',$info);
+        $this->assign('recordList',$lists);
+
+
+        return $this->fetch();
+    }
+
+    public function calendar(){
+
+        return $this->fetch();
+    }
+
+    //获取正月数据
+    public function taskjson(){
+        $start = input('start');
+        $end = input('end');
+        $data = array();
+        if(!$start||!$end||$start>$end){
+            header('Content-Type:application/json; charset=utf-8');
+            exit(json_encode($data));
+        }
+        $start = date('Y-m-d H:i:s',strtotime($start));
+        $end = date('Y-m-d H:i:s',strtotime($end));
+        $map[] = [''];
+        $list = model('DailyTask')->get_list_by_time($this->orgId,$start,$end);
+
+        foreach ($list as $k=>$v){
+            $arr = array(
+                'taskid' => $v['id'],
+                'title' => "{$v['title']}<br>执行人:{$v['users']}<br>开始时间:{$v['start_time']}<br>结束时间:{$v['end_time']}<br>",
+                'status' => $v['status'],
+                'start' => $v['start_time'],
+                'end' => $v['end_time']
+            );
+            if($v['status'] == 0){
+                $arr['color'] = '#777777';
+            }else if($v['status'] == 1){
+                $arr['color'] = '#478fca';
+            }else if($v['status'] == 2){
+                $arr['color'] = '#69aa46';
+            }else{
+                $arr['color'] = '#dd5a43';
+            }
+            $data[] = $arr;
+        }
+        header('Content-Type:application/json; charset=utf-8');
+        exit(json_encode($data));
+    }
+
+    //复制月计划
+    public function plan(){
+        $type = input('type');
+        if(request()->isPost()){
+            $data = request()->post();
+            if($data['from'] == $data['to']){
+                $this->error('不能复制同月的任务');
+            }
+            $ret =  model('DailyTask')->plan_data($data,$this->orgId);
+            if($ret){
+                if($type==1){
+                    $this->success('操作成功',url('index'));
+                }else{
+                    $this->success('操作成功',url('calendar'));
+
+                }
+            }else{
+                $this->error(model('DailyTask')->getError());
+            }
+        }else{
+            $from = model('DailyTask')->get_task_month($this->orgId);
+            //间隔1月往后数11次
+            $timenow = new \Datetime();
+            $datetin = \DateInterval::createFromDateString('1 month');
+
+            $datePer = new \DatePeriod($timenow, $datetin, 11);
+            $to = [];
+            foreach ($datePer as $day) {
+                $m =  $day->format('Y-m');
+                $to[]= $m;
+            }
+
+            $this->assign('from',$from);
+            $this->assign('to',$to);
+            $this->assign('type',$type);
+            return $this->fetch();
+        }
+    }
+
+    public function batch(){
+        $type = input('type');
+
+        if(request()->isPost()){
+            $result = model('DailyTask')->batchDel($this->orgId,$this->userId);
+            if($result){
+                if($type==1){
+                    $this->success('操作成功',url('index'));
+                }else{
+                    $this->success('操作成功',url('calendar'));
+
+                }
+            }else{
+                $this->error('删除失败');
+            }
+
+        }else{
+            $from = model('DailyTask')->get_task_month($this->orgId);
+
+            $minmonth = date('Y-m');
+            $aa = [];
+            foreach ($from as $k=>$v){
+                if($minmonth < $v['create_yyyymm']){
+                    $aa[] = $v['create_yyyymm'];
+                }
+            }
+            $this->assign('from',$aa);
+            $this->assign('type',$type);
+            return $this->fetch();
+        }
+    }
+
+}
+

+ 145 - 0
application/admin/controller/DelayReason.php

@@ -0,0 +1,145 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class DelayReason extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='delay_reason';
+        $this->model= new \app\common\model\DelayReason();
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)
+                ->order([$sortRow=>$sort,'id'=>'asc'])
+                ->select();
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    public function changeSort($id=0,$sort=0){
+        if($id<0||$sort<0){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->update(['sort'=>$sort]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    public function batchSort(){
+        $data = input('data','','trim');
+        if(!$data){
+            $this->error('参数错误');
+        }
+        $data = json_decode($data,true);
+        if(!$data){
+            $this->error('参数错误');
+        }
+
+        Db::startTrans();
+        try{
+            foreach ($data as $k=>$v){
+                db($this->table)->where('id',$v['id'])->setField('sort',$v['sort']);
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+}

+ 151 - 0
application/admin/controller/Dep.php

@@ -0,0 +1,151 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class Dep extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='dep';
+        $this->model= new \app\common\model\Dep();
+    }
+    public function index(){
+        $cate_id = input('cate_id',0);
+
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            if($cate_id != ''){
+                $map[] = ['cate_id','=',$cate_id];
+            }
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['cateName'] = Db::name('dep_cate')
+                    ->where('id',$v['cate_id'])
+                    ->value('title');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $cateInfo = Db::name('dep_cate')
+                ->where('id',$cate_id)
+                ->find();
+            $this->assign('m_name',$cateInfo?$cateInfo['title']:'');
+            $this->assign('cate_id',$cate_id);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            $cateId = input('cate_id',0);
+            $cate = model('DepCate')->getList();
+            $this->assign('cate',$cate);
+            $this->assign('cate_id',$cateId);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function batchSort(){
+        $data = input('data','','trim');
+        if(!$data){
+            $this->error('参数错误');
+        }
+        $data = json_decode($data,true);
+        if(!$data){
+            $this->error('参数错误');
+        }
+
+        Db::startTrans();
+        try{
+            foreach ($data as $k=>$v){
+                Db::name('dep')->where('id',$v['id'])->setField('sort',$v['sort']);
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+}

+ 142 - 0
application/admin/controller/DepCate.php

@@ -0,0 +1,142 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class DepCate extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='dep_cate';
+        $this->model= new \app\common\model\DepCate();
+    }
+    public function index(){
+
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $dep = Db::name('dep')
+            ->where('cate_id',$id)
+            ->where('del',0)
+            ->find();
+        if($dep){
+            $this->error('当前分类下有部门,暂不能删除');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function batchSort(){
+        $data = input('data','','trim');
+        if(!$data){
+            $this->error('参数错误');
+        }
+        $data = json_decode($data,true);
+        if(!$data){
+            $this->error('参数错误');
+        }
+
+        Db::startTrans();
+        try{
+            foreach ($data as $k=>$v){
+                Db::name('dep')->where('id',$v['id'])->setField('sort',$v['sort']);
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+}

+ 236 - 0
application/admin/controller/Device.php

@@ -0,0 +1,236 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\model\User;
+use think\App;
+use think\Db;
+
+class Device extends Auth
+{
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model = new \app\common\model\Device();
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $cate_id = input('cate_id','','trim');
+            if($cate_id != ''){
+                $map[] = ['cate_id','=',$cate_id];
+            }
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('device')
+                ->where($map)->limit($start,$length)
+                ->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['user_name']=implode(',',$this->model->getByIdUserName($v['id']));
+                $info = Db::name('device_cate')
+                    ->where('id',$v['cate_id'])
+                    ->find();
+                $lists[$k]['cate_name'] = $info?$info['title']:'';
+            }
+
+            //数据返回
+            $totalCount = db('device')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $cate = model('DeviceCate')->list();
+            $this->assign('cate',$cate);
+            $this->assign('meta_title','设备管理列表');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        $model = $this->model;
+        if(request()->isPost()){
+            $res = $model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($model->getError());
+            }
+        }else{
+            $meta_title = '新增设备';
+            $formModel = new \app\common\model\DeviceForm();
+            if($id){
+                $info = Db::name('device')->where('id',$id)->find();
+                $info['device_form']=explode(',',$info['device_form']);
+                $info['user']=$model->getDeviceUserList($info['id']);
+                $this->assign('info',$info);
+                $meta_title = '编辑设备';
+                $deviceForm= $formModel->byCateList($info['cate_id']);
+                $this->assign('device_form',$deviceForm);
+
+            }
+            //用户
+            $user= (new User())->getDeviceWorker();
+            $this->assign('device_user',$user);
+            $this->assign('meta_title',$meta_title);
+            $cate = model('DeviceCate')->list();
+            $this->assign('cate',$cate);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('device')->where('id',$id)->update(['del'=>1]);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('device')->where('id',$id)->update([$fn => $fv]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    //二维码
+    public function qrcode($id=0)
+    {
+        $info=Db::name('device')->where('id',$id)->find();
+        if (!$info) {
+            exit('数据不存在');
+        }
+        $code = get_qrcode_str('device', $id);
+        $this->assign('code',$code);
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+    public function allPrint(){
+        $ids = input('ids');
+        if(!$ids){
+            $list = Db::name('device')
+                ->where('org_id',cur_org_id())
+                ->where('enable',1)
+                ->where('del',0)
+                ->select();
+        }else{
+            $ids = explode(',',$ids);
+            $list = Db::name('device')
+                ->where('org_id',cur_org_id())
+                ->where('enable',1)
+                ->where('id','in',$ids)
+                ->where('del',0)
+                ->select();
+        }
+
+        foreach ($list as $k=>$v){
+            $list[$k]['qCode'] = get_qrcode_str('device',$v['id']);
+        }
+
+        $this->assign('list',$list);
+        return $this->fetch();
+
+    }
+
+    public function addrdown(){
+        $orgid = $this->orgId;
+        $map[] = ['del','=',0];
+        $map[] = ['org_id','=',$this->orgId];
+        $map= empty($map) ? true: $map;
+        //数据查询
+        $lists = db('device')->where($map)->select();
+
+        foreach ($lists as $k=>$v){
+            $lists[$k]['code'] = get_qrcode_str('device',$v['id']);
+        }
+        $path = date('Ymd').'_'.$orgid.'_'.time().mt_rand(1000,9999);
+        $dir = './uploads/qrcodeimg/'.$path.'/';
+
+        foreach ($lists as $v1){
+            $name = $v1['title'].'('.$v1['id'].')'.'.jpg';
+            $filepath = $dir.'/'.$name;
+            create_qrcode($v1['code'],$filepath);
+        }
+
+        $zippath = './uploads/qrcodeimg/'.$path.'.zip';
+        $spath = $dir;
+        @unlink($zippath);
+        $zip = new \ZipArchive();
+        if($zip->open($zippath, \ZipArchive::CREATE)=== TRUE){
+            add_file_to_zip($spath,$zip); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
+            $zip->close(); //关闭处理的zip文件
+            if(!file_exists($zippath)){
+                $this->error("打包失败"); //即使创建,仍有可能失败。。。。
+            }
+
+            deldir($dir); // 删除生成的目录
+
+            $downname = session('orgName').'设备维保二维码.zip';
+            header("Cache-Control: public");
+            header("Content-Description: File Transfer");
+            header('Content-disposition: attachment; filename='.$downname); //文件名
+            header("Content-Type: application/zip"); //zip格式的
+            header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
+            header('Content-Length: '. filesize($zippath)); //告诉浏览器,文件大小
+            @readfile($zippath);
+
+        }else{
+            $this->error("打包失败");
+        }
+    }
+
+    public function getByCate(){
+        $cate_id = input('id/d',0);
+        if($cate_id==0){
+            $this->success('操作成功','',[]);
+
+        }
+        $list  = Db::name('device_form')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('enable',1)
+            ->where('cate_id',$cate_id)
+            ->select();
+        $this->success('操作成功','',$list);
+    }
+}

+ 114 - 0
application/admin/controller/DeviceCate.php

@@ -0,0 +1,114 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class DeviceCate extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\DeviceCate();
+        $this->table= $this->model->table;
+        $this->m_name = '设备分类';
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name',$this->m_name);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+
+
+}

+ 151 - 0
application/admin/controller/DeviceForm.php

@@ -0,0 +1,151 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class DeviceForm extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\DeviceForm();
+        $this->table= $this->model->table;
+        $this->m_name = '设备维保项';
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $cate_id = input('cate_id','','trim');
+            if($cate_id != ''){
+                $map[] = ['cate_id','=',$cate_id];
+            }
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            foreach ($lists as $k=>$v){
+                $info = Db::name('device_cate')
+                    ->where('id',$v['cate_id'])
+                    ->find();
+                $lists[$k]['cate_name'] = $info?$info['title']:'';
+            }
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name',$this->m_name);
+            $cate = model('DeviceCate')->list();
+            $this->assign('cate',$cate);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            $cate = model('DeviceCate')->list();
+            $this->assign('cate',$cate);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function batchSort(){
+        $data = input('data','','trim');
+        if(!$data){
+            $this->error('参数错误');
+        }
+        $data = json_decode($data,true);
+        if(!$data){
+            $this->error('参数错误');
+        }
+
+        Db::startTrans();
+        try{
+            foreach ($data as $k=>$v){
+                Db::name('device_form')->where('id',$v['id'])->setField('sort',$v['sort']);
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+
+}

+ 213 - 0
application/admin/controller/DeviceRecord.php

@@ -0,0 +1,213 @@
+<?php
+
+namespace app\admin\controller;
+use think\Db;
+
+class DeviceRecord extends Auth {
+    public function index() {
+        if (request()->isAjax()) {
+            //分页参数
+            $length = input('rows', 10, 'intval');   //每页条数
+            $page = input('page', 1, 'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx', 'sort', 'trim');      //排序列
+            $sort = input('sord', 'asc', 'trim');        //排序方式
+            $order = $sortRow . ' ' . $sort . ' ,id desc';
+            $title = input('title', '', 'trim');
+            if ($title) {
+                $map[] = ['d.title', 'like', '%' . $title . '%'];
+            }
+            $map[] = ['dr.org_id', '=', $this->orgId];
+            $map = empty($map) ? true : $map;
+            //数据查询
+            $lists = Db::name('device_record')
+                ->alias('dr')
+                ->join('device d', 'd.id=dr.device_id')
+                ->field('dr.*,d.title as device_name,d.content as device_details')
+                ->where($map)
+                ->limit($start, $length)
+                ->order($order)
+                ->select();
+            foreach ($lists as $k => $v) {
+                $lists[$k]['user_name'] = Db::name('user')
+                    ->where('id', $v['user_id'])->value('real_name');
+                $status = 0;
+                if($v['order_id'] > 0 ){
+                    $order =  Db::name('orders')
+                        ->where('id',$v['order_id'])
+                        ->where('quality_type',1)
+                        ->whereIn('order_mode',[5,6])->where('del',0)->find();
+
+                    if($order){
+                        $status = 2;
+                    }else{
+                        $status = 1;
+                    }
+                }
+                $lists[$k]['zg_type'] = $status;
+            }
+            //数据返回
+            $totalCount = Db::name('device_record')
+                ->alias('dr')
+                ->join('device d', 'd.id=dr.device_id')
+                ->field('dr.*,d.title as device_name,d.content as device_details')
+                ->where($map)
+                ->count();
+            $totalPage = ceil($totalCount / $length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }
+        else {
+            $this->assign('meta_title', '设备检查记录列表');
+            return $this->fetch();
+        }
+    }
+    public function details($id) {
+        if (!$id) {
+            $this->error('参数错误');
+        }
+        $ret = Db::name('device_record')->where('id', $id)->find();
+        $device = Db::name('device')->field('title,content')->where('id', $ret['device_id'])->find();
+        $ret['title'] = $device['title'];
+        $ret['device_details'] = $device['content'];
+        $ret['images'] = explode(',',$ret['images']);
+        $ret['check_json'] = json_decode($ret['check_json'], true);
+        $ret['user_name'] = Db::name('user')->where('id', $ret['user_id'])
+            ->value('real_name');
+        $status = 0;
+        if($ret['order_id'] > 0 ){
+            $order =  Db::name('orders')
+                ->where('id',$ret['order_id'])
+                ->where('quality_type',1)
+                ->whereIn('order_mode',[5,6])->where('del',0)->find();
+
+            if($order){
+                $status = 2;
+            }else{
+                $status = 1;
+            }
+        }
+        $ret['zg_type'] = $status;
+        $this->assign('info', $ret);
+        $this->assign('meta_title', '设备检查记录详情');
+        return $this->fetch();
+    }
+    //excel导出
+    public function export() {
+        $meta_title = '设备检查记录';
+        if (request()->isPost()) {
+            $start = input('start');
+            $end = input('end');
+            $where[] = ['create_yyyymmdd', '>=', $start];
+            $where[] = ['create_yyyymmdd', '<=', $end];
+            $where[] = ['org_id', '=', $this->orgId];
+            $ret = Db::name('device_record')->where($where)->select();
+            foreach ($ret as $k => $v) {
+                $device = Db::name('device')
+                    ->field('title,content')
+                    ->where('id', $v['device_id'])->find();
+                $ret[$k]['user_name'] = Db::name('user')
+                    ->where('id', $v['user_id'])->value('real_name');
+                $ret[$k]['device_name'] = $device['title'];
+                $ret[$k]['device_details'] = $device['content'];
+            }
+            include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+            //实例化PHPExcel类
+            $objPHPExcel = new \PHPExcel();
+            //激活当前的sheet表
+            $objPHPExcel->setActiveSheetIndex(0);
+            //设置表格头(即excel表格的第一行)
+            $objPHPExcel->setActiveSheetIndex(0)
+                ->setCellValue('A1', '编号')
+                ->setCellValue('B1', '设备名称')
+                ->setCellValue('C1', '设备详情')
+                ->setCellValue('D1', '维护人员')
+                ->setCellValue('E1', '维护时间')
+                ->setCellValue('F1', '检查项');
+            // 设置表格头水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置列水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置单元格宽度
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
+            //循环刚取出来的数组,将数据逐一添加到excel表格。
+            for ($i = 0; $i < count($ret); $i++) {
+                $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['id']);//ID
+                $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['device_name']);//设备名称
+                $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['device_details']);//设备详情
+                $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $ret[$i]['user_name']);//维护人员
+                $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $ret[$i]['create_time']);//维护时间
+                $result = json_decode($ret[$i]['check_json'], true);
+                $str = array();
+                foreach ($result as $kk => $vv) {
+                    $ss = $vv['title'] . ":";
+                    if ($vv['result'] == 1) {
+                        $ss .= '☑';
+                    }
+                    else {
+                        $ss .= '□';
+                    }
+                    $str[] = $ss;
+                }
+                $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), implode(' ; ', $str));//检查项
+            }
+            //设置保存的Excel表格名称
+            $filename = '设备检查记录_' . date('YmdHis', time()) . '.xls';
+            //设置当前激活的sheet表格名称
+            $objPHPExcel->getActiveSheet()->setTitle('设备检查记录');
+            //设置浏览器窗口下载表格
+            ob_end_clean();
+            header("Content-Type: application/force-download");
+            header("Content-Type: application/octet-stream");
+            header("Content-Type: application/download");
+            header('Content-Disposition:inline;filename="' . $filename);
+            //生成excel文件
+            $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+            //下载文件在浏览器窗口
+            return $objWriter->save('php://output');
+        }
+        $this->assign('meta_title', $meta_title);
+        return $this->fetch();
+    }
+}

+ 96 - 0
application/admin/controller/DeviceStatistics.php

@@ -0,0 +1,96 @@
+<?php
+
+namespace app\admin\controller;
+use think\App;
+use think\Db;
+
+class DeviceStatistics extends Auth {
+
+    public function device(){
+        $cur = date('Y-m-d');
+        $start = input('start',date('Y-m-d', strtotime(''.$cur.' -1 week')));
+        $end = input('end',date('Y-m-d'));
+        $start1 = $start.' 00:00:00';
+        $end1 = $end.' 23:59:59';
+        $list = $this->deviceData($start1,$end1);
+        $this->assign('list',$list);
+        $this->assign('start',$start);
+        $this->assign('end',$end);
+        return $this->fetch();
+    }
+    public function deviceData($start1,$end1){
+        $map1[] = ['create_time','>=',$start1];
+        $map1[] = ['create_time','<=',$end1];
+        $map1[] = ['org_id','<=',$this->orgId];
+        $list  =Db::name('device_record')
+            ->where('org_id',$this->orgId)
+            ->group('device_id')
+            ->select();
+        foreach ($list as $k=>$v){
+            $list[$k]['title'] = Db::name('device')
+                ->where('id',$v['device_id'])
+                ->value('title');
+            $c = Db::name('device_record')
+                ->where($map1)
+                ->where('device_id',$v['device_id'])
+                ->count();
+            $list[$k]['count'] = $c?$c:0;
+        }
+        return $list;
+    }
+    public function deviceExport(){
+        $cur = date('Y-m-d');
+        $start = input('start',date('Y-m-d', strtotime(''.$cur.' -1 week')));
+        $end = input('end',date('Y-m-d'));
+        $start1 = $start.' 00:00:00';
+        $end1 = $end.' 23:59:59';
+        $ret = $this->deviceData($start1,$end1);
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+        //实例化PHPExcel类
+        $objPHPExcel = new \PHPExcel();
+        //激活当前的sheet表
+        $objPHPExcel->setActiveSheetIndex(0);
+        //设置表格头(即excel表格的第一行)
+        $objPHPExcel->setActiveSheetIndex(0)
+            ->setCellValue('A1', '设备')
+            ->setCellValue('B1', '总数');
+        // 设置表格头水平居中
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+
+
+        //设置列水平居中
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+
+
+        //设置单元格宽度
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
+
+        //循环刚取出来的数组,将数据逐一添加到excel表格。
+        for ($i = 0; $i < count($ret); $i++) {
+            $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['title']);
+            $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['count']);
+        }
+
+        //设置保存的Excel表格名称
+        $filename = '设备维保工作量统计分析_' . date('YmdHis', time()) . '.xls';
+        //设置当前激活的sheet表格名称
+        $objPHPExcel->getActiveSheet()->setTitle('设备维保工作量统计分析');
+        //设置浏览器窗口下载表格
+        ob_end_clean();
+        header("Content-Type: application/force-download");
+        header("Content-Type: application/octet-stream");
+        header("Content-Type: application/download");
+        header('Content-Disposition:inline;filename="' . $filename);
+        //生成excel文件
+        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+        //下载文件在浏览器窗口
+        return $objWriter->save('php://output');
+    }
+}

+ 385 - 0
application/admin/controller/DeviceTask.php

@@ -0,0 +1,385 @@
+<?php
+namespace app\admin\controller;
+use app\common\model\Task;
+use think\Db;
+use think\Exception;
+
+class DeviceTask extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $month= input('month','','trim');
+            if($month != ''){
+                $map[] = ['create_yyyymm','=',$month];
+            }
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $status = input('status','','trim');
+            if($status != ''){
+                $map[] = ['status','=',$status];
+            }
+            $cate_id = input('cate_id','','trim');
+            if($cate_id != ''){
+                $map[] = ['cate_id','=',$cate_id];
+            }
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] =['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('device_task')->where($map)
+                ->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['start_time'] = date('Y-m-d H:i',strtotime($v['start_time']));
+                $lists[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time']));
+                $taskUser=Db::name('device_task_user')
+                    ->alias('dtu')
+                    ->field('u.real_name')
+                    ->join('user u','u.id=dtu.user_id')
+                    ->where('dtu.task_id',$v['id'])
+                    ->select();
+                $userName = [];
+                foreach ($taskUser as $kk=>$vv){
+                    $userName[$kk]=$vv['real_name'];
+                }
+                $lists[$k]['task_user']=implode(',',$userName);
+                $info = Db::name('device_cate')
+                    ->where('id',$v['cate_id'])
+                    ->find();
+                $lists[$k]['cate_name'] = $info?$info['title']:'';
+            }
+            //数据返回
+            $totalCount = Db::name('device_task')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $cate = model('DeviceCate')->list();
+            $this->assign('cate',$cate);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('DeviceTask')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('DeviceTask')->getError());
+            }
+        }else{
+            $title = '新增';
+            if($id){
+                $title = '编辑';
+                $info = Db::name('DeviceTask')->where('id',$id)->find();
+                $info['device_addr'] = Db::name('device_task_addr')->where('task_id',$info['id'])->column('device_id');
+                foreach ($info['device_addr'] as $k=>&$v){
+                    $v = (string)$v;
+                }
+                $info['start_time'] = date('Y-m-d H:i',strtotime($info['start_time']));
+                $info['end_time'] = date('Y-m-d H:i',strtotime($info['end_time']));
+                $device_user = Db::name('device_task_user')->where('task_id',$info['id'])->column('user_id');
+                $info['device_user'] = isset($device_user)?implode(',',$device_user):'';
+                $this->assign('info',$info);
+                $deviceAddr= Db::name('Device')->where('org_id',cur_org_id())
+                    ->where('cate_id',$info['cate_id'])
+                    ->where('del',0)
+                    ->where('enable',1)->select();
+                $this->assign('deviceAddr',$deviceAddr);
+            }
+
+            $deviceUser = model('WorkTypeMode')->getRolesUser(10,cur_org_id());
+            $this->assign('deviceUser',$deviceUser);
+            $this->assign('send_user_num',0);
+            $this->assign('title',$title);
+            $cate = model('DeviceCate')->list();
+            $this->assign('cate',$cate);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = model('DeviceTask')->del($id,$this->userId);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+    public function byIdSDel(){
+        $ids = input('ids',[]);
+        if(!$ids){
+            $this->error('参数错误');
+        }
+        $res = model('DeviceTask')->byIdSDel($ids,$this->userId);
+        if($res){
+            $this->success('删除成功',url('index'));
+        }else{
+            $this->error(model('DeviceTask')->getError());
+        }
+    }
+    public function info($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $info=Db::name('device_task')
+            ->field('id,start_time,end_time,status,title')
+            ->where('id',$id)
+            ->find();
+        $info['start_time']=date('Y-m-d H:i',strtotime($info['start_time']));
+        $info['end_time']=date('Y-m-d H:i',strtotime($info['end_time']));
+        //获取执行用户
+        $task_user=Db::name('device_task_user')
+            ->alias('dtu')
+            ->join('user u','u.id=dtu.user_id')
+            ->where('dtu.task_id',$info['id'])
+            ->column('u.real_name');
+        $info['task_user']=implode(',',$task_user);
+        $task_addr = Db::name('device_task_addr')
+            ->alias('dta')
+            ->join('device d','d.id=dta.device_id')
+            ->where('dta.task_id',$info['id'])
+            ->column('d.title');
+        $info['task_addr']=implode(',',$task_addr);
+
+        $map[] = ['dr.task_id', '=', $info['id']];
+        $map[] = ['dr.org_id', '=', $this->orgId];
+        //数据查询
+        $lists = Db::name('device_record')
+            ->alias('dr')
+            ->field('dr.*,d.title')
+            ->Leftjoin('device d', 'd.id=dr.device_id')
+            ->where($map)
+            ->order('dr.id','desc')
+            ->select();
+        foreach ($lists as $k => $v) {
+            $lists[$k]['task_title'] = Db::name('device_task')
+                ->where('id', $v['task_id'])->value('title');
+            $lists[$k]['task_user'] = Db::name('user')
+                ->where('id', $v['user_id'])->value('real_name');
+        }
+
+        $this->assign('info',$info);
+        $this->assign('recordList',$lists);
+
+
+        return $this->fetch();
+    }
+
+    public function calendar(){
+
+        return $this->fetch();
+    }
+
+    //获取正月数据
+    public function taskjson(){
+        $start = input('start');
+        $end = input('end');
+        $data = array();
+        if(!$start||!$end||$start>$end){
+            header('Content-Type:application/json; charset=utf-8');
+            exit(json_encode($data));
+        }
+        $start = date('Y-m-d H:i:s',strtotime($start));
+        $end = date('Y-m-d H:i:s',strtotime($end));
+        $map[] = [''];
+        $list = model('DeviceTask')->get_list_by_time($this->orgId,$start,$end);
+
+        foreach ($list as $k=>$v){
+            $arr = array(
+                'taskid' => $v['id'],
+                'title' => "{$v['title']}<br>执行人:{$v['users']}<br>开始时间:{$v['start_time']}<br>结束时间:{$v['end_time']}<br>",
+                'status' => $v['status'],
+                'start' => $v['start_time'],
+                'end' => $v['end_time']
+            );
+            if($v['status'] == 0){
+                $arr['color'] = '#777777';
+            }else if($v['status'] == 1){
+                $arr['color'] = '#478fca';
+            }else if($v['status'] == 2){
+                $arr['color'] = '#69aa46';
+            }else{
+                $arr['color'] = '#dd5a43';
+            }
+            $data[] = $arr;
+        }
+        header('Content-Type:application/json; charset=utf-8');
+        exit(json_encode($data));
+    }
+
+    //复制月计划
+    public function plan(){
+        $type = input('type');
+        if(request()->isPost()){
+            $data = request()->post();
+            if($data['from'] == $data['to']){
+                $this->error('不能复制同月的任务');
+            }
+            $ret =  model('DeviceTask')->plan_data($data,$this->orgId);
+            if($ret){
+                if($type==1){
+                    $this->success('操作成功',url('index'));
+                }else{
+                    $this->success('操作成功',url('calendar'));
+
+                }
+            }else{
+                $this->error(model('DeviceTask')->getError());
+            }
+        }else{
+            $from = model('DeviceTask')->get_task_month($this->orgId);
+            //间隔1月往后数11次
+            $timenow = new \Datetime();
+            $datetin = \DateInterval::createFromDateString('1 month');
+
+            $datePer = new \DatePeriod($timenow, $datetin, 11);
+            $to = [];
+            foreach ($datePer as $day) {
+                $m =  $day->format('Y-m');
+                $to[]= $m;
+            }
+
+            $this->assign('from',$from);
+            $this->assign('to',$to);
+            $this->assign('type',$type);
+            return $this->fetch();
+        }
+    }
+
+    public function batch(){
+        $type = input('type');
+
+        if(request()->isPost()){
+            $result = model('DeviceTask')->batchDel($this->orgId,$this->userId);
+            if($result){
+                if($type==1){
+                    $this->success('操作成功',url('index'));
+                }else{
+                    $this->success('操作成功',url('calendar'));
+                }
+            }else{
+                $this->error('删除失败');
+            }
+
+        }else{
+            $from = model('DeviceTask')->get_task_month($this->orgId);
+            $minmonth = date('Y-m');
+            $aa = [];
+            foreach ($from as $k=>$v){
+//                if($minmonth < $v['create_yyyymm']){
+//                    $aa[] = $v['create_yyyymm'];
+//                }
+                $aa[] = $v['create_yyyymm'];
+
+            }
+            $this->assign('from',$aa);
+            $this->assign('type',$type);
+            return $this->fetch();
+        }
+    }
+
+    public function delay(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $status = input('status','','trim');
+            if($status != ''){
+                $map[] = ['status','=',$status];
+            }
+
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('device_task_delay')->where($map)
+                ->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $taskTitle = Db::name('device_task')->where('id',$v['task_id'])->value('title');
+                $lists[$k]['task_title'] = $taskTitle?$taskTitle:'';
+                $lists[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time']));
+                $lists[$k]['uname'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
+                $lists[$k]['deal_user'] = '';
+                if($v['deal_user_id'] > 0){
+                    $lists[$k]['deal_user'] = Db::name('user')->where('id',$v['deal_user_id'])->value('real_name');
+                }
+            }
+            //数据返回
+            $totalCount = Db::name('device_task_delay')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 处理
+     */
+    public function deal($id = 0){
+        if(request()->isPost()){
+            $res = model('DeviceTask')->dealDelay($this->userId,$this->orgId);
+            if($res){
+                $this->success('操作成功',url('deal'));
+            }else{
+                $this->error(model('DeviceTask')->getError());
+            }
+        }else{
+            $info = Db::name('device_task_delay')->where('id',$id)->find();
+            $this->assign('info',$info);
+
+            return $this->fetch();
+        }
+    }
+    public function getByCate(){
+        $cate_id = input('id/d',0);
+        if($cate_id==0){
+            $this->success('操作成功','',[]);
+
+        }
+        $list  = Db::name('device')
+            ->where('org_id',$this->orgId)
+            ->where('del',0)
+            ->where('enable',1)
+            ->where('cate_id',$cate_id)
+            ->select();
+        $this->success('操作成功','',$list);
+    }
+}
+

+ 291 - 0
application/admin/controller/Dinner.php

@@ -0,0 +1,291 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class Dinner extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='dinner';
+        $this->model= new \app\common\model\Dinner();
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['name','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $type = input('type','','trim');
+            if($type){
+                $map[] = ['dinner_type_id','=',$type];
+            }
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['cate','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name($this->table)->where($map)->limit($start,$length)->order(
+                ['sort'=>'asc','id'=>'desc']
+            )->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['type'] = Db::name('dinner_type')
+                    ->field('name,color')
+                    ->where('id',$v['dinner_type_id'])
+                    ->find();
+                $img = $v['imgs']?explode(',',$v['imgs']):[];
+                $lists[$k]['img'] = $img?$img[0]:'';
+            }
+            //数据返回
+            $totalCount = Db::name($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            $typeList = model('DinnerType')->getList($this->orgId);
+            $this->assign('typeList',$typeList);
+            return $this->fetch();
+        }
+    }
+
+    // 特殊人群菜单
+    public function index2(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['name','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $type = input('type','','trim');
+            if($type){
+                $map[] = ['dinner_type_id','=',$type];
+            }
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['cate','=',1];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name($this->table)->where($map)->limit($start,$length)->order(
+                ['sort'=>'asc','id'=>'desc']
+            )->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['dinner_type'] = Db::name('dinner_type')
+                    ->field('name,color')
+                    ->where('id',$v['dinner_type_id'])
+                    ->find();
+                $img = $v['imgs']?explode(',',$v['imgs']):[];
+                $lists[$k]['img'] = $img?$img[0]:'';
+            }
+            //数据返回
+            $totalCount = Db::name($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            $typeList = model('DinnerType')->getList($this->orgId);
+            $this->assign('typeList',$typeList);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates(0);
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =Db::name($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            $typeList = model('DinnerType')->getList($this->orgId);
+            $this->assign('typeList',$typeList);
+            return $this->fetch();
+        }
+    }
+
+    public function add2($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates(1);
+            if($res){
+                $this->success('操作成功',url('index2'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =Db::name($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            $typeList = model('DinnerType')->getList($this->orgId);
+            $this->assign('typeList',$typeList);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+    public function detail($id){
+        $res = db($this->table)->where('id',$id)->find();
+        $res['imgs'] = explode(',',$res['imgs']);
+        $this->assign('info',$res);
+        return $this->fetch();
+
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $name = '菜单管理:';
+            $content = '';
+            if($fn == 'enable'){
+                $content = $name.'预约餐下架';
+                if($fv == 1){
+                    $content = $name.'预约餐上架';
+                }
+            }elseif ($fn == 'today_enable'){
+                $content = $name.'当天餐下架';
+                if($fv == 1){
+                    $content = $name.'当天餐上架';
+                }
+            }
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    public function disableall(){
+
+        $res = db($this->table)
+            ->where('org_id',$this->orgId)
+            ->update([
+                'enable'=>0,
+                'update_time'=>getTime()
+            ]);
+
+        if($res){
+            $ids =  db($this->table)
+                ->where('org_id',$this->orgId)
+                ->column('id');
+
+
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    public function enableall(){
+
+        $res = db($this->table)
+            ->where('org_id',$this->orgId)
+            ->update([
+                'enable'=>1,
+                'update_time'=>getTime()
+            ]);
+        if($res){
+            $ids =  db($this->table)
+                ->where('org_id',$this->orgId)
+                ->column('id');
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    public function disablealltoday(){
+
+        $res = db($this->table)
+            ->where('org_id',$this->orgId)
+            ->update([
+                'today_enable'=>0,
+                'update_time'=>getTime()
+            ]);
+        if($res){
+            $ids =  db($this->table)
+                ->where('org_id',$this->orgId)
+                ->column('id');
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    public function enablealltoday(){
+
+        $res = db($this->table)
+            ->where('org_id',$this->orgId)
+            ->update([
+                'today_enable'=>1,
+                'update_time'=>getTime()
+            ]);
+        if($res){
+            $ids =  db($this->table)
+                ->where('org_id',$this->orgId)
+                ->column('id');
+
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+}

+ 315 - 0
application/admin/controller/DinnerAddress.php

@@ -0,0 +1,315 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\util\QrcodeUtil;
+use think\Db;
+
+class DinnerAddress extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('dinner_address')->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['types_text'] = $v['type']==0?'预定餐':'当日餐';
+            }
+
+            //数据返回
+            $totalCount = db('dinner_address')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('DinnerAddress')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('Address')->getError());
+            }
+        }else{
+            if($id){
+                $info = db('dinner_address')->where('id',$id)->find();
+
+                $this->assign('info',$info);
+            }
+
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('dinner_address')->where('id',$id)->setField('del',1);
+        if($res){
+
+
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('dinner_address')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $name = '科室地址:';
+            $content = '';
+            if($fn == 'enable'){
+                $content = $name.'禁用';
+                if($fv == 1){
+                    $content = $name.'启用';
+                }
+            }
+
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function qrcode($id=0){
+        $info = Db::name('dinner_address')->where('id',$id)->find();
+        $str = get_qrcode_str('dinner_address',$id);
+
+        $code = url('h5/WxHome/index',[],false,true).'?code='.$str;
+        $this->assign('url',$code);
+        $this->assign('code',think_encrypt($code));
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+    // 地址下载
+    public function addrdown(){
+        $orgid = $this->orgId;
+        $map[] = ['del','=',0];
+        $map[] = ['org_id','=',$this->orgId];
+        $map= empty($map) ? true: $map;
+        //数据查询
+        $lists = db('dinner_address')->where($map)->select();
+
+        foreach ($lists as $k=>$v){
+            $str = get_qrcode_str('dinner_address',$v['id']);
+            $code = url('h5/WxHome/index',['code'=>$str],false,true);
+            $lists[$k]['code'] =$code;
+        }
+        $path = date('Ymd').'_'.$orgid.'_'.time().mt_rand(1000,9999);
+        $dir = './uploads/temp/'.$path.'/';
+
+        foreach ($lists as $v1){
+            $name = $v1['title'].'('.$v1['id'].')'.'.jpg';
+            $filepath = $dir.'/'.$name;
+            QrcodeUtil::create($v1['code'],1,$filepath);
+        }
+
+        $zippath = './uploads/temp/'.$path.'.zip';
+        $spath = $dir;
+        @unlink($zippath);
+        $zip = new \ZipArchive();
+        if($zip->open($zippath, \ZipArchive::CREATE)=== TRUE){
+            add_file_to_zip($spath,$zip); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
+            $zip->close(); //关闭处理的zip文件
+            if(!file_exists($zippath)){
+                $this->error("打包失败"); //即使创建,仍有可能失败。。。。
+            }
+
+            deldir($dir); // 删除生成的目录
+
+            $downname = session('orgName').'订餐地点二维码.zip';
+            header("Cache-Control: public");
+            header("Content-Description: File Transfer");
+            header('Content-disposition: attachment; filename='.$downname); //文件名
+            header("Content-Type: application/zip"); //zip格式的
+            header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
+            header('Content-Length: '. filesize($zippath)); //告诉浏览器,文件大小
+            @readfile($zippath);
+
+        }else{
+            $this->error("打包失败");
+        }
+    }
+
+    public function import(){
+        return $this->fetch();
+    }
+    /**
+     * 下载点模板
+     */
+    public function downloadtem(){
+        set_time_limit(0);
+        ini_set("memory_limit","512M");
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+
+        $fileName = '订餐地点模板.xlsx';
+        $excel = new \PHPExcel();
+        $sheet = $excel->setActiveSheetIndex(0);
+        $arr = array('A','B','C','D');
+
+        foreach($arr as $k=>$v){
+            $excel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(true);//换行
+            $excel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
+            if($k==3){
+                $excel->getActiveSheet()->getColumnDimension($v)->setWidth(100);
+            }else{
+                $excel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
+
+            }
+        }
+        $sheet->setCellValueByColumnAndRow(0,1,'名称');
+       // $sheet->setCellValueByColumnAndRow(1,1,'类型[预定餐,当日餐]');
+        $sheet->setCellValueByColumnAndRow(1,1,'备注');
+
+
+        $excel->getActiveSheet()->setCellValue('A2', '示例地址');
+        $excel->getActiveSheet()->setCellValue('B2', 'XXX');
+     //   $excel->getActiveSheet()->setCellValue('C2', 'XXX');
+
+        ob_end_clean();//清除缓冲区,避免乱码
+        header('Content-Type: application/vnd.ms-excel');
+        header('Content-Disposition: attachment;filename="'.$fileName.'"');
+        header('Cache-Control: max-age=0');
+
+        $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
+        $objWriter->save('php://output'); //文件通过浏览器下载
+
+    }
+
+
+    /**
+     * 导入
+     */
+    public function importexcel(){
+        set_time_limit(0);
+        ini_set("memory_limit", -1);
+        ob_flush();//清空缓存
+        flush();//刷新缓存
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+        $orgId = $this->orgId;
+        if(request()->file()) {
+            $file = request()->file('file');
+            //获取文件后缀
+            $e = explode('.',$_FILES['file']['name']);
+            $ext = $e[count($e)-1];
+            if($ext == 'xls'){
+                \PHPExcel_IOFactory::createReader( 'Excel5');
+            }else{
+                \PHPExcel_IOFactory::createReader('Excel2007');
+            }
+            $newArr=['xls','xlsx'];
+            if(!in_array($ext,$newArr)){
+                exit('文件格式不正确');
+            }
+            $uploaddir = config('app.upload_dir');
+            // 移动到框架应用根目录/uploads/ 目录下
+            $info = $file->validate(config('app.import_upload_file'))
+                ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . $uploaddir . DIRECTORY_SEPARATOR . 'files');
+            if(!$info){
+                exit('文件上传失败');
+            }
+            $img = './'.$uploaddir.'/files/' . $info->getSaveName();
+            $filePath = str_replace('\\', '/', $img);
+            $newPath = \PHPExcel_IOFactory::load($filePath);
+
+            $excelArray = $newPath->getsheet(0)->toArray();   //转换为数组格式
+
+            array_shift($excelArray);  //删除第一个数组(标题);
+
+            if(empty($excelArray)){
+                exit('文件内容为空');
+            }
+            foreach ($excelArray as $k => $v) {
+                if(!$v[0]){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,地址为空,未导入</font><br />";
+                    continue;
+                }
+//                if(!$v[1]){
+//                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型为空,未导入</font><br />";
+//                    continue;
+//                }
+
+//                $a  =['预定餐','当日餐'];
+//                if(!in_array($v[1],$a)){
+//                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,类型错误,未导入</font><br />";
+//                    continue;
+//                }
+                $check = Db::name('dinner_address')
+                    ->where('org_id',$orgId)
+                    ->where('del',0)
+                    ->where('title',$v[0])
+                    ->find();
+                if($check){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,地址已存在,未导入</font><br />";
+                    continue;
+                }
+
+                $rData = [
+                    'org_id'=>$orgId,
+                    'title'=>$v[0],
+                    'remark'=>$v[1],
+                   // 'type'=>$v[1],
+                    'create_time'=>getTime()
+                ];
+                $ret=Db::name('dinner_address')->insertGetId($rData);
+
+                if(!$ret){
+                    echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,导入失败</font><br />";
+                }else{
+                    echo "<font color=\"green\" style='margin-left:20px;font-size: 17px'>第".($k+1)."行,导入成功</font><br />";
+                }
+
+            }
+        }else{
+            exit('请上传文件');
+        }
+
+    }
+
+}

+ 111 - 0
application/admin/controller/DinnerApply.php

@@ -0,0 +1,111 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class DinnerApply extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='dinner_apply';
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['name','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['status','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->where('org_id',$this->orgId)->setField('del',1);
+        if($res){
+
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    public function cancel($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->where('org_id',$this->orgId)->setField('status',3);
+        if($res){
+
+            $this->success('作废成功');
+        }else{
+            $this->error('作废失败');
+        }
+    }
+
+
+    public function option($id=0){
+        if(request()->isPost()){
+            $status = input('status/d',1);
+            $remark = input('remark','');
+            $res = Db::name('dinner_apply')
+                ->where('id',$id)
+                ->update([
+                    'status'=>$status,
+                    'remark'=>$remark,
+                ]);
+            if($status==1){
+                $content = '同意特殊人员申请';
+            }elseif ($status==2){
+                $content = '拒绝特殊人员申请';
+
+            }
+            if($res){
+
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+}

+ 32 - 0
application/admin/controller/DinnerConfig.php

@@ -0,0 +1,32 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class DinnerConfig extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='dinner_config';
+        $this->model= new \app\common\model\DinnerConfig();
+    }
+    public function index(){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            $info = Db::name('dinner_config')
+                ->where('org_id',$this->orgId)
+                ->find();
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+    }
+
+}

+ 656 - 0
application/admin/controller/DinnerGroup.php

@@ -0,0 +1,656 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\util\QrcodeUtil;
+use think\Db;
+use think\Exception;
+
+class DinnerGroup extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('dinner_group')->where($map)->limit($start,$length)->order($order)->select();
+
+
+            //数据返回
+            $totalCount = Db::name('dinner_group')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('DinnerGroup')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('DinnerGroup')->getError());
+            }
+        }else{
+            if($id){
+                $info = Db::name('dinner_group')->where('id',$id)->find();
+
+                $this->assign('info',$info);
+            }
+
+            $cur = get_week_days(0);
+            $curnext = get_week_days(1);
+            $weeks = [
+                ["id"=>0,"name"=>"本周({$cur[0]} ~ {$cur[1]})"],
+                ["id"=>1,"name"=>"下周({$curnext[0]} ~ {$curnext[1]})"]
+            ];
+            $this->assign('weeks',$weeks);
+
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('dinner_group')->where('id',$id)->setField('del',1);
+        if($res){
+
+
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('dinner_group')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $name = '套餐:';
+            $content = '';
+            if($fn == 'enable'){
+                $content = $name.'禁用';
+                if($fv == 1){
+                    $content = $name.'启用';
+                }
+            }
+
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function setting($id=0,$day=''){
+        $info = Db::name('dinner_group')->where('id',$id)->find();
+        if(!$info){
+            $this->error('套餐不存在');
+        }
+        $day = $day?$day:$info['start'];
+        $this->assign('day',$day);
+
+        $weeks = [];
+        $stime = $info['start'];
+        while (true){
+            if($stime > $info['end']){
+                break;
+            }
+            $weeks[] = [
+                'day' => $stime,
+                'week' => get_week_txt($stime),
+            ];
+            $stime = date('Y-m-d',strtotime($stime) + 24*60*60);
+        }
+        $this->assign('weeks',$weeks);
+
+        $typeList = model('DinnerType')->getList($this->orgId);
+        foreach ($typeList as $k=>$v){
+            $limit = Db::name('dinner_group_type')
+                ->where('group_id',$id)
+                ->where('day',$day)
+                ->where('dinner_type_id',$v['id'])
+                ->value('limit');
+            $typeList[$k]['limit'] = $limit?$limit:0;
+
+            $items = Db::name('dinner_group_item')
+                ->alias('a')
+                ->join('dinner b','a.dinner_id = b.id')
+                ->where('a.group_id',$id)
+                ->where('a.day',$day)
+                ->where('b.dinner_type_id',$v['id'])
+                ->field('a.id,a.money,a.dinner_id,b.name,b.money as oldmoney,b.imgs,a.required,a.max')
+                ->order('b.sort asc, a.id desc')
+                ->select();
+            foreach ($items as $kk=>$vv){
+                if($vv['money'] == 0 && $vv['oldmoney'] > 0){
+                    $items[$kk]['money'] = $vv['oldmoney'];
+                }
+                $imgs = $vv['imgs']?explode(',',$vv['imgs']):[];
+                $items[$kk]['img'] = $imgs?$imgs[0]:'';
+            }
+            $typeList[$k]['items'] = $items?$items:[];
+
+            // 组合
+            $combination = Db::name('dinner_group_combination')
+                ->where('group_id',$info['id'])
+                ->where('dinner_type_id',$v['id'])
+                ->where('day',$day)
+                ->select();
+            foreach ($combination as $kk=>$vv){
+                $items = explode(',',$vv['items']);
+                $names = Db::name('dinner')
+                    ->alias('a')
+                    ->join('dinner_group_item b','a.id = b.dinner_id')
+                    ->where('b.id','in',$items)
+                    ->column('name');
+                $combination[$kk]['names'] = $names?implode(',',$names):'';
+            }
+            $typeList[$k]['combination'] = $combination?$combination:[];
+
+            // 互斥组合
+            $combination2 = Db::name('dinner_group_combination2')
+                ->where('group_id',$info['id'])
+                ->where('dinner_type_id',$v['id'])
+                ->where('day',$day)
+                ->select();
+            foreach ($combination2 as $kk=>$vv){
+                $items = explode(',',$vv['items']);
+                $names = Db::name('dinner')
+                    ->alias('a')
+                    ->join('dinner_group_item b','a.id = b.dinner_id')
+                    ->where('b.id','in',$items)
+                    ->column('name');
+                $combination2[$kk]['names'] = $names?implode(',',$names):'';
+            }
+            $typeList[$k]['combination2'] = $combination2?$combination2:[];
+        }
+//        halt($typeList);
+        $this->assign('typeList',$typeList);
+
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+    // 选择种类限制
+    public function limits(){
+        $groupId = input('id/d',0);
+        $day = input('day','','trim');
+        $typeId = input('typeId/d',0);
+        $info = Db::name('dinner_group_type')
+            ->where('group_id',$groupId)
+            ->where('day',$day)
+            ->where('dinner_type_id',$typeId)
+            ->find();
+        if(request()->isPost()){
+            $limit = input('limit/d',0);
+            if($limit < 0){
+                $this->error('限制数不能小于0');
+            }
+            if($info){
+                if($info['limit'] == $limit){
+                    $ret = true;
+                }else{
+                    $ret = Db::name('dinner_group_type')->where('id',$info['id'])->update(['limit'=>$limit]);
+                }
+            }else{
+                $ret = Db::name('dinner_group_type')->insert([
+                    'group_id' => $groupId,
+                    'day' => $day,
+                    'dinner_type_id' => $typeId,
+                    'limit' => $limit
+                ]);
+            }
+            if($ret){
+
+                $this->success('操作成功');
+            }else{
+                $this->error('操作失败');
+            }
+        }else{
+            $this->assign('id',$groupId);
+            $this->assign('day',$day);
+            $this->assign('typeId',$typeId);
+            $limit = $info?$info['limit']:0;
+            $this->assign('limit',$limit);
+            return $this->fetch();
+        }
+    }
+
+    public function items($id=0,$typeId=0,$day=''){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['name','like','%'.$title.'%'];
+            }
+
+            $dids = Db::name('dinner_group_item')->where('group_id',$id)->where('day',$day)->column('dinner_id');
+            if($dids){
+                $map[] = ['id','not in',$dids];
+            }
+
+            $map[] = ['cate','=',1];
+            $map[] = ['dinner_type_id','=',$typeId];
+            $map[] = ['enable','=',1];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('dinner')->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $img = $v['imgs']?explode(',',$v['imgs']):[];
+                $lists[$k]['img'] = $img?$img[0]:'';
+            }
+
+            //数据返回
+            $totalCount = Db::name('dinner')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('id',$id);
+            $this->assign('day',$day);
+            $this->assign('typeId',$typeId);
+            return $this->fetch();
+        }
+    }
+
+    public function itemsave(){
+        $groupId = input('groupId/d',0);
+        $day = input('day','','trim');
+        $id = input('id/d',0);
+        if($groupId<=0 || !$day || $id < 0){
+            $this->error('参数错误');
+        }
+        $dinner = Db::name('dinner')->where('id',$id)->find();
+        if(!$dinner){
+            $this->error('菜品不存在');
+        }
+        $info = Db::name('dinner_group_item')->where('dinner_id',$id)->where('day',$day)->find();
+        if($info){
+            $this->error('已添加,无重复');
+        }
+        $data = [
+            'group_id' => $groupId,
+            'day' => $day,
+            'dinner_id' => $id,
+            'required' => 0,
+            'money' => $dinner['money']
+        ];
+        $ret = Db::name('dinner_group_item')->insert($data);
+        if($ret){
+
+            $this->success('操作成功');
+        }else{
+            $this->success('操作失败');
+        }
+    }
+
+    public function itemdel(){
+        $id = input('id/d',0);
+        if($id < 0){
+            $this->error('参数错误');
+        }
+        $info = Db::name('dinner_group_item')->where('id',$id)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+
+        Db::startTrans();
+        try{
+            $ret = Db::name('dinner_group_item')->delete($id);
+            if(!$ret){
+                \exception('操作失败2');
+            }
+
+            // 消除组合里的商品
+            $map[]=['','exp',Db::raw("FIND_IN_SET({$id},items)")];
+            $lists = Db::name('dinner_group_combination')->where($map)->select();
+            $lists = $lists?$lists:[];
+            foreach ($lists as $k=>$v){
+                $items = explode(',',$v['items']);
+                $items = array_diff($items,[$id]);
+                sort($items);
+
+                if(count($items) <= 1){
+                    $ret = Db::name('dinner_group_combination')->delete($v['id']);
+                }else{
+                    $ret = Db::name('dinner_group_combination')
+                        ->where('id',$v['id'])
+                        ->update(['items'=>implode(',',$items)]);
+
+                }
+                if(!$ret){
+                    \exception('操作失败1');
+                }
+            }
+
+            // 消除互斥组合里的商品
+            $map2[]=['','exp',Db::raw("FIND_IN_SET({$id},items)")];
+            $lists = Db::name('dinner_group_combination2')->where($map2)->select();
+            $lists = $lists?$lists:[];
+            foreach ($lists as $k=>$v){
+                $items = explode(',',$v['items']);
+                $items = array_diff($items,[$id]);
+                sort($items);
+
+                if(count($items) <= 1){
+                    $ret = Db::name('dinner_group_combination2')->delete($v['id']);
+                }else{
+                    $ret = Db::name('dinner_group_combination2')
+                        ->where('id',$v['id'])
+                        ->update(['items'=>implode(',',$items)]);
+
+                }
+                if(!$ret){
+                    \exception('操作失败1');
+                }
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败'.$e->getMessage());
+        }
+        $this->success('操作成功');
+    }
+
+    public function itemcombination(){
+        $id = input('id/d',0);
+        if($id < 0){
+            $this->error('参数错误');
+        }
+        $info = Db::name('dinner_group_combination')->where('id',$id)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+
+        $ret = Db::name('dinner_group_combination')->delete($id);
+        if($ret){
+            $this->success('操作成功');
+        }else{
+            $this->success('操作失败');
+        }
+    }
+
+    public function itemrequired(){
+        $id = input('id/d',0);
+        if($id < 0){
+            $this->error('参数错误');
+        }
+        $info = Db::name('dinner_group_item')->where('id',$id)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+
+        $ret = Db::name('dinner_group_item')->where('id',$id)->update(['required' => $info['required']==1?0:1]);
+        if($ret){
+            $this->success('操作成功');
+        }else{
+            $this->success('操作失败');
+        }
+    }
+
+    public function itemmax(){
+        $id = input('id/d',0);
+        $val = input('val/d',0);
+        if($id < 0 || $val < 0){
+            $this->error('参数错误');
+        }
+        $info = Db::name('dinner_group_item')->where('id',$id)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+
+        $ret = Db::name('dinner_group_item')->where('id',$id)->update(['max' => $val]);
+        if($ret){
+            $info['val'] = $val;
+            $this->success('操作成功');
+        }else{
+            $this->success('操作失败');
+        }
+    }
+
+    public function itemmoney(){
+        $id = input('id/d',0);
+        $val = input('val/f',0);
+        if($id < 0 || $val < 0){
+            $this->error('参数错误');
+        }
+        $info = Db::name('dinner_group_item')->where('id',$id)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+
+        $ret = Db::name('dinner_group_item')->where('id',$id)->update(['money' => $val]);
+        if($ret){
+            $info['money'] = $val;
+            $this->success('操作成功');
+        }else{
+            $this->success('操作失败');
+        }
+    }
+
+    public function combination(){
+        if(request()->isPost()){
+            $data = [
+                'title' => input('title','','trim'),
+                'group_id' => input('group_id/d',0),
+                'day' => input('day','','trim'),
+                'dinner_type_id' => input('dinner_type_id/d',0),
+                'items' => input('items','','trim')
+            ];
+            if(!$data['title']){
+                $this->error('请输入名称');
+            }
+            if(!$data['items'] && !format_str($data['items'])){
+                $this->error('请选择菜品');
+            }
+            $items = explode(',',format_str($data['items']));
+            sort($items);
+            if(count($items) <= 1){
+                $this->error('组合至少要选两种菜品');
+            }
+            $data['items'] = implode(',',$items);
+
+            $ret = Db::name('dinner_group_combination')
+                ->where('group_id',$data['group_id'])
+                ->where('day',$data['day'])
+                ->where('dinner_type_id',$data['dinner_type_id'])
+                ->column('items');
+            $ret = $ret?$ret:[];
+            $aitems = [];
+            foreach ($ret as $k=>$v){
+                $aitems = array_merge($aitems,explode(',',$v));
+            }
+            if(array_intersect($items,$aitems)){
+                $this->error('选择的部分商品已在其他组合中');
+            }
+
+            $ret = Db::name('dinner_group_combination')->insert($data);
+            if(!$ret){
+                $this->error('操作失败');
+            }
+            $this->success('操作成功');
+        }else{
+            $groupId = input('groupId/d',0);
+            $typeId = input('typeId/d',0);
+            $day = input('day','','trim');
+
+            $dinners = Db::name('dinner_group_item')
+                ->alias('a')
+                ->join('dinner b','a.dinner_id = b.id')
+                ->where('a.group_id',$groupId)
+                ->where('a.day',$day)
+                ->where('b.dinner_type_id',$typeId)
+                ->field('a.id,b.name as title')
+                ->select();
+            $this->assign('groupId',$groupId);
+            $this->assign('typeId',$typeId);
+            $this->assign('day',$day);
+            $this->assign('dinners',$dinners);
+            return $this->fetch();
+        }
+
+    }
+
+    public function combinationdel(){
+        $id = input('id/d',0);
+        if($id < 0){
+            $this->error('参数错误');
+        }
+        $info = Db::name('dinner_group_combination')->where('id',$id)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+
+        Db::startTrans();
+        try{
+            $ret = Db::name('dinner_group_combination')->delete($id);
+            if(!$ret){
+                \exception('操作失败');
+            }
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败'.$e->getMessage());
+        }
+        $this->success('操作成功');
+    }
+
+    public function combination2(){
+        if(request()->isPost()){
+            $data = [
+                'group_id' => input('group_id/d',0),
+                'day' => input('day','','trim'),
+                'dinner_type_id' => input('dinner_type_id/d',0),
+                'items' => input('items','','trim')
+            ];
+            if(!$data['items'] && !format_str($data['items'])){
+                $this->error('请选择菜品');
+            }
+            $items = explode(',',format_str($data['items']));
+            sort($items);
+            if(count($items) <= 1){
+                $this->error('组合至少要选两种菜品');
+            }
+            $data['items'] = implode(',',$items);
+
+//            $ret = Db::name('dinner_group_combination2')
+//                ->where('group_id',$data['group_id'])
+//                ->where('day',$data['day'])
+//                ->where('dinner_type_id',$data['dinner_type_id'])
+//                ->column('items');
+//            $ret = $ret?$ret:[];
+//            $aitems = [];
+//            foreach ($ret as $k=>$v){
+//                $aitems = array_merge($aitems,explode(',',$v));
+//            }
+//            if(array_intersect($items,$aitems)){
+//                $this->error('选择的部分商品已在其他组合中');
+//            }
+
+            $ret = Db::name('dinner_group_combination2')->insert($data);
+            if(!$ret){
+                $this->error('操作失败');
+            }
+            $this->success('操作成功');
+        }else{
+            $groupId = input('groupId/d',0);
+            $typeId = input('typeId/d',0);
+            $day = input('day','','trim');
+
+            $dinners = Db::name('dinner_group_item')
+                ->alias('a')
+                ->join('dinner b','a.dinner_id = b.id')
+                ->where('a.group_id',$groupId)
+                ->where('a.day',$day)
+                ->where('b.dinner_type_id',$typeId)
+                ->field('a.id,b.name as title')
+                ->select();
+            $this->assign('groupId',$groupId);
+            $this->assign('typeId',$typeId);
+            $this->assign('day',$day);
+            $this->assign('dinners',$dinners);
+            return $this->fetch();
+        }
+
+    }
+
+    public function combination2del(){
+        $id = input('id/d',0);
+        if($id < 0){
+            $this->error('参数错误');
+        }
+        $info = Db::name('dinner_group_combination2')->where('id',$id)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+
+        Db::startTrans();
+        try{
+            $ret = Db::name('dinner_group_combination2')->delete($id);
+            if(!$ret){
+                \exception('操作失败');
+            }
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败'.$e->getMessage());
+        }
+        $this->success('操作成功');
+    }
+}

File diff suppressed because it is too large
+ 1908 - 0
application/admin/controller/DinnerOrder.php


+ 249 - 0
application/admin/controller/DinnerRefuseOrder.php

@@ -0,0 +1,249 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class DinnerRefuseOrder extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='dinner_order_refuse';
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('sn','','trim');
+            if($title){
+                $map[] = ['b.sn','like','%'.$title.'%'];
+            }
+
+            $map[] = ['a.org_id','=',$this->orgId];
+            $map[] = ['b.state','<>',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)
+                ->alias('a')
+                ->join('dinner_order b','a.dinner_order_id=b.id')
+                ->field('b.id,b.sn,b.price,b.name,b.mobile,b.address,b.remark,b.pay_time,a.create_time,a.op_time,a.status,a.id as refuse_id')
+                ->where($map)->limit($start,$length)->order(
+                ['a.id'=>'desc']
+            )->select();
+
+            foreach ($lists as $k=>$v){
+                $all = Db::name('dinner_order_item')
+                ->alias('a')
+                ->join('dinner b','a.dinner_id=b.id')
+                ->join('dinner_type c','a.dinner_type_id=c.id')
+                ->field('a.*,b.name as dinner_name,c.color,c.name as dinner_type_name')
+                ->where('a.order_id',$v['id'])
+                ->select();
+
+                $item = '';
+                foreach ($all as $k2=>$v2){
+                    $ss = $k2+1;
+                    if($ss<10){
+                        $ss= '0'.$ss;
+                    }
+                    $ur = url('dinner/detail').'?id='.$v2['dinner_id'];
+                    $item.=''.$ss.',<span class="label" style="border-radius:0rem !important;background-color: '.$v2['color'].';color: white">'.$v2['dinner_type_name'].'</span><a  data-title="详情" href="javascript:;" url="'.$ur.'">'.$v2['dinner_name'].'*'.$v2['num'];
+                    if(count($all)>1 && $k2<count($all)){
+                        $item.='<br/>';
+                    }
+                }
+                $lists[$k]['item'] = $item;
+
+                $refuse = Db::name('dinner_order_refuse_item')
+                    ->alias('a')
+                    ->join('dinner b','a.dinner_id=b.id')
+                    ->join('dinner_type c','a.dinner_type_id=c.id')
+                    ->field('a.*,b.name as dinner_name,c.color,c.name as dinner_type_name')
+                    ->where('a.order_refuse_id',$v['refuse_id'])
+                    ->select();
+
+                $item_refuse = '';
+                foreach ($refuse as $k3=>$v3){
+                    $ss1 = $k3+1;
+                    if($ss1<10){
+                        $ss1= '0'.$ss1;
+                    }
+                    $ur = url('dinner/detail').'?id='.$v3['dinner_id'];
+                    $item_refuse.=''.$ss1.',<span class="label" style="border-radius:0rem !important;background-color: '.$v3['color'].';color: white">'.$v3['dinner_type_name'].'</span><a  onclick="layer_open(this,0)" data-title="详情" href="javascript:;" url="'.$ur.'">'.$v3['dinner_name'].'*'.$v3['num'];
+                    if(count($refuse)>1 && $k3<count($refuse)){
+                        $item_refuse.='<br/>';
+                    }
+                }
+                $lists[$k]['item_refuse'] = $item_refuse;
+
+                $status_txt = '';
+                if($v['status']==4){
+                    $status_txt ='<span class="label" style="border-radius:0rem !important;background-color: #d15b47;color: white">正在退款中</span><br/>'.$v['sn'].'';
+                }elseif ($v['status']==5){
+                    $status_txt ='<span class="label" style="border-radius:0rem !important;background-color: #82af6f;color: white">已退款</span><br/>'.$v['sn'].'';
+                }elseif ($v['status']==6){
+                    $status_txt ='<span class="label" style="border-radius:0rem !important;background-color: #3a87ad;color: white">申请退款被拒</span><br/>'.$v['sn'].'';
+
+                }
+                $lists[$k]['status_txt'] = $status_txt;
+                $lists[$k]['op_time'] = $v['op_time']?$v['op_time']:'';
+
+            }
+            //数据返回
+            $totalCount = db($this->table)
+                ->alias('a')
+                ->join('dinner_order b','a.dinner_order_id=b.id')
+                ->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            return $this->fetch();
+        }
+    }
+
+    public function option($id=0){
+        if(request()->isPost()){
+            $res = Db::name($this->table)
+                ->where('org_id',$this->orgId)
+                ->where('id',$id)
+                ->find();
+            if($res['status']!==4){
+                $this->error('当前订单已操作');
+            }
+            $order = Db::name('dinner_order')->where('id',$res['dinner_order_id'])->find();
+            if(!$order){
+                $this->error('订单不存在');
+            }
+            $status = input('status','');
+            $remark = input('refuse_remark','');
+            if(!in_array($status,[5,6])){
+                $this->error('参数错误');
+            }
+            Db::startTrans();
+            try{
+                if($order['cate'] == 0){
+                    $r = Db::name('dinner_order')
+                        ->where('id',$res['dinner_order_id'])
+                        ->update([
+                            'state'=>$status,
+                            'update_time'=>getTime()
+                        ]);
+
+                    if(!$r){
+                        \exception('操作失败');
+                    }
+                }else{
+                    if($status==5){
+                        $checkAll =  Db::name('dinner_order_item')
+                            ->where('order_id',$res['dinner_order_id'])
+                            ->where('is_refuse',0)
+                            ->find();
+                        if(!$checkAll){//已退款
+                            Db::name('dinner_order')
+                                ->where('id',$res['dinner_order_id'])
+                                ->update([
+                                    'state'=>5,
+                                    'update_time'=>getTime()
+                                ]);
+                        }
+                    }
+                }
+
+                $r = Db::name($this->table)
+                    ->where('id',$id)
+                    ->update([
+                        'status'=>$status,
+                        'op_user_id'=>$this->userId,
+                        'op_time'=>getTime(),
+                        'refuse_remark'=>$remark
+                    ]);
+                if(!$r){
+                    \exception('操作失败');
+                }
+                if($status==5&&$res['order_type']==1&&$res['is_replace']==0) {
+                    $checkAll =  Db::name('dinner_order_item')
+                        ->where('order_id',$res['dinner_order_id'])
+                        ->where('is_refuse',0)
+                        ->find();
+                    if($checkAll){//部分退款
+                         Db::name('dinner_order')
+                            ->where('id',$res['dinner_order_id'])
+                            ->update([
+                                'state'=>7,
+                                'update_time'=>getTime()
+                            ]);
+                    }
+                    if($res['refuse_price'] > 0){
+                        $orderInfo = Db::name('dinner_order')
+                            ->where('id',$res['dinner_order_id'])
+                            ->find();
+                        $config =get_pay_wechat($orderInfo['org_id']);
+
+                        if(empty($config['mch_id']) || empty($config['key'])){
+                            \exception('微信商户信息未配置,请联系管理员');
+                        }
+                        $app = \EasyWeChat\Factory::payment($config);
+                        $totalFee = intval(round($orderInfo['price']*100));
+                        $refundFee = intval(round($res['refuse_price']*100));
+                        $ret = $app->refund->byOutTradeNumber($orderInfo['sn'], 'T'.$orderInfo['sn'], $totalFee, $refundFee);
+                        if($ret['return_code'] != 'SUCCESS' || $ret['result_code'] != 'SUCCESS'){
+                            trace(json_encode($ret),'error');
+                            \exception('退款申请提交失败');
+                        }
+                    }
+                }
+                if($status==6){ // 拒绝,返还
+                    $all = Db::name('dinner_order_refuse_item')->where('order_refuse_id',$id)->select();
+
+                    if($order['cate'] == 0){
+                        foreach ($all as $k=>$v){
+                            Db::name('dinner_order_item')
+                                ->where('dinner_id',$v['dinner_id'])
+                                ->where('dinner_type_id',$v['dinner_type_id'])
+                                ->where('is_refuse',1)
+                                ->setField('is_refuse',0);
+                        }
+                    }else{
+                        foreach ($all as $k=>$v){
+                            Db::name('dinner_order_item')
+                                ->where('dinner_id',$v['dinner_id'])
+                                ->where('dinner_type_id',$v['dinner_type_id'])
+                                ->where('order_id',$res['dinner_order_id'])
+                                ->where('day',$v['day'])
+                                ->where('is_refuse',1)
+                                ->update(['is_refuse'=>0]);
+                        }
+                    }
+                }
+
+
+
+                Db::commit();
+                $this->success('操作成功');
+            }catch (Exception $e){
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+
+        }else{
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+
+
+}

+ 120 - 0
application/admin/controller/DinnerType.php

@@ -0,0 +1,120 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class DinnerType extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='dinner_type';
+        $this->model= new \app\common\model\DinnerType();
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['name','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+
+
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $name = '菜品分类:';
+            $content = '';
+            if($fn == 'enable'){
+                $content = $name.'禁用';
+                if($fv == 1){
+                    $content = $name.'启用';
+                }
+            }
+
+
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+}

+ 108 - 0
application/admin/controller/DinnerUser.php

@@ -0,0 +1,108 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class DinnerUser extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='dinner_user';
+        $this->model= new \app\common\model\DinnerUser();
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['name','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+}

+ 126 - 0
application/admin/controller/DinnerWechat.php

@@ -0,0 +1,126 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\model\User;
+use think\App;
+use think\Db;
+
+class DinnerWechat extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\DinnerWechat();
+        $this->table= $this->model->table;
+
+    }
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = 'a.id desc';
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['o.name','like','%'.$title.'%'];
+            }
+
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('dinner_wechat')
+                ->alias('a')
+                ->join('org o','a.org_id = o.id')
+                ->field('a.*,o.name')
+                ->where($map)
+                ->limit($start,$length)
+                ->order($order)
+                ->select();
+
+            //数据返回
+            $totalCount = Db::name('dinner_wechat')
+                ->alias('a')
+                ->join('org o','a.org_id = o.id')
+                ->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    public function index2(){
+        $map[] = ['org_id','=',$this->orgId];
+        $info = Db::name('dinner_wechat')
+            ->where($map)
+            ->find();
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+    /**
+     * 新增/编辑
+     */
+//    public function add($id=0){
+//        if(request()->isPost()){
+//            $res = $this->model->updates();
+//            if($res){
+//                $this->success('操作成功',url('index'));
+//            }else{
+//                $this->error($this->model->getError());
+//            }
+//        }
+//    }
+
+
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            $meta_title = '新增配置';
+            if($id){
+                $info = Db::name('dinner_wechat')->where('id',$id)->find();
+                $this->assign('info',$info);
+                $meta_title = '编辑配置';
+            }
+            $this->assign('meta_title',$meta_title);
+            $orgs = Db::name('org')->where('del',0)->where('type',2)->field('id,name as title')->select();
+            $this->assign('orgs',$orgs);
+
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        $info = Db::name('dinner_wechat')->where('id',$id)->find();
+        if(!$info){
+            $this->error('该记录不存在');
+        }
+        $res = Db::name('dinner_wechat')->delete($id);
+        if($res){
+
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+}

+ 125 - 0
application/admin/controller/Feedback.php

@@ -0,0 +1,125 @@
+<?php
+namespace app\admin\controller;
+
+class Feedback extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('user_name','','trim');
+            if($title){
+                $map[] = ['u.real_name','like','%'.$title.'%'];
+            }
+
+//            $map[] = ['org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('feedback')
+                ->alias('f')
+                ->field('f.*,u.real_name')
+                ->join('user u','u.id=f.user_id')
+                ->limit($start,$length)
+                ->where($map)
+                ->order($order)
+                ->select();
+
+
+            //数据返回
+            $totalCount = db('feedback')
+                ->alias('f')
+                ->field('f.*,u.real_name')
+                ->join('user u','u.id=f.user_id')
+                ->where($map)
+                ->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function opinion($id=0){
+        if(request()->isPost()){
+            $res = model('Feedback')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('Feedback')->getError());
+            }
+        }else{
+            if($id){
+                $info = db('feedback')->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 详情
+     * @param int $id
+     */
+    public function details($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $info = db('feedback')->where('id',$id)->find();
+        $info['real_name'] = db('user')->where('id',$info['user_id'])->value('real_name');
+        $info['to_user'] = db('user')->where('id',$info['to_user_id'])->value('real_name');
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('feedback')->where('id',$id)->delete();
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('feedback')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+}

+ 43 - 0
application/admin/controller/File.php

@@ -0,0 +1,43 @@
+<?php
+namespace app\admin\controller;
+
+use app\hander\HelpHander;
+
+class File extends Auth
+{
+
+    public function upfile(){
+        $file = request()->file('files');
+        // 移动到框架应用根目录/uploads/ 目录下
+        $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
+            ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
+        if($info){
+            $img = '/uploads/files/' . $info->getSaveName();
+            $img = str_replace('\\', '/', $img);
+
+            $path = request()->domain(true).$img;
+            HelpHander::success(['path' => $path]);
+        }else{
+            HelpHander::error($file->getError());
+        }
+    }
+
+    public function upimg(){
+        $file = request()->file('files');
+        // 移动到框架应用根目录/uploads/ 目录下
+        $info = $file->validate(config('app.max_upload_img'))
+            ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
+        if($info){
+            $img = '/uploads/files/' . $info->getSaveName();
+            $img = str_replace('\\', '/', $img);
+
+            $path = request()->domain(true).$img;
+            HelpHander::success(['path' => $path]);
+        }else{
+            HelpHander::error($file->getError());
+        }
+    }
+
+}
+
+

+ 111 - 0
application/admin/controller/GGoods.php

@@ -0,0 +1,111 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class GGoods extends Auth
+{
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['org_id','=',cur_org_id()];
+            $map[] = ['del','=',0];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('g_goods')->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['cate_name']=Db::name('g_goods_cate')->where('id',$v['cate_id'])->value('title');
+
+            }
+            //数据返回
+            $totalCount = Db::name('g_goods')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','商品列表');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('GGoods')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('GGoods')->getError());
+            }
+        }else{
+            $meta_title = '新增商品';
+            if($id){
+                $info = Db::name('g_goods')->where('id',$id)->find();
+                $this->assign('info',$info);
+                $meta_title = '编辑商品';
+            }
+            //获取分类
+            $map['org_id'] = cur_org_id();
+            $map['enable'] = 1;
+            $cate = Db::name('g_goods_cate')->field('id as cate_id,title')->where($map)->select();
+            $this->assign('goods_cate',$cate);
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('g_goods')->where('id',$id)->update(['del'=>1]);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('g_goods')->where('id',$id)->update([$fn => $fv]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+}

+ 106 - 0
application/admin/controller/GGoodsCate.php

@@ -0,0 +1,106 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class GGoodsCate extends Auth
+{
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('g_goods_cate')->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = Db::name('g_goods_cate')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','商品分类列表');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('GGoodsCate')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('GGoodsCate')->getError());
+            }
+        }else{
+            $meta_title = '新增商品分类';
+            if($id){
+                $info = Db::name('g_goods_cate')->where('id',$id)->find();
+                $this->assign('info',$info);
+                $meta_title = '编辑商品分类';
+            }
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $ret = Db::name('g_goods')->where('cate_id',$id)->where('del',0)->find();
+        if($ret){
+            $this->error('已被使用,无法删除');
+        }
+        $res = Db::name('g_goods_cate')->delete($id);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('g_goods_cate')->where('id',$id)->update([$fn => $fv]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+}

+ 59 - 0
application/admin/controller/GOrderRefund.php

@@ -0,0 +1,59 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class GOrderRefund extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='g_order_refund';
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['userName'] = Db::name('user')
+                    ->where('id',$v['user_id'])
+                    ->value('real_name');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+
+
+}

+ 94 - 0
application/admin/controller/GOrders.php

@@ -0,0 +1,94 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class GOrders extends Auth
+{
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','sort','trim');      //排序列
+            $sort = input('sord','asc','trim');        //排序方式
+            $order = $sortRow.' '.$sort.' ,id desc';
+
+            $order_sn = input('order_sn','','trim');
+            if($order_sn){
+                $map[] = ['order_sn','=',$order_sn];
+            }
+            $name = input('name','','trim');
+            if($name){
+                $map[] = ['name','like','%'.$name.'%'];
+            }
+            $status = input('status','','trim');
+            if($status != ''){
+                $map[] = ['status','=',$status];
+            }
+//            if($this->user_id > 1){
+//                $map[] = ['user_id','=',$this->user_id];
+//            }
+            $map[] = ['org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('g_orders')->where($map)->limit($start,$length)->order($order)->select();
+            //数据返回
+            $totalCount = Db::name('g_orders')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','订单列表');
+            return $this->fetch();
+        }
+    }
+    public function details($id){
+        if(!$id){
+            $this->error('参数错误');
+        }
+
+        $ret = Db::name('g_orders')->where('id',$id)->find();
+        $ret['goods'] = $orderGoods = Db::name('g_order_goods')
+            ->alias('og')
+            ->field('og.nums,og.price,og.goods_id,g.title,g.img')
+            ->join('g_goods g', 'g.id=og.goods_id')
+            ->where('og.order_id', $ret['id'])
+            ->select();
+        if($ret['status']==1 && time() < (strtotime($ret['create_time'])+(7*24*3600))){
+            $ret['tk'] = 1;
+        }else{
+            $ret['tk'] = 0;
+
+        }
+        $this->assign('info',$ret);
+        $this->assign('meta_title','订单详情');
+        return $this->fetch();
+    }
+
+    /**
+     * 退款
+     */
+    public function refund($id = 0){
+        if(request()->isPost()){
+            $res = model('GOrders')->refundOrder($this->userId);
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('GOrders')->getError());
+            }
+        }else{
+            $pay = Db::name('g_orders')->where('id',$id)->find();
+            $money = $pay['amount'];
+            $this->assign('money',$money);
+            $this->assign('pay',$pay);
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+}

+ 184 - 0
application/admin/controller/Group.php

@@ -0,0 +1,184 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class Group extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] =['enable','=',$enable];
+            }
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = Db::name('group')
+                ->where($map)
+                ->limit($start,$length)
+                ->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['nums'] = Db::name('group_device')
+                    ->where('org_id',$this->orgId)
+                    ->where('group_id',$v['id'])
+                    ->count();
+            }
+            //数据返回
+            $totalCount = Db::name('group')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            $this->assign('meta_title','分组列表');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $model = new \app\common\model\Group();
+            $post = request()->post();
+            $data = [
+                'title'=>$post['title'],
+                'enable'=>$post['enable'],
+                'org_id'=>$this->orgId,
+                'id'=>$id
+            ];
+            $validate = new \app\common\validate\Group();
+            $result = $validate->scene('')->check($data,[]);
+            if(true !== $result){
+                $this->error($validate->getError());
+            }
+            unset($data['id']);
+            if($id <=0){
+                $data['create_time'] = date('Y-m-d H:i:s');
+                $res = Db::name('group')
+                    ->insertGetId($data);
+                $id = $res;
+            }else{
+                $data['update_time'] = date('Y-m-d H:i:s');
+                $res = Db::name('group')
+                    ->where('id',$id)
+                    ->update($data);
+            }
+            if($res){
+                Db::name('group_device')
+                    ->where('org_id',$this->orgId)
+                    ->where('group_id',$id)
+                    ->delete();
+                $data = request()->post();
+                if(isset($data['device_id']) && !empty($data['device_id'])){
+                    $ids = explode(',',$data['device_id']);
+                    $a = [];
+                    foreach ($ids as $k=>$v){
+                        $a[] = [
+                            'org_id'=>$this->orgId,
+                            'device_id'=>$v,
+                            'group_id'=>$id,
+                        ];
+                    }
+                    Db::name('group_device')
+                        ->insertAll($a);
+
+                }
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($model->getError());
+            }
+        }else{
+            $meta_title = '新增分组';
+            if($id){
+                $info = Db::name('group')->where('id',$id)->find();
+                $info['group_device'] = Db::name('group_device')
+                    ->where('org_id',$this->orgId)
+                    ->where('group_id',$id)
+                    ->column('device_id');
+                $this->assign('info',$info);
+
+
+                $meta_title = '编辑分组';
+                $device = (new \app\common\model\TemperatureDevice())->getIdSList($this->orgId,$id);
+
+            }else{
+                $device = (new \app\common\model\TemperatureDevice())->getAllList($this->orgId);
+
+            }
+
+            $this->assign('meta_title',$meta_title);
+            $this->assign('device',$device);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $ret = Db::name('temperature_device')->where('group_id',$id)->find();
+        if($ret){
+            $this->error('分组已被绑定,无法删除');
+        }
+        $res = Db::name('group')->where('id',$id)->delete();
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name('group')->where('id',$id)->update([$fn => $fv]);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function detail_auth($id){
+        $info = Db::name('group_device')
+            ->where('group_id', $id)->column('device_id');
+        $d = Db::name('temperature_device')
+            ->where('id','in',$info)
+            ->select();
+        $this->assign('list',$d);
+        return $this->fetch();
+
+    }
+
+}

+ 62 - 0
application/admin/controller/Gui.php

@@ -0,0 +1,62 @@
+<?php
+namespace app\admin\controller;
+use app\watch\controller\Api;
+use think\App;
+use think\facade\Db;
+
+class Gui extends Auth
+{
+    public function __construct(App $app) {
+        parent::__construct($app);
+        $this->api = new Api($this->app);
+    }
+    public function index(){
+
+        $id = request()->get('id');
+        if(empty($id)){
+            $d = $this->api->community(1,10);
+            if(!isset($d['objs'][0])) $this->error('没有添加设备');
+            $id = isset($d['objs'][0]['_id'])?$d['objs'][0]['_id']:'';
+        }
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $date = input('riqi','');
+            $imei = input('imei','');
+            $p = ['rows_per_page'=>$length,'page'=>$page];
+
+            if($date){
+               $p['time_begin'] = date('Ymd',strtotime($date));
+            }
+            if(!empty($imei)){
+                $id = $imei;
+            }
+            $list = $this->api->deviceLocationData($id,$p);
+            if(!$list['success']){
+                $this->error($list['error_desc']);
+            }
+            $data = [];
+            foreach ($list['objs'] as $k=>$v){
+                $a = [
+                    'id'=>$k+1,
+                    'address'=>$v['address'],
+                    'created_at'=>nDate($v['created_at']['$date']),
+                ];
+                $data[$k] = $a;
+            }
+            $result['page'] = $page;
+            $result['total'] = $list['page']['page_count'];
+            $result['records'] = $list['page']['total'];
+            $result['rows'] = $data;
+            return json($result);
+        }else{
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+
+
+
+
+}

+ 564 - 0
application/admin/controller/Hiddendanger.php

@@ -0,0 +1,564 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\model\Config;
+use think\App;
+use think\Db;
+use think\Exception;
+use think\Model;
+
+class Hiddendanger extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\Hiddendanger();
+        $this->table = 'hiddendanger';
+    }
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+            $content = input('content','','trim');
+            if($content){
+                $map[] = ['content','like','%'.$content.'%'];
+            }
+
+            $user = input('user','','trim');
+            if($user != ''){
+                $userIds = Db::name('user')->where('del',0)->where('real_name','like','%'.$user.'%')->column('id');
+                $map[] = ['create_user_id','in',$userIds];
+            }
+
+            $st = input('start','','trim');
+            if($st !=''){
+                $map[] = ['create_time','>=',$st.' 00:00:00'];
+            }
+
+            $et = input('end','','trim');
+            if($et !=''){
+                $map[] = ['create_time','<=',$et.' 23:59:59'];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $from = input('from', '', 'trim');
+            if ($from!='') {
+                if($from == 1){
+                    $map[] = ['order_id','>',0];
+                    $map[] = ['bus_type','<>',0];
+                    $map[] = ['to_from','=',0];
+                }else{
+                    $map[] = ['order_id','>',0];
+                    $map[] = ['bus_type','<>',0];
+                    $map[] = ['to_from','<>',0];
+                }
+            }
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)
+                ->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['depName'] = Db::name('dep')
+                    ->where('id',$v['dep_id'])
+                    ->value('title');
+                $lists[$k]['fromName'] = '';
+                if($v['order_id'] > 0 && $v['bus_type'] != 0){
+                    if($v['to_from']){
+                        $lists[$k]['fromName'] = '一键呼叫';
+                    }else{
+                        $lists[$k]['fromName'] = '投诉';
+                    }
+                }
+                $lists[$k]['worktypemode'] = '';
+                if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
+                    $worktype = Db::name('orders')
+                        ->alias('o')
+                        ->join('work_type_mode w','o.work_type_mode = w.id')
+                        ->where('o.id',$v['order_id'])
+                        ->value('w.name');
+                    $lists[$k]['worktypemode'] = $worktype?$worktype:'';
+                }
+
+                $lists[$k]['realName'] = Db::name('user')
+                    ->where('id',$v['create_user_id'])
+                    ->value('real_name');
+//                $lists[$k]['statusTxt'] = $v['status']==1?'已处理':"未处理";
+                $orderMode = 0;
+                if($v['order_id'] > 0){
+                    $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
+                }
+
+                $lists[$k]['statusTxt'] = model('Hiddendanger')->formatStatus($v['status'],$v['order_id'],$v['id']);
+                $lists[$k]['order_mode'] = $orderMode;
+            }
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch('index');
+
+        }
+    }
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = Db::name($this->table)
+            ->where('id',$id)
+            ->update([
+                'del'=>1,
+                'del_user_id'=>$this->userId,
+                'del_time'=>getTime(),
+            ]);
+        if(!$res){
+            $this->error('删除失败');
+        }
+        $this->success('删除成功');
+    }
+
+    public function edit($id){
+        if(request()->isGet()){
+
+            $this->assign('id',$id);
+            return $this->fetch();
+        }else{
+            $info = Db::name($this->table)
+                ->where('id',$id)
+                ->find();
+            if(!$info){
+                $this->error('记录不存在');
+            }
+            if($info['status'] == 1){
+                $this->error('该记录已处理');
+            }
+            $curRoles = Db::name('user_roles')
+                ->where('user_id',$this->userId)
+                ->value('roles_id');
+            $data = array(
+                'curr_roles_id' => $curRoles,
+                'note' => input('note',TRUE),
+                'status' => 1,
+                'update_time' => date('Y-m-d H:i:s'),
+                'hand_user_id' => $this->userId
+            );
+            $res =Db::name($this->table)
+                ->where(array('id'=>$id))
+                ->update($data);
+            $res?$this->success('处理成功'):$this->error('处理失败');
+        }
+    }
+    public function detail($id){
+
+        $info = Db::name($this->table)
+            ->where('id',$id)
+            ->find();
+        $info['depName'] = Db::name('dep')
+            ->where('id',$info['dep_id'])
+            ->value('title');
+        $info['realName'] = Db::name('user')
+            ->where('id',$info['create_user_id'])
+            ->value('real_name');;
+//        $info['statusTxt'] = $info['status']==1?'已处理':"未处理";
+        $info['images'] = !empty($info['images'])?explode(',',$info['images']):'';
+
+        $orderMode = 0;
+        if($info['order_id'] > 0){
+            $orderMode = Db::name('orders')->where('id',$info['order_id'])->value('order_mode');
+        }
+
+        $info['statusTxt'] = model('Hiddendanger')->formatStatus($info['status'],$info['order_id'],$info['id']);
+        $info['order_mode'] = $orderMode;
+
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+    public function yhDetail($id){
+
+        $info = Db::name($this->table)
+            ->where('id',$id)
+            ->find();
+        $info['depName'] = Db::name('dep')
+            ->where('id',$info['dep_id'])
+            ->value('title');
+        $info['realName'] = Db::name('user')
+            ->where('id',$info['create_user_id'])
+            ->value('real_name');;
+//        $info['statusTxt'] = $info['status']==1?'已处理':"未处理";
+        $info['images'] = !empty($info['images'])?explode(',',$info['images']):'';
+
+        $orderMode = 0;
+        if($info['order_id'] > 0){
+            $orderMode = Db::name('orders')->where('id',$info['order_id'])->value('order_mode');
+        }
+
+        $info['statusTxt'] = model('Hiddendanger')->formatStatus($info['status'],$info['order_id'],$info['id']);
+        $info['order_mode'] = $orderMode;
+
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+    //派单
+    public function send($id) {
+        if (request()->isGet()) {
+            $this->assign('id', $id);
+            $hiddendanger = Db::name($this->table)->where('id',$id)->find();
+            $this->assign('hiddendanger',$hiddendanger);
+            $order_type = (new \app\common\model\OrderType())->getList();
+            $address = (new \app\common\model\Address())->getListByType(1);
+            $this->assign('order_type_list', $order_type);
+            $this->assign('address_list', $address);
+            $order_repair = Db::name('order_repair')
+                ->where('order_id', $id)
+                ->find();
+            $this->assign('order_repair', $order_repair);
+
+            $workType = Db::name('work_type_mode')
+                ->where('type',1)
+                ->select();
+            $config = Db::name('config')
+                ->where('name','web_order_transfer_type')
+                ->value('value');
+            if(empty($config)){
+                $workType = [];
+            }else{
+                $ll = explode('|',$config);
+                foreach ($workType as $kk=>$vv){
+                    if(!in_array($vv['id'],$ll)){
+                        unset($workType[$kk]);
+                    }
+                }
+            }
+            foreach ($workType as $k=>$v){
+                $this->assign('send_user_num'.$v['id'], model('Orders')->sendUserNum($v['id'], $this->orgId));
+                $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
+                $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
+                $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
+            }
+
+            $this->assign('dispatch_type', check_two_dispatch($this->userId));
+            $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
+            $this->assign('workType', $workType);
+            $address = (new \app\common\model\Address())->getListByType(2);
+            $conveyCate = (new \app\common\model\ConveyCate());
+            $priority = $conveyCate->priority;
+            $order_convey = $conveyCate->getList();
+            $order_device = (new \app\common\model\ConveyDevice())->getList();
+            $this->assign('address', $address);
+            $this->assign('priority', $priority);
+            $this->assign('order_convey_type', $order_convey);
+            $this->assign('order_device', $order_device);
+            $oCid = Db::name('order_convey')
+                ->where('order_id',-1)
+                ->find();
+            $opt = Db::name('order_convey_patient')
+                ->where('order_id',-1)
+                ->find();
+
+            $this->assign('ocid',$oCid);
+            $this->assign('opt',$opt);
+            $this->assign('ps',empty($opt)?1:0);
+            $auths = [1,2,3,4,15,0];
+            if(!is_admin($this->userId)){
+                $auth = get_dispatch_auth($this->userId);
+                if($auth){
+                    $auths = array_intersect($auths,$auth);
+                }else{
+                    $auths = [];
+                }
+            }
+            $this->assign('auths',$auths);
+            return $this->fetch();
+        }
+        else {
+            $data = request()->post();
+            $data['org_id'] = $this->orgId;
+            $res = model('Hiddendanger')->send($id, $this->userId, $data);
+
+            if (!$res) {
+                $this->error(model('Hiddendanger')->getError());
+            }
+            $this->success('操作成功');
+        }
+    }
+    //转单
+    public function ts_send($id) {
+        if (request()->isGet()) {
+            $this->assign('id', $id);
+            $hiddendanger = Db::name($this->table)->where('id',$id)->find();
+            $this->assign('hiddendanger',$hiddendanger);
+            $order_type = (new \app\common\model\OrderType())->getList();
+            $address = (new \app\common\model\Address())->getListByType(1);
+            $this->assign('order_type_list', $order_type);
+            $this->assign('address_list', $address);
+            $order_repair = Db::name('order_repair')
+                ->where('order_id', $id)
+                ->find();
+            $this->assign('order_repair', $order_repair);
+
+            $workType = Db::name('work_type_mode')
+                ->where('type',1)
+                ->select();
+            $config = Db::name('config')
+                ->where('name','web_order_transfer_type')
+                ->value('value');
+            if(empty($config)){
+                $workType = [];
+            }else{
+                $ll = explode('|',$config);
+                foreach ($workType as $kk=>$vv){
+                    if(!in_array($vv['id'],$ll)){
+                        unset($workType[$kk]);
+                    }
+                }
+            }
+            foreach ($workType as $k=>$v){
+                $this->assign('send_user_num'.$v['id'], model('Orders')->sendUserNum($v['id'], $this->orgId));
+                $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
+                $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
+                $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
+            }
+            foreach ($workType as $k=>$v){
+                if($v['id']!==0){
+                    unset($workType[$k]);
+                }
+            }
+            $this->assign('dispatch_type', check_two_dispatch($this->userId));
+            $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
+            $this->assign('workType', $workType);
+            $address = (new \app\common\model\Address())->getListByType(2);
+            $conveyCate = (new \app\common\model\ConveyCate());
+            $priority = $conveyCate->priority;
+            $order_convey = $conveyCate->getList();
+            $order_device = (new \app\common\model\ConveyDevice())->getList();
+            $this->assign('address', $address);
+            $this->assign('priority', $priority);
+            $this->assign('order_convey_type', $order_convey);
+            $this->assign('order_device', $order_device);
+            $oCid = Db::name('order_convey')
+                ->where('order_id',-1)
+                ->find();
+            $opt = Db::name('order_convey_patient')
+                ->where('order_id',-1)
+                ->find();
+
+            $this->assign('ocid',$oCid);
+            $this->assign('opt',$opt);
+            $this->assign('ps',empty($opt)?1:0);
+            $auths = [1,2,3,4,15,0];
+            if(!is_admin($this->userId)){
+                $auth = get_dispatch_auth($this->userId);
+                if($auth){
+                    $auths = array_intersect($auths,$auth);
+                }else{
+                    $auths = [];
+                }
+            }
+            $this->assign('auths',$auths);
+            return $this->fetch();
+        }
+        else {
+            $data = request()->post();
+            $data['org_id'] = $this->orgId;
+            $res = model('Hiddendanger')->zd_send($id, $data,$this->userId);
+            if (!$res) {
+                $this->error(model('Hiddendanger')->getError());
+            }
+            $this->success('操作成功');
+        }
+    }
+
+    public function summary($id){
+        if(request()->isGet()){
+            $info = Db::name('hiddendanger')
+                ->where('id',$id)
+                ->find();
+            $this->assign('info',$info);
+            $this->assign('id',$id);
+            return $this->fetch();
+        }else{
+
+            $data = array(
+                'summary' => input('summary','','trim'),
+                'update_time' => date('Y-m-d H:i:s'),
+            );
+            $res =Db::name($this->table)
+                ->where(array('id'=>$id))
+                ->update($data);
+            $res?$this->success('操作成功'):$this->error('操作失败');
+        }
+    }
+
+    public function export(){
+        $meta_title = '隐患订单';
+        if (request()->isGet()) {
+            $content = input('content','','trim');
+            if($content){
+                $map[] = ['content','like','%'.$content.'%'];
+            }
+
+            $user = input('user','','trim');
+            if($user != ''){
+                $userIds = Db::name('user')->where('del',0)->where('real_name','like','%'.$user.'%')->column('id');
+                $map[] = ['create_user_id','in',$userIds];
+            }
+
+            $st = input('start','','trim');
+            if($st !=''){
+                $map[] = ['create_time','>=',$st.' 00:00:00'];
+            }
+
+            $et = input('end','','trim');
+            if($et !=''){
+                $map[] = ['create_time','<=',$et.' 23:59:59'];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $from = input('from', '', 'trim');
+            if ($from!='') {
+                if($from == 1){
+                    $map[] = ['order_id','>',0];
+                    $map[] = ['bus_type','<>',0];
+                    $map[] = ['to_from','=',0];
+                }else{
+                    $map[] = ['order_id','>',0];
+                    $map[] = ['bus_type','<>',0];
+                    $map[] = ['to_from','<>',0];
+                }
+            }
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)
+                ->order('id','desc')->select();
+
+            foreach ($lists as $k=>$v){
+                $lists[$k]['depName'] = Db::name('dep')
+                    ->where('id',$v['dep_id'])
+                    ->value('title');
+//                $lists[$k]['fromName'] =$this->model->from[$v['from']];
+                $lists[$k]['fromName'] = '';
+                if($v['order_id'] > 0 && $v['bus_type'] != 0){
+                    if($v['to_from']){
+                        $lists[$k]['fromName'] = '一键呼叫';
+                    }else{
+                        $lists[$k]['fromName'] = '投诉';
+                    }
+                }
+                $lists[$k]['realName'] = Db::name('user')
+                    ->where('id',$v['create_user_id'])
+                    ->value('real_name');
+//                $lists[$k]['statusTxt'] = $v['status']==1?'已处理':"未处理";
+                $orderMode = 0;
+                if($v['order_id'] > 0){
+                    $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
+                }
+
+                $lists[$k]['statusTxt'] = model('Hiddendanger')->formatStatus($v['status'],$v['order_id'],$v['id']);
+                $lists[$k]['order_mode'] = $orderMode;
+            }
+            include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+            //实例化PHPExcel类
+            $objPHPExcel = new \PHPExcel();
+            //激活当前的sheet表
+            $objPHPExcel->setActiveSheetIndex(0);
+            //设置表格头(即excel表格的第一行)
+            $objPHPExcel->setActiveSheetIndex(0)
+                ->setCellValue('A1', '编号')
+                ->setCellValue('B1', '时间')
+                ->setCellValue('C1', '内容')
+                ->setCellValue('D1', '部门')
+                ->setCellValue('E1', '用户')
+                ->setCellValue('F1', '状态')
+                ->setCellValue('G1', '来源')
+                ->setCellValue('H1', '去向');
+            // 设置表格头水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置列水平居中
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
+                ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+            //设置单元格宽度
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
+            $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
+            //循环刚取出来的数组,将数据逐一添加到excel表格。
+            for ($i = 0; $i < count($lists); $i++) {
+                $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['id']);
+                $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
+                $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
+                $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['depName']);
+                $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['realName']);
+                $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['statusTxt']);
+                if($lists[$i]['from'] > 0){
+                    $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), '隐患');
+                }else{
+                    $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), '');
+                }
+                $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['fromName']);
+
+            }
+            //设置保存的Excel表格名称
+            $filename = $meta_title.'_' . date('YmdHis', time()) . '.xls';
+            //设置当前激活的sheet表格名称
+            $objPHPExcel->getActiveSheet()->setTitle($meta_title);
+            //设置浏览器窗口下载表格
+            ob_end_clean();
+            header("Content-Type: application/force-download");
+            header("Content-Type: application/octet-stream");
+            header("Content-Type: application/download");
+            header('Content-Disposition:inline;filename="' . $filename);
+            //生成excel文件
+            $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+            //下载文件在浏览器窗口
+            return $objWriter->save('php://output');
+        }
+    }
+
+}

+ 664 - 0
application/admin/controller/House.php

@@ -0,0 +1,664 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\model\HousePay;
+use think\App;
+use think\Db;
+use think\Exception;
+
+class House extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\House();
+        $this->table= 'house_view';
+
+    }
+    public function index($import_id=0){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $name = input('name','','trim');
+            if($name){
+                $map[] = ['name','like','%'.$name.'%'];
+            }
+            $xq_title = input('xq_title','','trim');
+            if($xq_title){
+                $map[] = ['xq_title','like','%'.$xq_title.'%'];
+            }
+            $card = input('card','','trim');
+            if($card){
+                $map[] = ['card','like','%'.$card.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $cate = input('cate','','trim');
+            if($cate != ''){
+                $map[] = ['cate','=',$cate];
+            }
+            $c_type = input('c_type','','trim');
+            if($c_type != ''){
+                $map[] = ['c_type','=',$c_type];
+            }
+            if($import_id >0){
+                $map[] = ['import_log_id','=',$import_id];
+            }else{
+                $map[] = ['del','=',0];
+            }
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['cate_name'] =$this->model->cate[$v['cate']];
+                $lists[$k]['is_show_option'] =$import_id>0?false:true;
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            $cType = Db::name('house_c_type')
+                ->where('del',0)
+                ->where('enable',1)
+                ->select();
+            $this->assign('m_name','资源');
+            $this->assign('cType',$cType);
+            $logInfo = [];
+            if($import_id>0){
+                $logInfo = Db::name('import_log')
+                    ->where('id',$import_id)
+                    ->find();
+            }
+            $this->assign('import_id',$import_id);
+            $this->assign('importInfo',$logInfo);
+            return $this->fetch();
+        }
+    }
+
+    public function showfee(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $name = input('name','','trim');
+            if($name){
+                $map[] = ['name','like','%'.$name.'%'];
+            }
+            $xq_title = input('xq_title','','trim');
+            if($xq_title){
+                $map[] = ['xq_title','like','%'.$xq_title.'%'];
+            }
+            $card = input('card','','trim');
+            if($card){
+                $map[] = ['card','like','%'.$card.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $cate = input('cate','','trim');
+            if($cate != ''){
+                $map[] = ['cate','=',$cate];
+            }
+            $c_type = input('c_type','','trim');
+            if($c_type != ''){
+                $map[] = ['c_type','=',$c_type];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['cate_name'] =$this->model->cate[$v['cate']];
+                $start =Db::name('house_pay_log')
+                    ->alias('hpl')
+                    ->join('house_pay hp','hp.id = hpl.pay_id')
+                    ->where('hpl.bus_id',$v['id'])
+                    ->where('hp.status',1)
+                    ->where('hp.del',0)
+                    ->field('hpl.start')
+                    ->order('hpl.start','asc')
+                    ->find();
+                $start = $start?$start['start']:'';
+                $end = Db::name('house_pay_log')
+                    ->alias('hpl')
+                    ->join('house_pay hp','hp.id = hpl.pay_id')
+                    ->where('hpl.bus_id',$v['id'])
+                    ->where('hp.status',1)
+                    ->where('hp.del',0)
+                    ->field('hpl.end')
+                    ->order('hpl.end','asc')
+                    ->find();
+                $end = $end?$end['end']:'';
+                $money = Db::name('house_pay_log')
+                    ->alias('hpl')
+                    ->join('house_pay hp','hp.id = hpl.pay_id')
+                    ->where('hpl.bus_id',$v['id'])
+                    ->where('hp.status',1)
+                    ->where('hp.del',0)
+                    ->sum('hpl.money');
+
+                $lists[$k]['startend'] = '';
+                if($start && $end){
+                    $lists[$k]['startend'] = $start.' ~ '.$end;
+                }
+                $lists[$k]['money'] = 0;
+                if($money){
+                    $lists[$k]['money'] = $money;
+                }
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            $cType = Db::name('house_c_type')
+                ->where('del',0)
+                ->where('enable',1)
+                ->select();
+            $this->assign('m_name','综合收费');
+            $this->assign('cType',$cType);
+            return $this->fetch();
+        }
+    }
+
+    public function fee($id){
+            $refer = isset($_SERVER['http_referer'])?$_SERVER['http_referer']:'';
+            $lists = [];
+            // 获取房产及房产下的储藏室和停车位
+            $house = Db::name('house')->where(['id'=>$id,'enable'=>1,'del'=>0])->find();
+            if(!$house){
+                $this->error('资源不存在',$refer);
+            }
+            if($house['owner_id'] <= 0){
+                $this->error('资源未绑定业主',$refer);
+            }
+            $fees  =  (new \app\common\model\HouseFee())->getTree(cur_org_id());;
+            $fees = $fees?json_decode(json_encode($fees),true):[];
+
+            $lists = $this->model->getlistbyowner($house['owner_id'],$house['area_id']);
+            foreach ($lists as $k=>$v){
+                $arrs = [];
+                foreach ($fees as $kk=>$vv){
+                    if($vv['type'] == $v['type']){
+                        $children = $vv['child']?$vv['child']:[];
+                        foreach ($children as $kkk=>$vvv){
+                            $vvv['parent_title'] = $vv['title'];
+                            $vvv['end'] = $vvv['start'] = '';
+                            $info = Db::name('house_pay_log')
+                                ->alias('pl')
+                                ->join('house_pay p','p.id = pl.pay_id')
+                                ->where('pl.bus_id',$v['id'])
+                                ->where('pl.fee_id',$vvv['id'])
+                                ->order('pl.end','desc')
+                                ->field('pl.*')
+                                ->find();
+                            if($info){
+                                $vvv['end'] = $info['end'];
+                                $vvv['start'] = $info['start'];
+                            }
+                            $minfo =Db::name('house_pay_log')
+                                ->alias('pl')
+                                ->join('house_pay p','p.id = pl.pay_id')
+                                ->where('pl.bus_id',$v['id'])
+                                ->where('pl.fee_id',$vvv['id'])
+                                ->sum('pl.money');
+                            $vvv['tmoney'] = 0;
+                            if($minfo){
+                                $vvv['tmoney'] = $minfo;
+                            }
+                            $arrs[] = $vvv;
+                        }
+                    }
+                }
+                $lists[$k]['fee'] = $arrs;
+            }
+
+            $owner =Db::name('owner')
+                ->where('id',$house['owner_id'])
+                 ->find();
+
+            $this->assign('lists',$lists);
+            $this->assign('houseId',$id);
+            $this->assign('owner',$owner);
+            return $this->fetch();
+    }
+
+    //保存收费记录
+    public function feeSave(){
+        $houseId = input('houseId');
+        $lastDate = input('lastDate');
+        $order = input('order');
+        if(!$houseId){
+            $this->error('参数错误');
+        }
+        if(!$lastDate){
+            $this->error('请选择最晚缴费日期');
+        }
+        if(!$order){
+            $this->error('请选择收费科目');
+        }
+        $order = json_decode($order,true);
+        if(empty($order)){
+            $this->error('请选择收费科目');
+        }
+        foreach ($order as $k=>$v){
+            if($v['total_price'] <= 0){
+                $this->error('收费金额必须大于0');
+            }
+            $fee = Db::name('house_fee')->where('id',$v['fee_id'])->find();
+            if(!$fee||$fee['del']==1||$fee['enable'] == 0){
+                $this->error('收费科目不存在');
+            }
+            if($fee['cycle'] == 1){ // 按周期
+                if(!$v['start']||!$v['end']){
+                    $this->error('未选择收费周期');
+                }
+                $ret = Db::name('house_pay_log')
+                    ->alias('hpl')
+                    ->join('house_pay hp','hp.id = hpl.pay_id')
+                    ->where('hp.del',0)
+                    ->where('hp.status','<>',3)
+                    ->where('hpl.bus_id',$v['id'])
+                    ->where('hpl.fee_id',$v['fee_id'])
+                    ->where('hpl.start','<=',$v['end'])
+                    ->where('hpl.end','>=',$v['start'])
+                    ->field('hpl.*')
+                    ->find();
+                if($ret){
+                    $this->error('请勿重复收费');
+                }
+            }
+        }
+
+        $ret = (new HousePay())->createOrder($houseId,$lastDate,$order,$this->userId,cur_org_id());
+        if(!$ret){
+            $this->error((new HousePay())->getError());
+        }else{
+            $data['info']   =   '操作成功';
+            $data['status'] =   1;
+            $data['id']    =   $ret;
+            $this->success('','',$data);
+        }
+    }
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $info['c_type_list'] = $this->model->getCType($info['c_type']);
+                $this->assign('info',$info);
+            }
+            $area = (new \app\common\model\HouseAreas())->getList();
+            $owner = (new \app\common\model\Owner())->getList();
+            $cate = $this->model->getCate();
+            $this->assign('area',$area);
+            $this->assign('owner',$owner);
+            $this->assign('cate',$cate);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('house')->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('house')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+    public function getType(){
+        $catId = input('id');
+        $list = Db::name('house_c_type')
+        ->where('cate',$catId)
+        ->where('del',0)
+        ->where('enable',1)
+        ->select();
+        $this->success('','',$list);
+    }
+    // excel
+    public function import(){
+
+        return $this->fetch();
+    }
+    /**
+     * 下载报修地点模板
+     */
+    public function downloadtem(){
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+        set_time_limit(0);
+        ini_set("memory_limit","512M");
+        $fileName = '资源模板.xlsx';
+        $excel = new \PHPExcel();
+        $sheet = $excel->setActiveSheetIndex(0);
+        $arr = array('A','B','C','D','E','F','G','H','I','J');
+        foreach($arr as $k=>$v){
+            $excel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(true);//换行
+            $excel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
+            $excel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
+        }
+        $sheet->setCellValueByColumnAndRow(0,1,'小区名称');
+        $sheet->setCellValueByColumnAndRow(1,1,'名称');
+        $sheet->setCellValueByColumnAndRow(2,1,'面积');
+        $sheet->setCellValueByColumnAndRow(3,1,'资源属性(住房/商铺/营业房/储藏室/停车位)');
+        $sheet->setCellValueByColumnAndRow(4,1,'类型');
+        $sheet->setCellValueByColumnAndRow(5,1,'业主姓名');
+        $sheet->setCellValueByColumnAndRow(6,1,'业主电话');
+        $sheet->setCellValueByColumnAndRow(7,1,'业主身份证');
+        $sheet->setCellValueByColumnAndRow(8,1,'业主预存款');
+        $sheet->setCellValueByColumnAndRow(9,1,'业主类型(住户/租户)');
+
+        ob_end_clean();//清除缓冲区,避免乱码
+        header('Content-Type: application/vnd.ms-excel');
+        header('Content-Disposition: attachment;filename="'.$fileName.'"');
+        header('Cache-Control: max-age=0');
+
+        $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
+        $objWriter->save('php://output'); //文件通过浏览器下载
+
+    }
+
+    /**
+     * 导入
+     */
+    public function importexcel(){
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+
+        $userId = $this->userId;
+        $orgId = cur_org_id();
+        set_time_limit(0);
+        ini_set("memory_limit", -1);
+        ob_flush();//清空缓存
+        flush();//刷新缓存
+        $file = request()->file('file');
+
+        if(!$file){
+            exit('请上传文件');
+        }
+        // 移动到框架应用根目录/uploads/ 目录下
+        $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
+            ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
+        if(!$info){
+            exit('上传文件失败');
+
+        }
+        $img = env('root_path').'/public/uploads/files/' . $info->getSaveName();
+        $finfo = $info->getInfo();
+        $fileExt = explode('.',$finfo['name']);
+        $finfo['file_name'] = $finfo['name'];
+        $filepath = str_replace('\\', '/', $img);
+        $file_type = $fileExt[count($fileExt)-1];
+
+        if($file_type == 'xls'){
+            $objReader = \PHPExcel_IOFactory::createReader('Excel5');
+        }else{
+            $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
+        }
+        $imData = [
+            'org_id'=>$orgId,
+            'title'=>$finfo['file_name'],
+            'type'=>1,
+            'create_time'=>getTime(),
+        ];
+        $importId =Db::name('import_log')->insertGetId($imData);
+        $objPHPExcel = $objReader->load($filepath,$encode='utf-8');
+        $table = array(0,1,2,3,4,5,6,7,8,9);
+        $allobjWorksheets = $objPHPExcel->getAllSheets();
+
+        try{
+            @unlink($filepath);
+            foreach($allobjWorksheets as $key=>$objWorksheet){
+                $highestRow = $objWorksheet->getHighestRow();
+                $success = 0;
+                $error = 0;
+                $errorMsg = [];
+                for ($row = 2; $row <= $highestRow; ++$row) {
+                    $oneData = array();
+                    for ($col = 0; $col < count($table); ++$col) {
+                        $cell = $objWorksheet->getCellByColumnAndRow($col, $row);
+                        $value = (string)$cell->getValue();
+                        $oneData[$table[$col]]= $value;
+                    }
+
+                    if(!$oneData[0]||!$oneData[1]||!$oneData[3]){
+                        $msg = "第".$row."行,数据存在空值,未导入";
+                        echo "<font color=\"red\">".$msg."</font><br />";
+                        $error++;
+                        $errorMsg[] = $msg;
+                        continue;
+                    }
+                    if(!in_array($oneData[3],$this->model->cate)){
+                        $msg = "第".$row."行,资源属性错误,未导入";
+                        echo "<font color=\"red\">".$msg."</font><br />";
+                        $error++;
+                        $errorMsg[] = $msg;
+                        continue;
+                    }
+
+                    $c = array_reverse($this->model->cate1);
+                    if(in_array($c[$oneData[3]],[1,2,3,4])){
+                        if(!is_numeric($oneData[2]) ||  !$oneData[2]){
+                            $msg = "第".$row."行,面积字段数据格式错误(只能为纯数字),未导入";
+                            echo "<font color=\"red\">".$msg."</font><br />";
+                            $error++;
+                            $errorMsg[] = $msg;
+                            continue;
+                        }
+                    }else{
+                        $oneData[2] = '0.00';
+                    }
+
+                    if(in_array($c[$oneData[3]],[1,2,3])){
+                        $type = 1;
+                    }elseif ($c[$oneData[3]]==4){
+                        $type = 2;
+                    }elseif ($c[$oneData[3]]==5){
+                        $type = 3;
+                    }
+                    $pid = $this->getPH($oneData[0]);
+                    $ret = Db::name('house')
+                        ->where('org_id',$orgId)
+                        ->where('title',$oneData[1])
+                        ->where('area_id',$pid)
+                        ->where('del',0)
+                        ->find();
+                    if($ret){
+                        $msg = "第".$row."行,数据已存在,未导入";
+                        echo "<font color=\"red\">".$msg."</font><br />";
+                        $error++;
+                        $errorMsg[] = $msg;
+                        continue;
+                    }
+
+                    if(!$oneData[5] || !$oneData[6] ||!$oneData[7]){
+                        $owId = 0;
+                    }else{
+                        $oType = 1;
+                        if($oneData[9]){
+                            if(in_array($oneData[9],['住户','租户'])){
+                                $oType = $oneData[9]=='住户'?1:2;
+
+                            }
+                        }
+                        $oMoney  = '0.00';
+                        if($oneData[8]){
+                            if(is_numeric($oneData[8])){
+                                $oMoney  = $oneData[8];
+                            }
+                        }
+                        $owner = Db::name('owner')
+                            ->where('card',$oneData[7])
+                            ->where('del',0)
+                            ->where('org_id',$orgId)
+                            ->find();
+                        if ($owner){
+                            $owId = $owner['id'];
+                        }else{
+                            $oData = [
+                                'org_id'=>$orgId,
+                                'name'=>$oneData[5],
+                                'phone'=>$oneData[6],
+                                'card'=>$oneData[7],
+                                'money'=>$oMoney,
+                                'type'=>$oType,
+                                'import_log_id'=>$importId,
+                                'create_time'=>getTime(),
+                            ];
+                            $owId = Db::name('owner')->insertGetId($oData);
+                            if(!$owId){
+                                $msg = "第".$row."行,导入业主失败";
+                                echo "<font color=\"red\">".$msg."</font><br />";
+                                $error++;
+                                $errorMsg[] = $msg;
+                                continue;
+                            }
+
+                        }
+
+
+                    }
+                    $iii = 0;
+                    if($oneData[4]){
+                        $tId = Db::name('house_c_type')
+                            ->where('name',$oneData[4])
+                            ->where('org_id',$orgId)
+                            ->where('cate',$c[$oneData[3]])
+                            ->find();
+                        if($tId){
+                            $iii = $tId['id'];
+                        }
+                    }
+                    $data = [
+                        'org_id'=>$orgId,
+                        'area_id'=>$pid,
+                        'owner_id'=>$owId,
+                        'type'=>$type,
+                        'cate'=>$c[$oneData[3]],
+                        'title'=>$oneData[1],
+                        'area'=>$oneData[2],
+                        'c_type'=>$iii,
+                        'create_time'=>getTime(),
+                        'enable'=>1,
+                        'import_log_id'=>$importId,
+                    ];
+                    $Id = Db::name('house')->insertGetId($data);
+                    if($owId>0){
+                        $this->model->addLog($Id);
+                    }
+                    if(!$Id){
+                        $msg = "第".$row."行,导入失败";
+                        echo "<font color=\"red\">".$msg."</font><br />";
+                        $error++;
+                        $errorMsg[] = $msg;
+                        continue;
+                    }
+                    $success++;
+                }
+                Db::name('import_log')->where('id',$importId)
+                    ->update(
+                        [
+                            'success'=>$success,
+                            'error'=>$error,
+                            'error_msg'=>json_encode($errorMsg),
+                        ]
+                    );
+            }
+            echo "<font color=\"green\">导入完成</font><br />";
+        }catch (Exception $e){
+            echo $e->getMessage();
+            echo "<font color=\"red\">数据异常,已停止导入</font><br />";
+        }
+    }
+    public function getPH($name){
+        $orgId = cur_org_id();
+        $res = Db::name('house_areas')
+            ->where('org_id',$orgId)
+            ->where('title',$name)
+            ->where('pid',0)
+            ->where('type',1)
+            ->find();
+
+        if(empty($res)){
+            $data  = [
+                'org_id'=>$orgId,
+                'title'=>$name,
+                'type'=>1,
+            ];
+            $id = Db::name('house_areas')->insertGetId($data);
+        }else{
+            $id = $res['id'];
+        }
+        return $id;
+    }
+}

+ 111 - 0
application/admin/controller/HouseAreas.php

@@ -0,0 +1,111 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+
+class HouseAreas extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\HouseAreas();
+        $this->table= $this->model->table;
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name','小区');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $info['latlng'] = !empty($info['lat'])?$info['lat'].'-'.$info['lng']:'';
+                $this->assign('info',$info);
+            }
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+}

+ 114 - 0
application/admin/controller/HouseCType.php

@@ -0,0 +1,114 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+
+class HouseCType extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\HouseCType();
+        $this->table= $this->model->table;
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['cate_name'] = (new \app\common\model\House())->cate[$v['cate']];
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name','类型');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            $cate = (new \app\common\model\House())->getCate();
+            $this->assign('cate',$cate);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+}

+ 109 - 0
application/admin/controller/HouseFee.php

@@ -0,0 +1,109 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class HouseFee extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model= new \app\common\model\HouseFee();
+        $this->table=$this->model->table;
+
+    }
+    /**
+     * 科室管理页
+     */
+    public function index(){
+
+        $list =  $this->model->getTree(cur_org_id());
+        $this->assign('tree',$list);
+        return $this->fetch();
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0,$pid=0){
+        if(request()->isPost()){
+            $res = $this->model->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            if($id){
+                $info =db($this->table)->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            $this->assign('type',[
+                [
+                   'id'=>1,
+                   'title'=>'房屋'
+                ],
+                [
+                    'id'=>2,
+                    'title'=>'储藏室'
+                ],[
+                    'id'=>3,
+                    'title'=>'停车位'
+                ]
+            ]);
+            $pInfo = [];
+            if($pid >0){
+                $pInfo = Db::name('house_fee')
+                    ->where('id',$pid)
+                    ->find();
+            }
+            $this->assign('pid',$pid);
+            $this->assign('pInfo',$pInfo);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $info = db($this->table)->where('id',$id)->where('del',0)->find();
+        if(!$info)  $this->error('科目不存在');
+        if($info['parent_id']==0){
+            $child  =  db($this->table)->where('parent_id',$id)
+                     ->where('del',0)->find();
+            if($child) $this->error('请先删除子科目');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+
+}

+ 220 - 0
application/admin/controller/HouseLock.php

@@ -0,0 +1,220 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+
+class HouseLock extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='house_lock';
+        $this->model= new \app\common\model\HouseLock();
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+
+            $status = input('status','','trim');
+            if($status != ''){
+                $map[] = ['status','=',$status];
+            }
+
+            $b = input('start','','trim');
+            $e = input('end','','trim');
+            if($b){
+                $b = date('Y-m-d 00:00:00',strtotime($b));
+                $map[] = ['create_time','>=',$b];
+            }
+            if($e){
+                $e = date('Y-m-d 23:59:59',strtotime($e));
+                $map[] = ['create_time','<=',$e];
+            }
+
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['user_id','=',$this->userId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
+                $lists[$k]['deal_real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
+                $lists[$k]['cur_user_id'] = $this->userId;
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            return $this->fetch();
+        }
+    }
+
+    public function add()
+    {
+        $start = input('start');
+        $end =  input('end');
+        if(!$start){
+            // 获取开始时间,为空的没有数据
+            $start = $this->model->getStartTime($this->userId);
+            $end = date('Y-m-d H:i:s');
+        }
+
+        $data = $this->model->getDataInfo($start,$end,$this->userId,$this->orgId);
+        $error = '';
+        if(!$data){
+            $error = $this->model->getError();
+        }
+        $this->assign('data',$data);
+        $this->assign('error',$error);
+        $this->assign('start',$start);
+        $this->assign('end',$end);
+        return $this->fetch();
+    }
+    public function addSave(){
+        $start = input('start');
+        $end = input('end');
+        $remark = input('remark');
+        $userId = $this->userId;
+        $orgId = $this->orgId;
+
+        $ret = $this->model->addSave($start,$end,$remark,$userId,$orgId);
+        if(!$ret){
+            $error = $this->model->getError();
+            $this->error($error);
+        }else{
+            $this->success('操作成功');
+        }
+    }
+    public function cancel($id){
+        $ret = $this->model->deal($id,3,$this->userId);
+        if(!$ret){
+            $this->error($this->model->getError());
+        }else{
+            $this->success('操作是吧');
+        }
+    }
+    public function detail($id)
+    {
+        $data = $this->model->getDataById($id);
+        if(!$data){
+            $this->error('记录不存在',url('HouseLock/index'));
+        }
+        $this->assign('data',$data);
+        return $this->fetch();
+    }
+    public function edit($id)
+    {
+        $data = $this->model->getDataById($id);
+        if(!$data){
+            $this->error('记录不存在',url('HouseLock/index'));
+        }
+        $this->assign('data',$data);
+        return $this->fetch();
+    }
+
+    public function apply(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+
+            $status = input('status','','trim');
+            if($status != ''){
+                $map[] = ['status','=',$status];
+            }
+
+            $b = input('start','','trim');
+            $e = input('end','','trim');
+            if($b){
+                $b = date('Y-m-d 00:00:00',strtotime($b));
+                $map[] = ['create_time','>=',$b];
+            }
+            if($e){
+                $e = date('Y-m-d 23:59:59',strtotime($e));
+                $map[] = ['create_time','<=',$e];
+            }
+
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
+                $lists[$k]['deal_real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+
+            return $this->fetch();
+        }
+    }
+
+    public function detail2($id)
+    {
+        $data = $this->model->getDataById($id);
+        if(!$data){
+            $this->error('记录不存在',url('HouseLock/apply'));
+        }
+        $this->assign('data',$data);
+        return $this->fetch();
+    }
+
+    public function agree($id){
+        $ret = $this->model->deal($id,1,$this->userId);
+        if(!$ret){
+            $this->error($this->model->getError());
+        }else{
+            $this->success('操作成功');
+        }
+    }
+
+    public function disagree($id){
+        $ret = $this->model->deal($id,2,$this->userId);
+        if(!$ret){
+            $this->error($this->model->getError());
+        }else{
+            $this->success('操作成功');
+        }
+    }
+    public function detail2print($id){
+        $data = $this->model->getDataById($id);
+        if(!$data){
+            $this->error('记录不存在',url('HouseLock/apply'));
+        }
+
+        $data['count_logs'] = count($data['logs']);
+        $this->assign('data',$data);
+        return $this->fetch();
+    }
+
+}

+ 59 - 0
application/admin/controller/HouseOwnerLog.php

@@ -0,0 +1,59 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+
+class HouseOwnerLog extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table= 'house_owner_log_view';
+
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $name = input('name','','trim');
+            if($name){
+                $map[] = ['name','like','%'.$name.'%'];
+            }
+            $title = input('content','','trim');
+            if($title){
+                $map[] = ['content','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('m_name','业主变更记录');
+            return $this->fetch();
+        }
+    }
+
+
+
+}

File diff suppressed because it is too large
+ 1111 - 0
application/admin/controller/HousePay.php


+ 164 - 0
application/admin/controller/ImportLog.php

@@ -0,0 +1,164 @@
+<?php
+namespace app\admin\controller;
+
+use think\App;
+use think\Db;
+use think\Exception;
+
+class ImportLog extends Auth
+{
+
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->table='import_log';
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['title','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+                if(strtotime($v['create_time'])+86400 < time()){
+                    $lists[$k]['is_ch'] = false;
+                }else{
+                    $lists[$k]['is_ch'] = true;
+
+                }
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField('del',1);
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db($this->table)->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function errorInfo($id){
+        $info =Db::name('import_log')
+            ->where('id',$id)
+            ->find();
+        $msg = json_decode($info['error_msg'],true);
+        if(empty($msg)) exit('没有找到错误信息');
+        $info['msg'] = $msg;
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+    public function withdraw($id){
+        $info = Db::name('import_log')
+            ->where('id',$id)
+            ->find();
+        if($info['status']!==0){
+            $this->error('该记录已被撤回');
+        }
+        if(strtotime($info['create_time'])+86400 < time()){
+            $this->error('超过一天不能撤回');
+        }
+        if($info['type']==1){
+            $table = 'house';
+        }elseif ($info['type']==2){
+            $table = 'owner';
+        }elseif ($info['type']==3){
+            $table = 'car';
+        }
+        if($info['success']==0){
+            $res = Db::name('import_log')
+                ->where('id',$id)
+                ->update(
+                    [
+                        'status'=>1,
+                        'withdraw_time'=>getTime(),
+                    ]);
+            $res?$this->success('撤回成功'):$this->error('撤回失败');
+
+        }
+        Db::startTrans();
+        try{
+            $res  =Db::name($table)
+                ->where('import_log_id',$id)
+                ->update(['del'=>1,'update_time'=>getTime()]);
+            if(!$res)   exception('更新'.$table.'失败');
+            if($info['type']==1){
+                $res  = Db::name('owner')
+                    ->where('import_log_id',$id)
+                    ->update('owner',['del'=>1,'update_time'=>getTime()]);
+                if(!$res)  exception('撤回业主失败');
+            }
+            $res  = Db::name('import_log')
+                ->where('id',$id)
+                ->update(
+                    [
+                        'status'=>1,
+                        'withdraw_time'=>getTime(),
+                    ]);
+            if(!$res)  exception('撤回失败');
+            Db::commit();
+            $this->success('撤回成功');
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error($e->getmessage());
+        }
+    }
+
+
+}

File diff suppressed because it is too large
+ 1195 - 0
application/admin/controller/Index.php


+ 63 - 0
application/admin/controller/Jiu.php

@@ -0,0 +1,63 @@
+<?php
+namespace app\admin\controller;
+use app\watch\controller\Api;
+use think\App;
+use think\facade\Db;
+
+class Jiu extends Auth
+{
+    public function __construct(App $app) {
+        parent::__construct($app);
+        $this->api = new Api($this->app);
+    }
+    public function index(){
+
+        $id = request()->get('id');
+        if(empty($id)){
+            $d = $this->api->community(1,10);
+            if(!isset($d['objs'][0])) $this->error('没有添加设备');
+            $id = $d['objs'][0]['_id'];
+
+        }
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $date = input('riqi','');
+            $imei = input('imei','');
+            $p = ['rows_per_page'=>$length,'page'=>$page];
+
+            if($date){
+               $p['time_begin'] = date('Ymd',strtotime($date));
+            }
+            if(!empty($imei)){
+                $id = $imei;
+            }
+            $list = $this->api->deviceSosData($id,$p);
+            if(!$list['success']){
+                $this->error($list['error_desc']);
+            }
+            $data = [];
+            foreach ($list['objs'] as $k=>$v){
+                $a = [
+                    'id'=>$k+1,
+                    'address'=>$v['address'],
+                    'created_at'=>nDate($v['created_at']['$date']),
+                ];
+                $data[$k] = $a;
+            }
+            $result['page'] = $page;
+            $result['total'] = $list['page']['page_count'];
+            $result['records'] = $list['page']['total'];
+            $result['rows'] = $data;
+            return json($result);
+        }else{
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+
+
+
+
+}

+ 165 - 0
application/admin/controller/Location.php

@@ -0,0 +1,165 @@
+<?php
+namespace app\admin\controller;
+use app\watch\controller\Api;
+use think\App;
+use think\Db;
+
+class Location extends Auth
+{
+    protected $lx = 'http://manager.aiqiangua.com:8080/organS2/themes/default/images/loc2.png';
+    protected $zx = 'http://manager.aiqiangua.com:8080/organS2/themes/default/images/loc.png';
+    public function __construct(App $app) {
+        parent::__construct($app);
+        $this->api = new Api($this->app);
+    }
+    public function index(){
+        if(request()->post()){
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+
+            $map[] =['del','=',0];
+            $map[] =['org_id','=',cur_org_id()];
+            $map= empty($map) ? true: $map;
+            $lists = Db::name('bracelet_device')
+                ->where($map)->limit($start,$length)
+                ->select();
+
+            $deviceInfo = [];
+            foreach ($lists as $k=>$v){
+                $a = $this->api->getDevice($v['imei']);
+                if(!$a['success']) $this->error($v['imei'].$a['error_desc']);
+                $deviceInfo[] = $a['obj'];
+
+            }
+            $totalCount =  Db::name('bracelet_device')
+                ->where($map)
+                ->count();
+            $totalPage = ceil($totalCount/$length);
+            $data = [];
+            $ydw  = [];
+            $wdw  = [];
+            $onlineNumber = 0;
+            foreach ($deviceInfo as $k=>$v){
+                 if(!empty($v['last_address'])){
+                     $a = [
+                         'lonLat'=>[$v['last_location']['coordinates'][0],$v['last_location']['coordinates'][1]],
+                         'imeI'=>$v['_id'],
+                         'name'=>$v['name'],
+                         'lon'=>$v['last_location']['coordinates'][0],
+                         'lat'=>$v['last_location']['coordinates'][1],
+                         'address'=>$v['last_address'],
+                         'updated_at'=>nDate($v['location_updated_at']['$date']),
+                         'icon'=>$v['online']?$this->zx:$this->lx
+                     ];
+                     $ydw[] = [
+                         'imeI'=>$v['_id'],
+                         'name'=>$v['name'],
+                         'online'=>$v['online']?'在线':'离线',
+                     ];
+                     if($v['online']){
+                         $onlineNumber++;
+                     }
+                 }else{
+                     $wdw[] = [
+                         'imeI'=>$v['_id'],
+                         'name'=>$v['name'],
+                     ];
+                 }
+
+
+            }
+            $data['data'][] = $a;
+            $data['online_numbers'] =$onlineNumber;
+
+            $lpage['page_count'] = $totalPage;
+            $lpage['total'] = $totalCount;
+            $lastPage = $page+1;
+            $proPage = $page-1;
+            $a1  = '<a href="javascript:;" style="color:black;">&nbsp;&nbsp;当前第'.$page.'页&nbsp;&nbsp;</a>';
+            $a3  = '<a href="javascript:;" style="color:black;">&nbsp;&nbsp;共'.$lpage['total'].'条</a>';
+            if($page==1 && $lpage['page_count'] <=1){
+                $a0 = '<a style="color:black;" href="javascript:;">上一页&nbsp;&nbsp;|</a>';
+                $a2 = '<a style="color:black;" href="javascript:;">|&nbsp;&nbsp;下一页&nbsp;&nbsp;|</a>';
+            }else if ($page==1 && $lpage['page_count'] >1){
+                $a0 = '<a style="color:black;" href="javascript:;">上一页&nbsp;&nbsp;|</a>';
+                $a2 = '<a style="color:black;" onclick="setPage('.$lastPage.')" href="javascript:;">|&nbsp;&nbsp;下一页&nbsp;&nbsp;|</a>';
+
+            }else if ($page > 1 && $lpage['page_count'] <=1){
+                $a0 = '<a style="color:black;" onclick="setPage('.$proPage.')" href="javascript:;">上一页&nbsp;&nbsp;|</a>';
+                $a2 = '<a style="color:black;" href="javascript:;">|&nbsp;&nbsp;下一页&nbsp;&nbsp;|</a>';
+
+            }else if ($page > 1 && $lpage['page_count'] >1){
+                $a0 = '<a style="color:black;" onclick="setPage('.$proPage.')" href="javascript:;">上一页&nbsp;&nbsp;|</a>';
+                $a2 = '<a style="color:black;" onclick="setPage('.$lastPage.')" href="javascript:;">|&nbsp;&nbsp;下一页&nbsp;&nbsp;|</a>';
+
+            }
+
+            $data['page'] = $a0.$a1.$a2.$a3;
+            $ydwTxt  ='';
+            $wdwTxt  ='';
+
+            if(!empty($ydw)){
+                foreach ($ydw as $v){
+                    $ydwTxt.='<li>'.$v['imeI'].'['.$v['name'].']['.$v['online'].']</li>';
+                }
+            }
+            if(!empty($wdw)){
+                foreach ($wdw as $v){
+                    $wdwTxt.='<li>'.$v['imeI'].'['.$v['name'].']</li>';
+                }
+            }
+            $data['ydw'] = $ydwTxt;
+            $data['wdw'] = $wdwTxt;
+            $this->success('获取成功','',$data);
+
+        }else{
+            $this->assign('gdKey',config('app.gdmap'));
+            return $this->fetch();
+
+        }
+    }
+    public function getSosNum(){
+        $count  = Db::name('sos_data')
+            ->where('org_id',cur_org_id())
+            ->count();
+        $this->success('操作成功','',$count);
+    }
+
+
+    public function getSosList(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = 1;      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+
+            $map[] = ['org_id','=',cur_org_id()];
+
+            $list = Db::name('sos_data')->where($map)
+                ->limit($start,$length)->order('id','desc')
+                ->select();
+
+            foreach ($list as $k=>&$v){
+                $v['created_at'] = $v['time_begin'];
+
+            }
+            $totalCount = Db::name('sos_data')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $list;
+            Db::name('sos_data')
+                ->whereIn('id',array_column($list,'id'))
+                ->delete();
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+
+
+
+}

+ 93 - 0
application/admin/controller/MateApply.php

@@ -0,0 +1,93 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\model\MateGoodsLog;
+use think\App;
+use think\Db;
+use think\Exception;
+
+class MateApply extends Auth
+{
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model = new \app\common\model\MateApply();
+        $this->table = 'mate_apply';
+    }
+    /**
+     * 项目仓库出库记录
+     *
+     * @author wst
+     * @date   2021/9/10 8:37
+     */
+    public function back(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $title = input('title','','trim');
+            if($title){
+                $map[] = ['sn','like','%'.$title.'%'];
+            }
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['enable','=',$enable];
+            }
+            $map[] = ['org_id','=',$this->orgId];
+            $map[] = ['type','=',2];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists =db($this->table)
+                ->where($map)->limit($start,$length)
+                ->order($order)->select();
+            foreach ($lists as $k=>$v){
+                $lists[$k]['userName'] = db('user')
+                    ->where('id',$v['user_id'])
+                    ->value('real_name');
+            }
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','出库记录');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增出库
+     */
+    public function add(){
+        if(request()->isPost()){
+            $res = $this->model->updates($this->userId);
+            if($res){
+                $this->success('操作成功',url('back'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            $meta_title = '新增出库';
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    //出库详情
+    public function detail($id){
+        $info = (new \app\common\model\MateApply())->getInfo($id);
+        if(!$info) $this->error('记录不存在');
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+}

+ 82 - 0
application/admin/controller/MateCate.php

@@ -0,0 +1,82 @@
+<?php
+
+namespace app\admin\controller;
+use think\Db;
+
+class MateCate extends Auth {
+    public function index() {
+        if (request()->isAjax()) {
+            //分页参数
+            $length = input('rows', 10, 'intval');   //每页条数
+            $page = input('page', 1, 'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx', 'id', 'trim');      //排序列
+            $sort = input('sord', 'asc', 'trim');        //排序方式
+            $order = $sortRow . ' ' . $sort;
+            $title = input('title', '', 'trim');
+            if ($title) {
+                $map[] = ['title', 'like', '%' . $title . '%'];
+            }
+            $map[] = ['org_id', '=', $this->orgId];
+            $map = empty($map) ? true : $map;
+            //数据查询
+            $lists = Db::name('mate_cate')
+                ->where($map)->limit($start, $length)
+                ->order($order)->select();
+            //数据返回
+            $totalCount = Db::name('mate_cate')->where($map)->count();
+            $totalPage = ceil($totalCount / $length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }
+        else {
+            $this->assign('meta_title', '物品分类列表');
+            return $this->fetch();
+        }
+    }
+    /**
+     * 新增/编辑
+     */
+    public function add($id = 0) {
+        if (request()->isPost()) {
+            $model = new \app\common\model\MateCate();
+            $res = $model->updates();
+            if ($res) {
+                $this->success('操作成功', url('index'));
+            }
+            else {
+                $this->error($model->getError());
+            }
+        }
+        else {
+            $meta_title = '新增物品分类';
+            if ($id) {
+                $info = Db::name('mate_cate')->where('id', $id)->find();
+                $this->assign('info', $info);
+                $meta_title = '编辑物品分类';
+            }
+            $this->assign('meta_title', $meta_title);
+            return $this->fetch();
+        }
+    }
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id = 0) {
+        if (!$id) {
+            $this->error('参数错误');
+        }
+        $res = Db::name('mate_cate')->where('id',$id)->setField('del',1);
+        if ($res) {
+            $this->success('删除成功');
+        }
+        else {
+            $this->error('删除失败');
+        }
+    }
+}

+ 151 - 0
application/admin/controller/MateCheck.php

@@ -0,0 +1,151 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\model\MateGoodsLog;
+use think\App;
+use think\Db;
+use think\Exception;
+
+class MateCheck extends Auth
+{
+    public function __construct(App $app = null) {
+        parent::__construct($app);
+        $this->model = new \app\common\model\MateCheck();
+        $this->table = $this->model->table;
+    }
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $enable = input('enable','','trim');
+            if($enable != ''){
+                $map[] = ['status','=',$enable];
+            }
+            $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists =db($this->table)
+                ->where($map)->limit($start,$length)
+                ->order($order)->select();
+            $lists = $lists?$lists:[];
+            foreach ($lists as $k=>$v){
+                $lists[$k]['userName'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
+            }
+
+            //数据返回
+            $totalCount = db($this->table)->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            $this->assign('meta_title','盘库列表');
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add(){
+        if(request()->isPost()){
+            $res = $this->model->updates($this->userId);
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            $meta_title = '新增盘库';
+            $this->assign('meta_title',$meta_title);
+            return $this->fetch();
+        }
+    }
+
+    //详情
+    public function info($id){
+        $info = $this->model->getInfo($id);
+        if(!$info) $this->error('记录不存在');
+        $this->assign('info',$info);
+        return $this->fetch();
+    }
+
+    public function check($id=0){
+        if(request()->isPost()){
+            $res = $this->model->checkGoods($this->userId);
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error($this->model->getError());
+            }
+        }else{
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }
+
+    public function delGoods($id=0){
+        $info = Db::name('mate_check_goods')->where('id',$id)->where('del',0)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+        $ret = Db::name('mate_check_goods')->where('id',$id)->update(['user_id'=>$this->userId,'del'=>1]);
+        if($ret){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+    public function del($id=0){
+        $info = Db::name('mate_check')->where('id',$id)->where('del',0)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+        Db::startTrans();
+        try{
+            $ret = Db::name('mate_check')->where('id',$id)->update(['del_user'=>$this->userId,'del'=>1,'del_time'=>date('Y-m-d H:i:s')]);
+            if(!$ret){
+                \exception('操作成功');
+            }
+
+            Db::name('mate_check_goods')->where('check_id',$id)->update(['user_id'=>$this->userId,'del'=>1]);
+
+            Db::commit();
+        }catch (Exception $e){
+            Db::rollback();
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+    public function finish($id=0){
+        $info = Db::name('mate_check')->where('id',$id)->where('del',0)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+        if($info['status'] != 0){
+            $this->error('盘库已完成');
+        }
+        $ginfo = Db::name('mate_check_goods')->where('check_id',$id)->where('status',0)->where('del',0)->find();
+        if($ginfo){
+            $this->error('还有物品未盘库');
+        }
+        $ret = Db::name('mate_check')->where('id',$id)->update(['status'=>1,'finish_time'=>date('Y-m-d H:i:s')]);
+        if(!$ret){
+            $this->error('操作失败');
+        }
+        $this->success('操作成功');
+    }
+
+}

+ 0 - 0
application/admin/controller/MateGoodsLog.php


Some files were not shown because too many files changed in this diff