Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PointLogController.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Support\Facades\DB;
  5. use App\Model\PointLog;
  6. use App\User;
  7. use Illuminate\Support\Facades\Auth;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\Storage;
  10. use Validator;
  11. use Helper;
  12. class PointLogController extends Controller
  13. {
  14. public function __construct()
  15. {
  16. DB::enableQueryLog();
  17. }
  18. public function getAll()
  19. {
  20. $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->limit(5)->get();
  21. if($query){
  22. $result = $query;
  23. $res_status = true;
  24. $msg = 'Mendapatkan Data';
  25. $status_msg = $msg;
  26. return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
  27. }else {
  28. $res_status = false;
  29. $msg = 'Data tidak ditemukan';
  30. $status_msg = $msg;
  31. return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
  32. }
  33. }
  34. public function getNonEvent()
  35. {
  36. $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->where('event_id', '=', 0)->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->limit(5)->get();
  37. if($query){
  38. $result = $query;
  39. $res_status = true;
  40. $msg = 'Mendapatkan Data';
  41. $status_msg = $msg;
  42. return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
  43. }else {
  44. $res_status = false;
  45. $msg = 'Data tidak ditemukan';
  46. $status_msg = $msg;
  47. return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
  48. }
  49. }
  50. public function getWithEvent()
  51. {
  52. $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->where('event_id', '=', 1)->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->limit(5)->get();
  53. if($query){
  54. $result = $query;
  55. $res_status = true;
  56. $msg = 'Mendapatkan Data';
  57. $status_msg = $msg;
  58. return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
  59. }else {
  60. $res_status = false;
  61. $msg = 'Data tidak ditemukan';
  62. $status_msg = $msg;
  63. return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
  64. }
  65. }
  66. public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
  67. {
  68. $response['response'] = array(
  69. 'status' => $status,
  70. 'message' => $msg,
  71. 'status_msg' => $status_msg,
  72. );
  73. $response['param'] = !empty($param) ? $param : '';
  74. $response['results'] = $result;
  75. return response()->json($response, 200);
  76. }
  77. }