mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-08-01 08:16:55 -04:00
106 lines
3.9 KiB
PHP
106 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\Staff\Http\Controllers;
|
|
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\Setup\Entities\Department;
|
|
use Modules\RolePermission\Entities\Role;
|
|
use Modules\WTIJobBoard\Entities\JobRequest;
|
|
use Modules\WTIJobBoard\Entities\JobRequestCategory;
|
|
use Modules\WTIJobBoard\Entities\JobRequestBadge;
|
|
use Modules\StudioPlus\Entities\StudioPlusVideo;
|
|
use Modules\Staff\Transformers\StaffResource;
|
|
use App\Traits\ImageStore;
|
|
use Modules\Staff\Entities\Staff;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Cache;
|
|
|
|
class StaffAccountController extends Controller
|
|
{
|
|
|
|
public function index($user_id)
|
|
{
|
|
$staff = Staff::with('user.role.permissions','department')->whereHas('user', function($query) use($user_id){
|
|
$query->where('id', $user_id);
|
|
})->first();
|
|
|
|
if($staff){
|
|
$roles = Role::where('id', '>', 1)->where('type','staff')->get();
|
|
if(isModuleActive('RolePermissionPlus')){
|
|
$roles = Role::where('id', '>', 1)->get();
|
|
}
|
|
$departments = Department::where('status', 1)->orderBy('name')->get();
|
|
|
|
$referrals = Staff::with('user.role','department')->whereHas('user', function($query) use($staff){
|
|
$query->where('parent_id',$staff->user_id);
|
|
})->get();
|
|
$badges = JobRequestBadge::orderByRaw('-`order` DESC')->get();
|
|
|
|
$uplines = Staff::with(['user:id,first_name,last_name,email,avatar,role_id','user.role:id,name'])->whereHas('user.role', function($query) use($user_id){
|
|
$query->where('id', '>', 1)->orWhere('id', '!=', $user_id)->orderBy('first_name');
|
|
})->get(['user_id']);
|
|
|
|
|
|
return view('staff::staff')->with('staff',$staff)->with('roles',$roles)->with('badges',$badges)->with('departments',$departments)->with('uplines',$uplines)->with('referrals',$referrals);
|
|
}
|
|
|
|
return redirect()->to('/admin/staffs');
|
|
}
|
|
|
|
public function jobsData($user_id, Request $request)
|
|
{
|
|
$query = JobRequest::query()->with(['category', 'video', 'product', 'tracks.status', 'tracks.metas', 'shipment'])->where('is_approved', true)->where(function($query) use($user_id){
|
|
$query->whereHas('applications', function($query) use($user_id){
|
|
$query->where('is_hired', true)->where('applicant_id', $user_id);
|
|
});
|
|
})->whereHas('category', function ($query) {
|
|
$query->where('will_be_shipped', 1);
|
|
})->where('status','publish')->whereNull('deleted_at');
|
|
|
|
|
|
$jobs = $query->clone()->get();
|
|
|
|
|
|
$type_ids = [];
|
|
$categories = Cache::remember('categories', 300, function() {
|
|
return JobRequestCategory::where('active',1)->get();
|
|
});
|
|
|
|
foreach ($categories as $key => $category) {
|
|
if($category->route_permission != null && permissionCheck($category->route_permission)){
|
|
array_push($type_ids, $category->id);
|
|
}
|
|
}
|
|
|
|
$categories = JobRequestCategory::whereIn('id', $type_ids)->orderByRaw('-`order` DESC')->get();
|
|
|
|
|
|
return response()->json([
|
|
'jobs' => $jobs,
|
|
'categories' => $categories
|
|
]);
|
|
}
|
|
|
|
public function videosStatistics($user_id, Request $request)
|
|
{
|
|
$statistics = StudioPlusVideo::query()->whereHas('channel', function($query) use ($user_id){
|
|
$query->where('user_id', $user_id);
|
|
});
|
|
|
|
$all = $statistics->clone()->count();
|
|
$rejected = $statistics->clone()->where('status', StudioPlusVideo::STATUS_REJECTED)
|
|
->count();
|
|
$published = $statistics->clone()->where('status', StudioPlusVideo::STATUS_PUBLISHED)
|
|
->count();
|
|
|
|
return response()->json([
|
|
'all' => $all,
|
|
'rejected' => $rejected,
|
|
'published' => $published
|
|
]);
|
|
}
|
|
}
|