Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
deal.php
1<?php
3
4
8
9class Deal extends Proxy
10{
11 public function init($params)
12 {
13 foreach($params as $index=>$item)
14 {
15 $entity = Integration\Service\Internal\Entity\Factory::create($this->getDstEntityTypeId());
16
17 $entity->setTitle($item['TITLE']);
18 $entity->setOriginId($index);
19 $entity->setOriginatorId(static::ANALITICS_ORIGINATOR_ID);
20 $entity->setOpportunity($item['PRICE']);
21 $entity->setCurrency($item['CURRENCY']);
22
23 if($item['COMPANY_ID'])
24 {
25 $entity->setCompanyId($item['COMPANY_ID']);
26 }
27 if($item['CONTACT_ID'])
28 {
29 $entity->setContactId($item['CONTACT_ID']) ;
30 }
31
32 $this->collection->addItem(
33 Integration\Service\Internal\Container\Item::create($entity)
34 ->setInternalIndex($index)
35 );
36 }
37 return $this;
38 }
39
40 static public function contactItemsGet($id)
41 {
42 $proxy = static::getProxy();
43 $r = $proxy->contactItemsGet($id);
44
45 if($r->isSuccess())
46 {
47 $result = $r->getData()['DATA']['result'];
48 }
49 else
50 {
51 throw new Exception\BatchableException(implode(',', $r->getErrorMessages()));
52 }
53
54 return $result;
55 }
56 static public function dealContactUpdates($id, $params, $contacts)
57 {
58 $result = [];
59 $indexes = self::getIndexesFromParams($params);
60 $contacts = static::getIndexesContactFromParams($contacts);
61
62 $relations = static::clientRelation($indexes, BusinessValuePersonDomainType::TYPE_I_NAME);
63
64 $contactIds = [];
66 foreach ($relations as $relation)
67 {
68 $contactIds[] = $relation->getDestinationEntityId();
69 }
70
71 if(count(array_diff($contactIds, $contacts))>0)
72 {
73 $proxy = static::getProxy();
74 $r = $proxy->contactItemsSet($id, static::getContactItemsFromIndexes(array_merge($contactIds, $contacts)));
75 if($r->isSuccess())
76 {
77 $result = $r->getData()['DATA']['result'];
78 }
79 else
80 {
81 throw new Exception\BatchableException(implode(',', $r->getErrorMessages()));
82 }
83 }
84 return $result;
85 }
86 static public function dealContactAdds($id, $params)
87 {
88 $result = [];
89 $indexes = self::getIndexesFromParams($params);
90
91 $relations = static::clientRelation($indexes, BusinessValuePersonDomainType::TYPE_I_NAME);
92
93 $contactIds = [];
95 foreach ($relations as $relation)
96 {
97 $contactIds[] = $relation->getDestinationEntityId();
98 }
99
100 if(count($contactIds)>0)
101 {
102 $proxy = static::getProxy();
103 $r = $proxy->contactItemsSet($id, static::getContactItemsFromIndexes($contactIds));
104 if($r->isSuccess())
105 {
106 $result = $r->getData()['DATA']['result'];
107 }
108 else
109 {
110 throw new Exception\BatchableException(implode(',', $r->getErrorMessages()));
111 }
112 }
113 return $result;
114 }
115
116 public function getSrcEntityTypeId()
117 {
118 return Integration\EntityType::ORDER;
119 }
120 public function getDstEntityTypeId()
121 {
122 return Integration\CRM\EntityType::DEAL;
123 }
124
125 static protected function getProxy()
126 {
128 }
129}