-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_element.php
More file actions
81 lines (68 loc) · 2.25 KB
/
add_element.php
File metadata and controls
81 lines (68 loc) · 2.25 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
<?php
require_once "cUrls.php";
$number = $_GET["name5"];
function funcEntity($number,$element,$arr)
{
$arr_common = [];
$data['add'] = [];
for ($i = 1; $i <= $number; $i++) {
if ($element == 'leads') {
$masEmptity = [
'name' => 'Сделка' . $i,
'contacts_id' => $arr[$i - 1]
];
} else if ($element == 'companies') {
$masEmptity = [
'name' => 'Компания' . $i
];
}
if ($element == 'contacts') {
$masEmptity = [
'name' => 'Контакт' . $i,
'company_id' => $arr[$i - 1]
];
} else if ($element == 'customers') {
$masEmptity = [
'name' => 'Покупатель' . $i,
'next_date' => '1542980340',
'contacts_id' => $arr[$i - 1]
];
}
array_push($data['add'], $masEmptity);
if ($i % 250 == 0 or $i % $number == 0) {
$arrIdEmptity = funcSend($data, $element);
$arr_common = array_merge($arr_common, $arrIdEmptity);
$data['add'] = [];
};
};
return $arr_common;
}
function funcSend($data,$method)
{
global $user;
var_dump($user);
$link = "https://apahe.amocrm.ru/api/v2/".$method.'?'.http_build_query($user);;
$headers[] = "Accept: application/json";
//Curl options
$curl = curl_init($link);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_USERAGENT, "amoCRM-API-client-
undefined/2.0");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_HEADER,false);
$out = curl_exec($curl);
curl_close($curl);
var_dump($out);
$result = json_decode($out, TRUE);
for ($i=0;$i<count($data['add']);$i++) {
$result2[$i]=$result['_embedded']['items'][$i]['id'];
};
return $result2;
};
set_time_limit(300);
$arrCompany=funcEntity($number,'companies',[2]);
$arrContacts=funcEntity($number,'contacts',$arrCompany);
$arrCustomers=funcEntity($number,'customers',$arrContacts);
$arrLeads=funcEntity($number,'leads',$arrContacts);
header('Location:elements.php');