OrderIssuePerformanceService.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. class OrderIssuePerformanceService
  15. {
  16. public function paginate(array $params)
  17. {
  18. $paginate = $params['paginate'] ?? 50;
  19. $page = $params['page'] ?? 1;
  20. $data = $this->queryAll($params);
  21. $collection = collect($data);
  22. $list = $collection->slice(($page - 1) * $paginate, $paginate)->all();
  23. $option = ['path' => Paginator::resolveCurrentPath()];
  24. $paginate = new LengthAwarePaginator($list, $collection->count(), $paginate, $page,$option );
  25. return $paginate;
  26. }
  27. public function queryAll($params)
  28. {
  29. $sql = $this->getSql($params);
  30. return $result = DB::select($sql);
  31. }
  32. public function getSql($params){
  33. $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 ";
  34. $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 ";
  35. $sql.=" where 1=1 ";
  36. if(isset($params['create_start'])){
  37. $sql.= " and order_issue_process_logs.created_at >= '".$params['create_start']." 00:00:00' ";
  38. }
  39. if(isset($params['create_end'])){
  40. $sql.= " and order_issue_process_logs.created_at <= '".$params['create_end']." 23:59:59' ";
  41. }
  42. if (isset($params['timeFrame'])) {
  43. $create_start ='';$create_end ='';
  44. if ($params['timeFrame'] == 'day') {
  45. $create_start = date('Y-m-d');
  46. $create_end = date('Y-m-d');
  47. } else if ($params['timeFrame'] == 'yesterday') {
  48. $create_start = date('Y-m-d', strtotime('-1 day'));
  49. $create_end = date('Y-m-d', strtotime('-1 day'));
  50. } else if ($params['timeFrame'] == 'week') {
  51. $date = date('Y-m-d', strtotime('-1 weeks', strtotime('Monday')));
  52. $create_start = $date;
  53. $create_end = date('Y-m-d');
  54. } else if ($params['timeFrame'] == 'month') {
  55. $create_start = date('Y-m-01', strtotime(date("Y-m-d")));
  56. $create_end = date('Y-m-d');
  57. }
  58. $sql.= " and order_issue_process_logs.created_at >= '".$create_start." 00:00:00' ";
  59. $sql.= " and order_issue_process_logs.created_at <= '".$create_end." 23:59:59' ";
  60. }
  61. $sql.= "group by users.name, owners.name;";
  62. return $sql;
  63. }
  64. }