123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
-
- namespace App\Http\Controllers\Api\V1;
-
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\DB;
- use App\Model\PointLog;
- use App\User;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Storage;
- use Validator;
- use Helper;
-
-
- class PointLogController extends Controller
- {
- public function __construct()
- {
- DB::enableQueryLog();
- }
-
- public function getAll()
- {
- $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')->get();
-
- if($query){
- $result = $query;
-
- $res_status = true;
- $msg = 'Mendapatkan Data';
- $status_msg = $msg;
-
- return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
-
- }else {
-
- $res_status = false;
- $msg = 'Data tidak ditemukan';
- $status_msg = $msg;
-
- return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
- }
- }
-
- public function getNonEvent()
- {
- $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')->get();
-
- if($query){
- $result = $query;
-
- $res_status = true;
- $msg = 'Mendapatkan Data';
- $status_msg = $msg;
-
- return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
-
- }else {
-
- $res_status = false;
- $msg = 'Data tidak ditemukan';
- $status_msg = $msg;
-
- return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
- }
- }
-
- public function getWithEvent()
- {
- $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')->get();
-
- if($query){
- $result = $query;
-
- $res_status = true;
- $msg = 'Mendapatkan Data';
- $status_msg = $msg;
-
- return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
-
- }else {
-
- $res_status = false;
- $msg = 'Data tidak ditemukan';
- $status_msg = $msg;
-
- return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
- }
- }
-
- public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
- {
- $response['response'] = array(
- 'status' => $status,
- 'message' => $msg,
- 'status_msg' => $status_msg,
- );
- $response['param'] = !empty($param) ? $param : '';
-
- $response['results'] = $result;
-
- return response()->json($response, 200);
- }
-
-
- }
|