71 lines
No EOL
2.2 KiB
PHP
71 lines
No EOL
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use Request;
|
|
use Validator;
|
|
use App\Models\Lead;
|
|
use App\Models\Customer;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
class LeadController extends Controller
|
|
{
|
|
public $successStatus = 200;
|
|
public $errorStatus = 500;
|
|
public $data = "";
|
|
public $room_str = "";
|
|
public $room_name = "";
|
|
public $className = "";
|
|
public $option = "";
|
|
|
|
public function action($action)
|
|
{
|
|
|
|
if ($action == "create_lead") {
|
|
$data = Request::all();
|
|
|
|
if(!isset($data['lead']) && !is_array($data['lead'])) {
|
|
return response()->json(['error' => 'lead not exist, but need'], $this->errorStatus);
|
|
}
|
|
if(!isset($data['lead']['customerForm'])){
|
|
return response()->json(['error' => 'lead customerForm not exist, but need'], $this->errorStatus);
|
|
}
|
|
|
|
//customer
|
|
/* $rules = array(
|
|
'name' => 'required',
|
|
'email' => 'requird'
|
|
|
|
);
|
|
$validator = Validator::make($data['lead']['customerForm'], $rules);
|
|
if ($validator->fails()) {
|
|
return response()->json($validator->messages(), $this->errorStatus);
|
|
|
|
}
|
|
|
|
//lead
|
|
$rules = array(
|
|
'sf_guard_user_id' => 'required',
|
|
'status_id' => 'requird',
|
|
'request_date' => 'requird'
|
|
);
|
|
$validator = Validator::make($data['lead'], $rules);
|
|
if ($validator->fails()) {
|
|
return response()->json($validator->messages(), $this->errorStatus);
|
|
|
|
}*/
|
|
|
|
$customer = Customer::create($data['lead']['customerForm']);
|
|
unset($data['lead']['customerForm']);
|
|
$data['lead']['customer_id'] = $customer->id;
|
|
$lead = Lead::create($data['lead']);
|
|
$ret= [
|
|
'url_v1' => make_old_url('/index.php/leads/'.$lead->id.'/edit'),
|
|
'url_v3' => route('lead_detail', $lead->id),
|
|
'lead_id' => $lead->id
|
|
];
|
|
|
|
return response()->json(['success' => $ret], $this->successStatus);
|
|
}
|
|
}
|
|
} |