WorkerServiceWorkLists.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\works;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\master_worker\MasterWorker;
  17. use app\common\model\works\ServiceWork;
  18. use app\common\lists\ListsSearchInterface;
  19. use think\db\Query;
  20. /**
  21. * 工程师服务工单列表
  22. * Class WorkerServiceWorkLists
  23. * @package app\adminapi\listsworks
  24. */
  25. class WorkerServiceWorkLists extends BaseAdminDataLists implements ListsSearchInterface
  26. {
  27. /**
  28. * @notes 设置搜索条件
  29. * @return \string[][]
  30. * @author likeadmin
  31. * @date 2024/07/10 15:06
  32. */
  33. public function setSearch(): array
  34. {
  35. return [
  36. '=' => ['id','category_type', 'work_status', 'service_status', 'master_worker_id', 'work_type','city'],
  37. ];
  38. }
  39. public function queryWhere(){
  40. $where = [];
  41. if (isset($this->params['master_worker_name']) && !empty($this->params['master_worker_name'])) {
  42. $master_worker_ids = MasterWorker::where([['worker_number|mobile|real_name', 'like','%' .$this->params['master_worker_name'] . '%']])->column('id')??[0];
  43. $where[] = ['master_worker_id','in' ,$master_worker_ids];
  44. }
  45. if(isset($this->params['workid']) && !empty($this->params['workid'])){
  46. $where[] = ['master_worker_id', '=', $this->params['workid']];
  47. }
  48. return $where;
  49. }
  50. public function queryAndWhere(){
  51. $where = [];
  52. if (isset($this->params['work_sn']) && !empty($this->params['work_sn'])) {
  53. $where[] = ['work_sn','=' ,$this->params['work_sn']];
  54. }
  55. if(isset($this->params['mobile']) && !empty($this->params['mobile'])){
  56. $where[] = ['mobile', '=', $this->params['mobile']];
  57. }
  58. if(isset($this->params['real_name']) && !empty($this->params['real_name'])){
  59. $where[] = ['real_name', 'like', '%'.$this->params['real_name'].'%'];
  60. }
  61. return $where;
  62. }
  63. /**
  64. * @notes 获取列表
  65. * @return array
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\DbException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @author likeadmin
  70. * @date 2024/07/10 15:06
  71. */
  72. public function lists(): array
  73. {
  74. $params = $this->params;
  75. $list = MasterWorker::hasWhere('serviceWork', function($query) use ($params) {
  76. $query->where('work_type','in',[0,1]);
  77. if (isset($params['work_sn']) && !empty($params['work_sn'])) {
  78. $query->where(['work_sn','=',trim($params['work_sn'])]);
  79. }
  80. if (isset($params['mobile']) && !empty($params['mobile'])) {
  81. $query->where('mobile','=',trim($params['mobile']));
  82. }
  83. if (isset($params['real_name']) && !empty($params['real_name'])) {
  84. $query->where('real_name','like','%'.trim($params['real_name']).'%');
  85. }
  86. if (isset($params['appointment_time']) && !empty($params['appointment_time'])) {
  87. $query->where('appointment_time','between',[strtotime($params['appointment_time']), strtotime($params['appointment_time'].' 23:59:59')]);
  88. }
  89. if (!empty($params['dispatch_time']) && is_array($params['dispatch_time'])) {
  90. $query->where('dispatch_time','between',[strtotime($params['dispatch_time'][0]), strtotime($params['dispatch_time'][1])]);
  91. }
  92. if (empty($params['appointment_time']) && empty($params['dispatch_time'])) {
  93. $query->where('appointment_time','between',[strtotime(date('Y-m-d')), strtotime(date('Y-m-d 23:59:59'))]);
  94. }
  95. })->with(['serviceWork' => function($query) use($params) {
  96. $query->where('work_type','in',[0,1]);
  97. if (isset($params['work_sn']) && !empty($params['work_sn'])) {
  98. $query->where(['work_sn','=',trim($params['work_sn'])]);
  99. }
  100. if (isset($params['mobile']) && !empty($params['mobile'])) {
  101. $query->where('mobile','=',trim($params['mobile']));
  102. }
  103. if (isset($params['real_name']) && !empty($params['real_name'])) {
  104. $query->where('real_name','like','%'.trim($params['real_name']).'%');
  105. }
  106. if (isset($params['appointment_time']) && !empty($params['appointment_time'])) {
  107. $query->where('appointment_time','between',[strtotime($params['appointment_time']), strtotime($params['appointment_time'].' 23:59:59')]);
  108. }
  109. if (!empty($params['dispatch_time']) && is_array($params['dispatch_time'])) {
  110. $query->where('dispatch_time','between',[strtotime($params['dispatch_time'][0]), strtotime($params['dispatch_time'][1])]);
  111. }
  112. if (empty($params['appointment_time']) && empty($params['dispatch_time'])) {
  113. $query->where('appointment_time','between',[strtotime(date('Y-m-d')), strtotime(date('Y-m-d 23:59:59'))]);
  114. }
  115. }])
  116. ->where($this->searchWhere)
  117. ->where($this->queryWhere())
  118. ->limit($this->limitOffset, $this->limitLength)
  119. ->select()
  120. ->toArray();
  121. foreach($list as &$item) {
  122. $item = [
  123. 'id' => $item['id'],
  124. 'worker_number' => $item['worker_number'],
  125. 'real_name' => $item['real_name'],
  126. 'category_ids' => empty($item['category_ids']) ? [] : explode(",",$item['category_ids']),
  127. 'serviceWork' => $item['serviceWork'],
  128. ];
  129. }
  130. return $list;
  131. }
  132. /**
  133. * @notes 获取数量
  134. * @return int
  135. * @author likeadmin
  136. * @date 2024/07/10 15:06
  137. */
  138. public function count(): int
  139. {
  140. $params = $this->params;
  141. return MasterWorker::hasWhere('serviceWork', function($query) use ($params) {
  142. $query->where('work_type','in',[0,1]);
  143. if (isset($params['work_sn']) && !empty($params['work_sn'])) {
  144. $query->where('work_sn','=',trim($params['work_sn']));
  145. }
  146. if (isset($params['mobile']) && !empty($params['mobile'])) {
  147. $query->where('mobile','=',trim($params['mobile']));
  148. }
  149. if (isset($params['real_name']) && !empty($params['real_name'])) {
  150. $query->where('real_name','like','%'.trim($params['real_name']).'%');
  151. }
  152. })->with('serviceWork')
  153. ->where($this->searchWhere)
  154. ->where($this->queryWhere())
  155. ->count();
  156. }
  157. }