ServiceWorkLists.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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\goods_category\GoodsCategory;
  17. use app\common\model\works\ServiceWork;
  18. use app\common\lists\ListsSearchInterface;
  19. use think\db\Query;
  20. /**
  21. * ServiceWork列表
  22. * Class ServiceWorkLists
  23. * @package app\adminapi\listsworks
  24. */
  25. class ServiceWorkLists 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','work_sn', 'real_name', 'mobile', 'address', 'title', 'category_type', 'base_service_fee', 'service_fee', 'work_status','work_pay_status', 'service_status', 'finished_images', 'master_worker_id', 'work_amount','work_type','appoint_approval','refund_approval'],
  37. ];
  38. }
  39. public function queryWhere(){
  40. $where = [];
  41. if(isset($this->params['dispatch_time']) && !empty($this->params['dispatch_time'])){
  42. $time = [strtotime($this->params['dispatch_time'][0]), strtotime($this->params['dispatch_time'][1])];
  43. $where[] = ['dispatch_time', 'between', $time];
  44. }
  45. if(isset($this->params['receive_time']) && !empty($this->params['receive_time'])){
  46. $time = [strtotime($this->params['receive_time'][0]), strtotime($this->params['receive_time'][1])];
  47. $where[] = ['receive_time', 'between', $time];
  48. }
  49. if(isset($this->params['appointment_time']) && !empty($this->params['appointment_time'])){
  50. $time = [strtotime($this->params['appointment_time'][0]), strtotime($this->params['appointment_time'][1])];
  51. $where[] = ['appointment_time', 'between', $time];
  52. }
  53. if(isset($this->params['finished_time']) && !empty($this->params['finished_time'])){
  54. $time = [strtotime($this->params['finished_time'][0]), strtotime($this->params['finished_time'][1])];
  55. $where[] = ['finished_time', 'between', $time];
  56. }
  57. if(isset($this->params['create_time']) && !empty($this->params['create_time'])){
  58. $time = [strtotime($this->params['create_time'][0]), strtotime($this->params['create_time'][1])];
  59. $where[] = ['create_time', 'between', $time];
  60. }
  61. if(isset($this->params['update_time']) && !empty($this->params['update_time'])){
  62. $time = [strtotime($this->params['update_time'][0]), strtotime($this->params['update_time'][1])];
  63. $where[] = ['update_time', 'between', $time];
  64. }
  65. if(isset($this->params['appoint_approval']) && !empty($this->params['appoint_approval'])){
  66. // 时间 超过15分钟未确认
  67. $time = time()-15*60;
  68. $where[] = ['update_time', '<', $time];
  69. }
  70. if(isset($this->params['workid']) && !empty($this->params['workid'])){
  71. $where[] = ['master_worker_id', '=', $this->params['workid']];
  72. $where[] = ['work_status', 'NOT IN', [7,8,9]];
  73. }
  74. if (isset($this->params['update_time']) && !empty($this->params['goods_category_id'])) {
  75. $goodsCategoryId = end($this->params['goods_category_id']);
  76. $goodsCategoryData = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  77. ->select()->toArray();
  78. $ids =get_tree_ids($goodsCategoryData,$goodsCategoryId);
  79. $ids[] = $goodsCategoryId;
  80. $where[] = ['goods_category_id','in' ,$ids];
  81. }
  82. //$where[] = ['work_pay_status','>',0];
  83. return $where;
  84. }
  85. /**
  86. * @notes 获取列表
  87. * @return array
  88. * @throws \think\db\exception\DataNotFoundException
  89. * @throws \think\db\exception\DbException
  90. * @throws \think\db\exception\ModelNotFoundException
  91. * @author likeadmin
  92. * @date 2024/07/10 15:06
  93. */
  94. public function lists(): array
  95. {
  96. return ServiceWork::with([
  97. 'worker'=>function(Query $query) {
  98. $query->field("id,worker_number,real_name,mobile");
  99. },
  100. 'goodsCategory' =>function (Query $query) {
  101. $query->field('id,name');
  102. },
  103. 'allocateWorkerLog' =>function(Query $query){
  104. $query->field('id,work_id,opera_log,create_time');
  105. },
  106. 'serviceWorkLog' =>function(Query $query){
  107. $query->field('id,work_id,opera_log,create_time');
  108. }
  109. ])
  110. ->where($this->searchWhere)
  111. ->where($this->queryWhere())
  112. ->field(['id', 'work_sn', 'real_name', 'mobile', 'address', 'title', 'category_type', 'goods_category_ids', 'goods_category_id', 'base_service_fee', 'service_fee', 'work_status','work_pay_status', 'service_status', 'dispatch_time', 'receive_time', 'appointment_time', 'finished_images', 'finished_time', 'master_worker_id', 'work_amount', 'work_type', 'create_time', 'update_time','lon', 'lat','appoint_approval','refund_approval'])
  113. ->limit($this->limitOffset, $this->limitLength)
  114. ->order(['id' => 'desc'])
  115. ->select()
  116. ->toArray();
  117. }
  118. /**
  119. * @notes 获取数量
  120. * @return int
  121. * @author likeadmin
  122. * @date 2024/07/10 15:06
  123. */
  124. public function count(): int
  125. {
  126. return ServiceWork::where($this->searchWhere)->where($this->queryWhere())->count();
  127. }
  128. }