CustomerNumbers.php
2.7 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
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Customers;
use App\Models\Contacts;
use DB;
class CustomerNumbers extends Model
{
protected $table = 'customer_numbers';
public function getRecordOfAltNumber($campaignArr, $number)
{
$numAvailInCustNumbers = array();
$numAvailInCustNumbers = Contacts::join('customers as cs', 'cs.id', '=', 'contacts.customer_id')
->join('customer_numbers as cn', 'cn.customer_id' ,'=', 'cs.id')
->whereIn('contacts.client', $campaignArr)
->where('cn.number', '=', $number)
->select('cs.peopledata')
->get()
->toArray();
return $numAvailInCustNumbers;
}
public function searchPhone($mobile){
$mobile10=substr($mobile,-10);
$inb_cust_data = array();
/*$inb_cust_data = Contacts::join('customerss as cs', 'cs.id', '=', 'contacts.customer_id')
->join('customer_numbers as cn', 'cn.customer_id' ,'=', 'cs.id')
->where('Right(cn.number,10)', '=', $mobile10)
->select('cs.peopledata')
->get()
->toArray();*/
$inb_cust_data = DB::select(DB::raw("select * from contacts as ct join customers as cs on cs.id = ct.customer_id join customer_numbers as cn on cn.customer_id=cs.id where RIGHT(cn.number,10)=$mobile10 limit 1;"));
if(empty($inb_cust_data)){
DB::select(DB::raw("select * from contacts as ct join customers as cs on cs.id = ct.customer_id where RIGHT(ct.mobile,10)=$mobile10 limit 1;"));
}
return $inb_cust_data;
}
public function addAltNumber($customerId, $ppldataSerialize, $altnumberArr)
{
$customers = Customers::where('id', '=', $customerId)
->update(['peopledata'=>$ppldataSerialize]);
$customernumbers = new CustomerNumbers();
$customernumbers->customer_id = $customerId;
$customernumbers->number = $altnumberArr[0];
$customernumbers->type = $altnumberArr[1];
$customernumbers->save();
return $customers;
}
public function delAltNumber($customerId, $ppldataSerialize, $altnumber)
{
$customers = Customers::where('id', '=', $customerId)
->update(['peopledata'=>$ppldataSerialize]);
$customernumbers = CustomerNumbers::where('number', '=', $altnumber)->delete();
return $customers;
}
}