ApproveMaintainUser.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\approve\controller;
  15. use app\common\constant\CommonConstant;
  16. use app\common\constant\MaintainConstant;
  17. use app\common\model\ApproveMaintainUser as model;
  18. use library\Controller;
  19. /**
  20. * 维修人员
  21. */
  22. class ApproveMaintainUser extends Controller
  23. {
  24. /**
  25. * 绑定数据表
  26. * @var string
  27. */
  28. protected $table = 'ApproveMaintainUser';
  29. /**
  30. * 控制器初始化
  31. */
  32. protected function initialize()
  33. {
  34. $this->get_type_title_list = MaintainConstant::get_type_title_list();
  35. }
  36. /**
  37. * 列表
  38. * @auth true
  39. * @menu true
  40. * @throws \think\Exception
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @throws \think\exception\DbException
  44. */
  45. public function index()
  46. {
  47. $name = input('name');
  48. $mobile = input('mobile');
  49. $this->title = '维修人员列表';
  50. $data = model::field('is_deleted', true)
  51. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  52. ->when($name, function ($query) use ($name) {
  53. $query->where('name', 'like', '%' . $name . '%');
  54. })
  55. ->when($mobile, function ($query) use ($mobile) {
  56. $query->where('mobile', 'like', '%' . $mobile . '%');
  57. })
  58. ->with([
  59. 'log' => function ($query) {
  60. $query->field('comment,create_at', true);
  61. }
  62. ]);
  63. self::_init($data);
  64. }
  65. /**
  66. * 列表数据处理
  67. * @param array $data
  68. * @throws \Exception
  69. */
  70. protected function _index_page_filter(&$data)
  71. {
  72. foreach ($data as &$value) {
  73. $comment_count = !empty($value['log']) ? count($value['log']) : 0;
  74. $comment_score = 0;
  75. if (!empty($value['log'])) {
  76. foreach ($value['log'] as $k => $v) {
  77. $comment_score = bcadd($comment_score, $v['comment_score']);
  78. }
  79. }
  80. $log_score = $comment_score > 0 ? bcdiv($comment_score, $comment_count, 1) : 0;
  81. $value['comment_count'] = $comment_count;
  82. $value['comment_score'] = $comment_score;
  83. $value['log_score'] = $log_score;
  84. }
  85. }
  86. /**
  87. * 添加
  88. * @auth true
  89. * @throws \think\Exception
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. * @throws \think\exception\DbException
  93. * @throws \think\exception\PDOException
  94. */
  95. public function add()
  96. {
  97. $this->title = '添加';
  98. $this->_form($this->table, 'form');
  99. }
  100. /**
  101. * 编辑
  102. * @auth true
  103. * @throws \think\Exception
  104. * @throws \think\db\exception\DataNotFoundException
  105. * @throws \think\db\exception\ModelNotFoundException
  106. * @throws \think\exception\DbException
  107. * @throws \think\exception\PDOException
  108. */
  109. public function edit()
  110. {
  111. $this->title = '编辑';
  112. $this->_form($this->table, 'form');
  113. }
  114. /**
  115. * 表单处理
  116. * @param array $data
  117. * @throws \think\db\exception\DataNotFoundException
  118. * @throws \think\db\exception\ModelNotFoundException
  119. * @throws \think\exception\DbException
  120. */
  121. protected function _form_filter(&$data)
  122. {
  123. if ($this->request->isGet()) {
  124. }
  125. if ($this->request->isPost()) {
  126. }
  127. }
  128. /**
  129. * 删除
  130. * @auth true
  131. * @throws \think\Exception
  132. * @throws \think\exception\PDOException
  133. */
  134. public function remove()
  135. {
  136. $this->applyCsrfToken();
  137. $this->_delete($this->table);
  138. }
  139. }