ApproveMaintainUser.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. if($data) {
  73. foreach ($data as &$value) {
  74. $comment_count = !empty($value['log']) ? count($value['log']) : 0;
  75. $comment_score = 0;
  76. if (!empty($value['log'])) {
  77. foreach ($value['log'] as $k => $v) {
  78. $comment_score = bcadd($comment_score, $v['comment_score']);
  79. }
  80. }
  81. $log_score = $comment_score > 0 ? bcdiv($comment_score, $comment_count, 1) : 0;
  82. $value['comment_count'] = $comment_count;
  83. $value['comment_score'] = $comment_score;
  84. $value['log_score'] = $log_score;
  85. }
  86. }
  87. }
  88. /**
  89. * 添加
  90. * @auth true
  91. * @throws \think\Exception
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. * @throws \think\exception\DbException
  95. * @throws \think\exception\PDOException
  96. */
  97. public function add()
  98. {
  99. $this->title = '添加';
  100. $this->_form($this->table, 'form');
  101. }
  102. /**
  103. * 编辑
  104. * @auth true
  105. * @throws \think\Exception
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. * @throws \think\exception\DbException
  109. * @throws \think\exception\PDOException
  110. */
  111. public function edit()
  112. {
  113. $this->title = '编辑';
  114. $this->_form($this->table, 'form');
  115. }
  116. /**
  117. * 表单处理
  118. * @param array $data
  119. * @throws \think\db\exception\DataNotFoundException
  120. * @throws \think\db\exception\ModelNotFoundException
  121. * @throws \think\exception\DbException
  122. */
  123. protected function _form_filter(&$data)
  124. {
  125. if ($this->request->isGet()) {
  126. }
  127. if ($this->request->isPost()) {
  128. }
  129. }
  130. /**
  131. * 删除
  132. * @auth true
  133. * @throws \think\Exception
  134. * @throws \think\exception\PDOException
  135. */
  136. public function remove()
  137. {
  138. $this->applyCsrfToken();
  139. $this->_delete($this->table);
  140. }
  141. }