Advertisement
Axxxxxx

class.php

Jun 30th, 2021
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.76 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Работа с вебформами для внешних сервисов (1с и т.п.)
  4.  *
  5.  * 1. этап: получение данных и отдача json. Статус: завершен.
  6.  */
  7. class ApiWebForms
  8. {
  9.     public function __construct($data)
  10.     {
  11.         $args = [
  12.             'type' => FILTER_SANITIZE_STRING,
  13.             'form_id' => FILTER_VALIDATE_INT,
  14.             'limit' => FILTER_VALIDATE_INT,
  15.             'from' => FILTER_SANITIZE_STRING,
  16.             'to' => FILTER_SANITIZE_STRING,
  17.             'id' => FILTER_VALIDATE_INT,
  18.             'debug' => FILTER_VALIDATE_INT,
  19.         ];
  20.         $_POST = $data;
  21.         $this->inputs = filter_input_array(INPUT_POST, $args);
  22.  
  23.         self::typeRequest();
  24.     }
  25.  
  26.     private function typeRequest()
  27.     {
  28.         $type = $this->inputs['type'];
  29.         switch ($type) {
  30.             case 'get':
  31.                 $result = self::getForm();
  32.                 echo $result;
  33.  
  34.             break;
  35.             // case 'set':
  36.             //     break;
  37.  
  38.             default:
  39.             break;
  40.         }
  41.     }
  42.  
  43.     /**
  44.      * Получение данных вебформ
  45.      *
  46.      * @return json
  47.      */
  48.     private function getForm()
  49.     {
  50.         $from = $this->inputs['from'] ? ['TIMESTAMP_1' => $this->inputs['from']] : [];
  51.         $to = $this->inputs['to'] ? ['TIMESTAMP_2' => $this->inputs['to']] : [];
  52.         $id = $this->inputs['id'] ? ['ID' => $this->inputs['id']] : [];
  53.         $arFilter = array_merge($from, $to, $id);
  54.         $limit = $this->inputs['limit'] ?? 1;
  55.         // d($arFilter);die;
  56.  
  57.         $rsResults = CFormResult::GetList(
  58.             $this->inputs['form_id'],
  59.             ($by = 's_timestamp'),
  60.             ($order = 'desc'),
  61.             $arFilter,
  62.             $is_filtered,
  63.             'N',
  64.             $limit
  65.         );
  66.  
  67.         while ($ar = $rsResults->Fetch()) {
  68.             $arAnswer = CFormResult::GetDataByID(
  69.                 $ar['ID'],
  70.                 [],
  71.                 $arResult,
  72.                 $arAnswer2
  73.             );
  74.             $arAnswer['FORM_DATA'] = $arResult;
  75.             // $attach = ['FILE', 'SIMPLE_FILE', 'SIMPLE_FILE_2'];
  76.             // если прикрепили изображение
  77.             if ($arAnswer['FILE']) {
  78.                 foreach ($arAnswer['FILE'] as $k => $v) {
  79.                     $file_url = CFile::GetPath($v['USER_FILE_ID']);
  80.                     $arAnswer['FILE'][$k]['URL'] = $file_url;
  81.                 }
  82.             }
  83.  
  84.             if ($arResult['USER_AUTH'] == 'Y' && $arResult['USER_ID']) {
  85.                 $filter = ['ID' => $arResult['USER_ID']];
  86.                 $rsUser = CUser::GetList(
  87.                     ($by = 'date_register'),
  88.                     ($order = 'desc'),
  89.                     $filter,
  90.                     ['SELECT' => ['UF_*']]
  91.                 );
  92.                 $arUser = $rsUser->Fetch();
  93.                 unset($arUser['PASSWORD'],$arUser['CHECKWORD']);
  94.                 $arAnswer['USER_DATA'] = $arUser;
  95.                 // получаем профили покупателя по ID юзера
  96.                 $profile = Bitrix\Sale\Helpers\Admin\Blocks\OrderBuyer::getBuyerProfilesList($arUser['ID']);
  97.                 $profile_ids = array_keys($profile);
  98.                 $profile_ids = array_filter($profile_ids);
  99.  
  100.                 foreach ($profile_ids as $_profile_id) {
  101.                     $inn_with_code1c = [];
  102.                     $db_propVals = CSaleOrderUserPropsValue::GetList(
  103.                         [],
  104.                         ['USER_PROPS_ID' => $_profile_id],
  105.                         false,
  106.                         false,
  107.                         ['NAME', 'PROP_CODE', 'VALUE']
  108.                     );
  109.                     while ($arPropVals = $db_propVals->Fetch()) {
  110.                         if ($arPropVals['PROP_CODE'] == 'INN') {
  111.                             $inn_with_code1c['INN'] = $arPropVals['VALUE'];
  112.                         }
  113.                         if ($arPropVals['PROP_CODE'] == 'CODE_1C') {
  114.                             $inn_with_code1c['CODE'] = $arPropVals['VALUE'];
  115.                         }
  116.                     }
  117.                     $arAnswer['INN_WITH_CODE1C'][] = $inn_with_code1c;
  118.                 }
  119.             }
  120.             $result[] = $arAnswer;
  121.         }
  122.  
  123.         if ($this->inputs['debug'] == 1) {
  124.             d($this->inputs, $result);
  125.         } else {
  126.             $json = json_encode($result, JSON_UNESCAPED_UNICODE);
  127.  
  128.             return $json;
  129.         }
  130.     }
  131.  
  132.     /**
  133.      * Создание записи в вебформе
  134.      */
  135.     private function setForm()
  136.     {
  137.     }
  138.  
  139.     /**
  140.      * Обновление записи в вебформе
  141.      */
  142.     private function updateForm()
  143.     {
  144.     }
  145. }
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement