roll and product
This commit is contained in:
parent
c7ea5af1b4
commit
46c75dc5cb
|
|
@ -20,7 +20,7 @@ class UserController extends SuperController
|
|||
public function __construct()
|
||||
{
|
||||
$model = User::class;
|
||||
$with = ['avatar', 'user_type_record'];
|
||||
$with = ['avatar', "role",'user_type_record'];
|
||||
$select = ['*'];
|
||||
$name_model = 'user';
|
||||
$search = ['name', 'mobile'];
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Models\Message;
|
|||
use App\Models\User;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Setting;
|
||||
use http\Env;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
|
|
@ -115,7 +116,7 @@ class Controller extends BaseController
|
|||
}
|
||||
public static function trigerUrl()
|
||||
{
|
||||
$trigerUrl = 'https://emexgold.com';
|
||||
$trigerUrl = env('wssLink','');
|
||||
if ($_SERVER['HTTP_HOST'] == 'emexgold.com') {
|
||||
$trigerUrl = 'https://emexgold.com';
|
||||
}elseif ($_SERVER['HTTP_HOST'] == 'marandiigold.ir'){
|
||||
|
|
|
|||
|
|
@ -18,154 +18,174 @@ class ProductController extends Controller
|
|||
|
||||
public function list_product($CU_adm = null)
|
||||
{
|
||||
// $PriceController = new PriceController;
|
||||
// $PriceController->b750();
|
||||
|
||||
CustomersSetting::firstOrCreate(['customer_id' => null, 'group' => null, 'agent_id' => null, 'profit_sell' => 0, 'profit_buy' => 0, 'credit_sell' => 10, 'credit_buy' => 10,]);
|
||||
$this->auto_close_open();
|
||||
$userTID = auth()->id();//get token
|
||||
if (auth('customer')->id()){
|
||||
// return response()->json('cu');
|
||||
}else{
|
||||
$userTID = $CU_adm;
|
||||
|
||||
}
|
||||
$userTID = auth('customer')->id() ?? $CU_adm;
|
||||
$customer = CustomerModel::with(['agent.CustomersSetting', 'CustomersSetting'])->find($userTID);
|
||||
$list_product = Product::with('price')->where('active', 1)->get();
|
||||
|
||||
$customer = CustomerModel::with(['agent.CustomersSetting', 'CustomersSetting'])->where('id', $userTID)->first();
|
||||
$list_product = Product::with(['price'])->where('active', 1)->get();
|
||||
$current_time = now()->format('H:i:s');
|
||||
|
||||
foreach ($list_product as &$product) {
|
||||
$prises = [];
|
||||
$current_time = now()->format('H:i:s');
|
||||
// تعیین وضعیت باز بودن فروش و خرید هر محصول
|
||||
foreach ($list_product as $product) {
|
||||
$show = ($current_time >= $product->auto_open_at && $current_time <= $product->auto_close_at);
|
||||
if (!$show) {
|
||||
$product->open_sell = $show;
|
||||
$product->open_buy = $show;
|
||||
}
|
||||
$product->open_sell = $show;
|
||||
$product->open_buy = $show;
|
||||
}
|
||||
|
||||
// گرفتن قیمت پایه هر محصول
|
||||
$prises = [];
|
||||
foreach ($list_product as $product) {
|
||||
$prises[$product->id] = $this->getprices($product, 'double');
|
||||
}
|
||||
|
||||
|
||||
$customerSettings = [];
|
||||
$productHasSetting = [];
|
||||
|
||||
if ($customer->agent_id) {
|
||||
// تنظیمات پیش فرض عمومی برای همه
|
||||
|
||||
foreach ($list_product as $key => &$product) {
|
||||
$prises[$product->id]= ["sell_price" => $product->price->diff_buy + $product->price->difference_provider , "buy_price" => $product->price->diff_sell + $product->price->difference_provider];
|
||||
$agent = CustomerModel::with(['agent','CustomersSetting'])->where('id',$customer->agent_id)->first();
|
||||
$settings = $agent->customersSetting()->get();
|
||||
$agent = $customer->agent_id ? CustomerModel::find($customer->agent_id) : $customer;
|
||||
function setAttribute($setting,&$prises,$product,$agent,$list_product,$key){
|
||||
$prises[$product->id]['buy_price'] += $setting->profit_buy;
|
||||
$prises[$product->id]['sell_price'] += $setting->profit_sell;
|
||||
$prises[$product->id]['credit_buy'] = ($prises[$product->id]['credit_buy'] ?? 0) + ($setting->credit_buy ?? 0);
|
||||
$prises[$product->id]['credit_sell'] = ($prises[$product->id]['credit_sell'] ?? 0) + ($setting->credit_sell ?? 0);
|
||||
if (!$setting->is_active){
|
||||
unset($prises[$product->id]);
|
||||
unset($list_product[$key]);
|
||||
}
|
||||
return $setting;
|
||||
}
|
||||
|
||||
do {
|
||||
$settings = (isset($agent))? $agent->customersSetting()->get()
|
||||
:CustomersSetting::whereNull('customer_id')->whereNull('group')->whereNull('agent_id');
|
||||
foreach ($list_product as $key => $product) {
|
||||
if ($setting = $settings->where('customer_id', $customer->id)->where('product_id', $product->id)->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["customer"]=$setting;
|
||||
}
|
||||
elseif ($setting=$settings->where('customer_id', $customer->id)->whereNull('product_id')->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["customer"]=$setting;
|
||||
}
|
||||
elseif ($setting=$settings->where('group', $customer->group)->where('product_id', $product->id)->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["customer"]=$setting;
|
||||
}
|
||||
elseif ($setting=$settings->where('group', $customer->group)->whereNull('product_id')->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["customer"]=$setting;
|
||||
}
|
||||
elseif ($setting = $settings->whereNull('group')->whereNull('customer_id')->where('product_id', $product->id)->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["customer"]=$setting;
|
||||
}
|
||||
elseif ($setting = $settings->whereNull('group')->whereNull('product_id')->whereNull('customer_id')->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["customer"]=$setting;
|
||||
}else{
|
||||
unset($prises[$key]);
|
||||
$setting= setAttribute($setting,$prises,$product,$agent,$list_product,$key);
|
||||
} elseif ($setting = $settings->where('customer_id', $customer->id)->whereNull('product_id')->first()) {
|
||||
$setting= setAttribute($setting,$prises,$product,$agent,$list_product,$key);
|
||||
} elseif ($setting = $settings->where('group', $customer->group)->where('product_id', $product->id)->first()) {
|
||||
$setting= setAttribute($setting,$prises,$product,$agent,$list_product,$key);
|
||||
} elseif ($setting = $settings->where('group', $customer->group)->whereNull('product_id')->first()) {
|
||||
$setting=setAttribute($setting,$prises,$product,$agent,$list_product,$key);
|
||||
} elseif ($setting = $settings->whereNull('group')->whereNull('customer_id')->where('product_id', $product->id)->first()) {
|
||||
$setting=setAttribute($setting,$prises,$product,$agent,$list_product,$key);
|
||||
} elseif ($setting = $settings->whereNull('group')->whereNull('product_id')->whereNull('customer_id')->first()) {
|
||||
$setting=setAttribute($setting,$prises,$product,$agent,$list_product,$key);
|
||||
} elseif ($setting = CustomersSetting::whereNull('customer_id')->whereNull('group')->whereNull('agent_id')->where('product_id', $product->id)->first() ) {
|
||||
$setting=setAttribute($setting,$prises,$product,$agent,$list_product,$key);
|
||||
} elseif ($setting = CustomersSetting::whereNull('customer_id')->whereNull('group')->whereNull('agent_id')->first()) {
|
||||
$setting= setAttribute($setting,$prises,$product,$agent,$list_product,$key);
|
||||
}else {
|
||||
unset($prises[$product->id]);
|
||||
unset($list_product[$key]);
|
||||
}
|
||||
$customerSettings[$agent->id??0][$product->id] = $setting;
|
||||
$customerSettings['all_levels'][$product->id][] = $setting;
|
||||
}
|
||||
// رفتن به ایجنت سطح بالاتر
|
||||
$agent = $agent ? CustomerModel::find($agent->agent_id) : null;
|
||||
} while ($agent);
|
||||
//return $prises;
|
||||
|
||||
if (isset($agent->agent_id) and $agent->agent_id) {
|
||||
foreach ($list_product as $key => &$product) {
|
||||
$agent2 = CustomerModel::with(['agent','CustomersSetting'])->where('id',$agent->agent_id)->first();
|
||||
$settings = $agent2->customersSetting()->get();
|
||||
// $prises[$product->id]['buy_price'] = 200000;
|
||||
// $prises[$product->id]['sell_price']= 200000;
|
||||
if ($setting = $settings->where('customer_id', $agent->id)->where('product_id', $product->id)->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["agent"]=$setting;
|
||||
}
|
||||
elseif ($setting=$settings->where('customer_id', $agent->id)->whereNull('product_id')->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["agent"]=$setting;
|
||||
}
|
||||
elseif ($setting=$settings->where('group', $agent->group)->where('product_id', $product->id)->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["agent"]=$setting;
|
||||
}
|
||||
elseif ($setting=$settings->where('group', $agent->group)->whereNull('product_id')->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["agent"]=$setting;
|
||||
}
|
||||
elseif ($setting = $settings->whereNull('group')->whereNull('customer_id')->where('product_id', $product->id)->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["agent"]=$setting;
|
||||
}
|
||||
elseif ($setting = $settings->whereNull('group')->whereNull('product_id')->whereNull('customer_id')->first()) {
|
||||
$prises[$product->id]['buy_price']+=$setting->profit_buy;
|
||||
$prises[$product->id]['sell_price']+=$setting->profit_sell;
|
||||
$customerSettings["agent"]=$setting;
|
||||
}else{
|
||||
unset($prises[$key]);
|
||||
unset($list_product[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// $product->price->difference
|
||||
|
||||
foreach ($list_product as &$product) {
|
||||
$BPR = $product->price->diff_sell + $product->price->difference_provider;
|
||||
$SPR = $product->price->diff_buy + $product->price->difference_provider ;
|
||||
// dd([$BPR,$SPR,$product]);
|
||||
if ($product->unit =="گرم" ){
|
||||
$prises[$product->id]['buy_gram_price'] = round($BPR / config('change_mesghal'));
|
||||
$prises[$product->id]['sell_gram_price'] =round($SPR /config('change_mesghal'));
|
||||
}else{
|
||||
$prises[$product->id]['buy_gram_price']=$BPR;
|
||||
$prises[$product->id]['sell_gram_price'] =$SPR;
|
||||
}
|
||||
|
||||
$product->customerSettings = $customerSettings;
|
||||
|
||||
if (!$customer->agent_id) {
|
||||
$prises[$product->id]['buy_price']=$BPR;
|
||||
$prises[$product->id]['sell_price'] =$SPR;
|
||||
$product->sub_agent = $product[$product->id];
|
||||
foreach ($list_product as $product) {
|
||||
if ($product->unit == "گرم") {
|
||||
$prises[$product->id]['buy_gram_price'] = round($product->price->difference / config('change_mesghal'));
|
||||
$prises[$product->id]['sell_gram_price'] = round($product->price->difference / config('change_mesghal'));
|
||||
} else {
|
||||
$prises[$product->id]['buy_gram_price'] = $product->price->difference;
|
||||
$prises[$product->id]['sell_gram_price'] = $product->price->difference;
|
||||
}
|
||||
|
||||
if (isset($prises[$product->id])) {
|
||||
$prises[$product->id]['rate_buy_price'] = $product->price->price+$prises[$product->id]['buy_price'];
|
||||
$prises[$product->id]['rate_sell_price'] = $product->price->price-$prises[$product->id]['sell_price'];
|
||||
if ($product->unit =="گرم" ){
|
||||
$prises[$product->id]['rate_buy_price'] = $product->price->price + $prises[$product->id]['buy_price'];
|
||||
$prises[$product->id]['rate_sell_price'] = $product->price->price - $prises[$product->id]['sell_price'];
|
||||
|
||||
if ($product->unit == "گرم") {
|
||||
$prises[$product->id]['change_mesghal'] = config('change_mesghal');
|
||||
$prises[$product->id]['rate_buy_gram_price'] =($product->price->price+$prises[$product->id]['buy_price'])/config('change_mesghal');
|
||||
$prises[$product->id]['rate_sell_gram_price'] =($product->price->price-$prises[$product->id]['sell_price'])/config('change_mesghal');
|
||||
$prises[$product->id]['rate_buy_gram_price'] = $prises[$product->id]['rate_buy_price'] / config('change_mesghal');
|
||||
$prises[$product->id]['rate_sell_gram_price'] = $prises[$product->id]['rate_sell_price'] / config('change_mesghal');
|
||||
}
|
||||
|
||||
$product->sub_agent = $prises[$product->id];
|
||||
$product->customerSettings = $customerSettings;
|
||||
}
|
||||
|
||||
// ✅ اضافه کردن همه تنظیمات سطوح ایجنت
|
||||
$product->customersetting = $customerSettings['all_levels'][$product->id] ?? [];
|
||||
}
|
||||
|
||||
return response()->json($list_product->values());
|
||||
}
|
||||
|
||||
private function statusforcustomersetting($customer, int $productId): bool
|
||||
{
|
||||
$specificSetting = $customer->customersSetting()
|
||||
->where('product_id', $productId)
|
||||
->first();
|
||||
|
||||
if ($specificSetting) {
|
||||
return $specificSetting->is_active == 0;
|
||||
}
|
||||
|
||||
if (empty($customer->group)) {
|
||||
$groupSetting = CustomersSetting::where('group', $customer->group)
|
||||
->where('product_id', $productId)
|
||||
->first();
|
||||
|
||||
if ($groupSetting) {
|
||||
return $groupSetting->is_active == 0;
|
||||
}
|
||||
}
|
||||
// return response()->json($customerSettings);
|
||||
return response()->json($list_product);
|
||||
$agent = $customer->agent;
|
||||
while ($agent) {
|
||||
$specificAgentSetting = $agent->customersSetting()
|
||||
->where('product_id', $productId)
|
||||
->first();
|
||||
|
||||
if ($specificAgentSetting) {
|
||||
return $specificAgentSetting->is_active == 0;
|
||||
}
|
||||
$agent = $agent->agent;
|
||||
}
|
||||
|
||||
//بر اساس تنظیمات عمومی
|
||||
// $defaultSetting = \App\Models\CustomersSetting::whereNull('customer_id')
|
||||
// ->whereNull('group')
|
||||
// ->whereNull('agent_id')
|
||||
// ->where(function ($q) use ($productId) {
|
||||
// $q->where('product_id', $productId)
|
||||
// ->orWhereNull('product_id');
|
||||
// })
|
||||
// ->first();
|
||||
//
|
||||
// if ($defaultSetting) {
|
||||
// return $defaultSetting->is_active == 0;
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getPrices(Product $product, string $mode = 'single')
|
||||
{
|
||||
if ($mode === 'double') {
|
||||
return [
|
||||
"sell_price" => $product->price->diff_buy + $product->price->difference_provider,
|
||||
"buy_price" => $product->price->diff_sell + $product->price->difference_provider,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
"sell_price" => $product->price->difference_provider,
|
||||
"buy_price" => $product->price->difference_provider,
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function list_product1($customer_id =null)
|
||||
{
|
||||
$PriceController = new PriceController;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Role extends Model
|
||||
{
|
||||
use softDeletes;
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['name', 'permissions'];
|
||||
|
||||
protected $casts = [
|
||||
'permissions' => 'array',
|
||||
];
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->hasMany(User::class, 'role_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -31,7 +31,8 @@ class User extends Authenticatable implements JWTSubject
|
|||
'last_seen_at',
|
||||
'active',
|
||||
'avatar_id',
|
||||
'sts'
|
||||
'sts',
|
||||
'role_id'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -75,7 +76,11 @@ class User extends Authenticatable implements JWTSubject
|
|||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function role()
|
||||
{
|
||||
return $this->belongsTo(Role::class,
|
||||
'role_id','id');
|
||||
}
|
||||
// hash password
|
||||
public function setPasswordAttribute($value){
|
||||
$this->attributes['password'] = Hash::make($value);
|
||||
|
|
|
|||
|
|
@ -62,6 +62,10 @@ class RouteServiceProvider extends ServiceProvider
|
|||
->middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/site.php'));
|
||||
Route::prefix('roles')
|
||||
->middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/roles.php'));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
|
@ -64,6 +64,13 @@ Route::middleware('auth:customer')->group(function () {
|
|||
Route::put('/agent/customer_setting/{id}', [DashboardAgentController::class, 'creat_customer_setting_id']);
|
||||
Route::get('/agent/customer_setting', [DashboardAgentController::class, 'get_customer_setting']);
|
||||
Route::get('/agent/customer_setting/{id}', [DashboardAgentController::class, 'get_customer_setting_id']);
|
||||
//--------------agent
|
||||
Route::get('/dashboard', [DashboardAgentController::class, 'index']);
|
||||
Route::post('/customers', [DashboardAgentController::class, 'agent_customers']);
|
||||
Route::post('/customer_setting', [DashboardAgentController::class, 'customer_setting']);
|
||||
Route::put('/customer_setting/{id}', [DashboardAgentController::class, 'creat_customer_setting_id']);
|
||||
Route::get('/customer_setting', [DashboardAgentController::class, 'get_customer_setting']);
|
||||
Route::get('/customer_setting/{id}', [DashboardAgentController::class, 'get_customer_setting_id']);
|
||||
|
||||
//--------------Customer
|
||||
Route::get('/me', [CustomerController::class, 'me']);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
|
||||
Route::get('/roles', function () {
|
||||
$roles = Role::all();
|
||||
if ($roles->isEmpty()) {
|
||||
return response()->json(['message' => 'نقشی یافت نشد'], 404);
|
||||
}
|
||||
return response()->json($roles);
|
||||
})->name('roles.index');
|
||||
|
||||
|
||||
Route::post('/roles', function (Request $request) {
|
||||
$missingFields = [];
|
||||
|
||||
if (!$request->has('name') || empty($request->name)) {
|
||||
$missingFields[] = 'نام';
|
||||
} elseif (Role::where('name', $request->name)->exists()) {
|
||||
return response()->json(['message' => 'فیلد نام قبلا ذخیره شده است'], 422);
|
||||
}
|
||||
|
||||
if (!$request->has('permissions') || empty($request->permissions)) {
|
||||
$missingFields[] = 'دسترسی';
|
||||
}
|
||||
|
||||
if (!empty($missingFields)) {
|
||||
$message = 'فیلد ' . implode(' و ', $missingFields) . ' اجباری میباشد';
|
||||
return response()->json(['message' => $message], 422);
|
||||
}
|
||||
|
||||
$role = Role::create([
|
||||
'name' => $request->name,
|
||||
'permissions' => $request->permissions ?? [],
|
||||
]);
|
||||
|
||||
return response()->json(['message' => 'نقش با موفقیت ایجاد شد', 'role' => $role], 201);
|
||||
})->name('roles.store');
|
||||
|
||||
|
||||
Route::put('/roles/{id}', function (Request $request, $id) {
|
||||
$role = Role::find($id);
|
||||
if (!$role) {
|
||||
return response()->json(['message' => 'نقش مورد نظر پیدا نشد'], 422);
|
||||
}
|
||||
|
||||
$missingFields = [];
|
||||
|
||||
if (!$request->has('name') || empty($request->name)) {
|
||||
$missingFields[] = 'نام';
|
||||
}
|
||||
|
||||
if (!$request->has('permissions') || empty($request->permissions)) {
|
||||
$missingFields[] = 'دسترسی';
|
||||
}
|
||||
|
||||
if (!empty($missingFields)) {
|
||||
$message = 'فیلد ' . implode(' و ', $missingFields) . ' اجباری میباشد';
|
||||
return response()->json(['message' => $message], 422);
|
||||
}
|
||||
|
||||
$role->update([
|
||||
'name' => $request->name,
|
||||
'permissions' => $request->permissions ?? [],
|
||||
]);
|
||||
|
||||
return response()->json(['message' => 'نقش با موفقیت بهروزرسانی شد', 'role' => $role], 200);
|
||||
})->name('roles.update');
|
||||
|
||||
|
||||
Route::delete('/roles/{id}', function ($id) {
|
||||
$role = Role::find($id);
|
||||
if (!$role) {
|
||||
return response()->json(['message' => 'نقش مورد نظر پیدا نشد'], 404);
|
||||
}
|
||||
$role->delete();
|
||||
return response()->json(['message' => 'نقش با موفقیت حذف شد', 'role' => $role], 200);
|
||||
})->name('roles.destroy');
|
||||
|
||||
Route::get('/server/admin/me', function (Request $request) {
|
||||
|
||||
$user = \App\Models\User::with('role')->find(2);
|
||||
|
||||
return response()->json([
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'role_id' => $user->role_id,
|
||||
'permissions' => $user->permissions,
|
||||
'active' => $user->active,
|
||||
'super_admin' => $user->super_admin
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Route::get('/server/admin/user/{id}', function ($id) {
|
||||
$user = User::with('role')->find($id);
|
||||
if (!$user) {
|
||||
return response()->json(['message' => 'کاربر یافت نشد'], 404);
|
||||
}
|
||||
return response()->json([
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'role_id' => $user->role_id,
|
||||
'permissions' => $user->role ? $user->role->permissions : [],
|
||||
'active' => $user->active,
|
||||
'super_admin' => $user->super_admin,
|
||||
]);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue