2023-08-01 12:27:33 +00:00
|
|
|
<?php namespace AhmadFatoni\ApiGenerator\Controllers\API;
|
|
|
|
|
|
|
|
|
|
use Cms\Classes\Controller;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
2023-08-03 16:21:42 +00:00
|
|
|
use TPS\Birzha\Models\Notification;
|
2023-08-01 12:27:33 +00:00
|
|
|
use RainLab\User\Models\User as Vendor;
|
|
|
|
|
|
|
|
|
|
class VendorApiController extends Controller
|
|
|
|
|
{
|
|
|
|
|
protected $Vendor;
|
|
|
|
|
|
|
|
|
|
protected $helpers;
|
|
|
|
|
|
|
|
|
|
public function __construct(Vendor $Vendor, Helpers $helpers)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->Vendor = $Vendor;
|
|
|
|
|
$this->helpers = $helpers;
|
|
|
|
|
}
|
2023-10-12 20:59:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public function deleteVendor(Request $request){
|
|
|
|
|
|
|
|
|
|
$data = $request->all();
|
|
|
|
|
|
|
|
|
|
$currentUser = \JWTAuth::parseToken()->authenticate();
|
|
|
|
|
|
|
|
|
|
$vendor = Vendor::where("id", $currentUser->id)->delete();
|
|
|
|
|
|
|
|
|
|
if($vendor){
|
|
|
|
|
return response()->json(["message"=>"deleted"], 200);
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
return $this->helpers->apiArrayResponseBuilder(400, 'fail');
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-01 12:27:33 +00:00
|
|
|
|
|
|
|
|
public function updateVendor(Request $request){
|
|
|
|
|
|
|
|
|
|
$data = $request->all();
|
|
|
|
|
|
|
|
|
|
$validator = Validator::make($data, [
|
|
|
|
|
'shop_title' => 'required',
|
|
|
|
|
'slogan' => 'required',
|
|
|
|
|
'work_time' => 'required',
|
|
|
|
|
'description' => 'required',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $validator = $this->validateForm($data, $rules);
|
|
|
|
|
if($validator->fails()) {
|
|
|
|
|
return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validator->errors() );
|
|
|
|
|
}
|
|
|
|
|
//dd($data);
|
|
|
|
|
$currentUser = \JWTAuth::parseToken()->authenticate();
|
2023-11-09 10:04:25 +00:00
|
|
|
$vendor = Vendor::where("id", $currentUser->id)->with(['categories' => function($q){
|
|
|
|
|
$q->with('translations:locale,model_id,attribute_data');
|
|
|
|
|
}])
|
|
|
|
|
->with('sliders')->first();
|
2023-08-01 12:27:33 +00:00
|
|
|
|
|
|
|
|
//dd($vendor->type);
|
|
|
|
|
|
|
|
|
|
if ($vendor->type != "simple"){
|
|
|
|
|
|
|
|
|
|
$vendor->shop_title = $data["shop_title"];
|
|
|
|
|
$vendor->slogan = $data["slogan"];
|
|
|
|
|
$vendor->work_time = $data["work_time"];
|
|
|
|
|
$vendor->description = $data["description"];
|
2023-11-09 10:04:25 +00:00
|
|
|
$vendor->short_description = $data["short_description"] ?? "";
|
|
|
|
|
$vendor->web2 = (int) $data["discount"];
|
|
|
|
|
$vendor->tiktok = $data["tiktok"];
|
|
|
|
|
$vendor->instagram = $data["instagram"];
|
|
|
|
|
$vendor->site = $data["site"];
|
2023-08-01 12:27:33 +00:00
|
|
|
$vendor->save();
|
|
|
|
|
|
2023-11-09 10:04:25 +00:00
|
|
|
$vendor->pathUrl = 'https://gurlushyk.com.tm' . \Config::get('cms.storage.media.path');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$all = array(
|
|
|
|
|
"id" => 0,
|
|
|
|
|
"name"=> "Hemmesi",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$vendor->categories->prepend($all);
|
|
|
|
|
|
|
|
|
|
return response()->json($vendor, 200);
|
2023-08-01 12:27:33 +00:00
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
return $this->helpers->apiArrayResponseBuilder(400, 'fail');
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2023-08-03 16:21:42 +00:00
|
|
|
|
2023-08-01 12:27:33 +00:00
|
|
|
|
|
|
|
|
public static function getAfterFilters() {return [];}
|
|
|
|
|
public static function getBeforeFilters() {return [];}
|
|
|
|
|
public static function getMiddleware() {return [];}
|
|
|
|
|
public function callAction($method, $parameters=false) {
|
|
|
|
|
return call_user_func_array(array($this, $method), $parameters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|