Customers.php
3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Contacts;
use App\Models\ContactStatus;
class Customers extends Model
{
protected $table = 'customers';
protected $fillable = array('id','group_id','unique_id','created_at','peopledata','currentstatus','legalstatus','firstname');
public function createNewEntry()
{
$customers = Customers::create();
return $customers->id;
}
public function checkRecordIfExist($customersId)
{
$customers = Customers::find($customersId);
return $customers->id;
}
public function updateExistingRecord($customersId, $peopledataArr)
{
$peopledataArr['peopledata']['id']=$customersId;
$ppldataSerialize = serialize($peopledataArr['peopledata']);
$customers = Customers::where('id', '=', $customersId)
->update(['peopledata'=>$ppldataSerialize,
'unique_id'=>$peopledataArr['peopledata']['unique_id'],
'group_id'=>$peopledataArr['peopledata']['group_id'],
'currentstatus'=>$peopledataArr['peopledata']['currentstatus'],
'legalstatus'=>$peopledataArr['peopledata']['legalstatus'],
'firstname'=>$peopledataArr['peopledata']['firstname']
]
);
$contacts = new Contacts();
$contacts->createNewEntryOfCustomer($customersId, $peopledataArr);
return $customers;
}
public function getReportdata($crm_id)
{
$customers = Customers::select('unique_id','id','currentstatus','legalstatus')
->whereIn('id',$crm_id)
->get();
return $customers;
}
public function searchCustomerData($searchKey,$campaign)
{
$customers = Customers::join('contacts as ct', 'customers.id', '=', 'ct.customer_id')
->where('ct.client','=',$campaign)
->where(function ($query) use ($searchKey){
$query->orWhere('customers.firstname', 'like', '%'.$searchKey.'%')
->orWhere('customers.unique_id', 'like','%'. $searchKey.'%')
->orWhere('customers.group_id', 'like', '%'.$searchKey.'%')
->orWhere('ct.mobile', 'like', '%'.$searchKey.'%');
})
->select('*')
->get()
->toArray();
return $customers;
}
public function getPersonIDs($key, $val)
{
$customers = Customers::whereIn($key, $val)
->select('id')
->get()
->toArray();
return $customers;
}
public function getPpldataOfCustomer($varid)
{
$customers = Customers::where('id',$varid)
->select('peopledata')
->first()
->toArray();
return $customers;
}
}