OrderIssuePerformanceService.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Services;
  3. use App\OrderIssueProcessLog;
  4. use App\Owner;
  5. use App\Services\common\QueryService;
  6. use App\User;
  7. use App\Exports\Export;
  8. use Carbon\Carbon;
  9. use Illuminate\Pagination\LengthAwarePaginator;
  10. use Illuminate\Pagination\Paginator;
  11. use Illuminate\Support\Facades\Auth;
  12. use Illuminate\Support\Facades\DB;
  13. use Maatwebsite\Excel\Facades\Excel;
  14. use App\Traits\ServiceAppAop;
  15. class OrderIssuePerformanceService
  16. {
  17. use ServiceAppAop;
  18. public function paginate(array $params)
  19. {
  20. $paginate = $params['paginate'] ?? 50;
  21. $page = $params['page'] ?? 1;
  22. $data = $this->queryAll($params);
  23. $collection = collect($data);
  24. $list = $collection->slice(($page - 1) * $paginate, $paginate)->all();
  25. $option = ['path' => Paginator::resolveCurrentPath()];
  26. $paginate = new LengthAwarePaginator($list, $collection->count(), $paginate, $page,$option );
  27. return $paginate;
  28. }
  29. public function queryAll($params)
  30. {
  31. $sql = $this->getSql($params);
  32. return $result = DB::select($sql);
  33. }
  34. public function getSql($params){
  35. $sql =" select users.name as userName,owners.name as ownerName,count(case order_issue_process_logs.type WHEN '创建' THEN 1 end ) as created, count(case order_issue_process_logs.type WHEN '处理' THEN 1 end ) as processed, count(case order_issue_process_logs.type WHEN '结束' THEN 1 end ) as end,count(1) as sumNumber ";
  36. $sql.=" from order_issue_process_logs inner join users on order_issue_process_logs.user_id = users.id inner join order_issues on order_issue_process_logs.order_issue_id = order_issues.id inner join orders on order_issues.order_id = orders.id inner join owners on orders.owner_id = owners.id ";
  37. $sql.=" where 1=1 ";
  38. if(isset($params['create_start'])){
  39. $sql.= " and order_issue_process_logs.created_at >= '".$params['create_start']." 00:00:00' ";
  40. }
  41. if(isset($params['create_end'])){
  42. $sql.= " and order_issue_process_logs.created_at <= '".$params['create_end']." 23:59:59' ";
  43. }
  44. if (isset($params['timeFrame'])) {
  45. $create_start ='';$create_end ='';
  46. if ($params['timeFrame'] == 'day') {
  47. $create_start = date('Y-m-d');
  48. $create_end = date('Y-m-d');
  49. } else if ($params['timeFrame'] == 'yesterday') {
  50. $create_start = date('Y-m-d', strtotime('-1 day'));
  51. $create_end = date('Y-m-d', strtotime('-1 day'));
  52. } else if ($params['timeFrame'] == 'week') {
  53. $date = date('Y-m-d', strtotime('-1 weeks', strtotime('Monday')));
  54. $create_start = $date;
  55. $create_end = date('Y-m-d');
  56. } else if ($params['timeFrame'] == 'month') {
  57. $create_start = date('Y-m-01', strtotime(date("Y-m-d")));
  58. $create_end = date('Y-m-d');
  59. }
  60. $sql.= " and order_issue_process_logs.created_at >= '".$create_start." 00:00:00' ";
  61. $sql.= " and order_issue_process_logs.created_at <= '".$create_end." 23:59:59' ";
  62. }
  63. $sql.= "group by users.name, owners.name;";
  64. return $sql;
  65. }
  66. }