'DB data field' return array( 'woid'=> 'woid', 'api_id' => 'api_id', //'externalId'=> 'object_id', // внешний ID при запросе информации //'orderId'=> 'object_id', // внешний ID при создании заказа 'object_id'=> 'object_id', // ID объекта при загрузке из базы 'id'=> 'order_id', // возникает после отправки заказа 'order_id'=> 'order_id', 'number'=> 'number', // нет на форме 'state'=> 'state', // нет на форме 'serviceType'=> 'serviceType', 'objectType'=> 'objectType', 'reportUsageType'=> 'reportUsageType', 'preliminaryCalculationValue'=> 'preliminaryCalculationValue', // нет на форме 'address' => 'address', 'customerName' => 'customerName', 'customerPhone'=> 'customerPhone', // нет в информации 'customerEmail' => 'customerEmail', // нет в информации 'сontactName' => 'сontactName', // ФИО контактного лица 'сontactPhone' => 'сontactPhone', // Номер телефона контактного лица 'сontactEmail' => 'сontactEmail', // Email контактного лица 'bankId' => 'bankId', // нет в информации 'bankManagerName'=> 'bankManagerName', // нет в информации 'bankManagerEmail'=> 'bankManagerEmail', // нет в информации 'managerComment'=> 'managerComment', // нет в информации 'managerEmail'=> 'managerEmail', // нет в информации //'appraisalCompanyId'=> 'appraisalCompanyId', 'contractCost'=> 'contractCost', // нет в информации 'calculationId'=> 'calculationId', // нет в информации 'requestDate' => 'requestDate', // нет на форме 'payed' => 'payed', // нет на форме 'reportPrinted' => 'reportPrinted', // нет на форме 'reportReady' => 'reportReady', 'deliveryRequired' => 'deliveryRequired', 'deliveryAddress' => 'deliveryAddress', 'documentsChecked' => 'documentsChecked', 'inspectionRequired' => 'inspectionRequired', 'inspectionConfirmed' => 'inspectionConfirmed', 'inspectionDate' => 'inspectionDate', 'inspectionContactName' => 'inspectionContactName', 'inspectionContactPhone' => 'inspectionContactPhone', 'inspected'=> 'inspected', 'appraisalManagerName'=> 'appraisalManagerName', 'updateDate'=> 'updateDate', ); } public function __construct(array $fields) { if(isset($fields["woid"])) { $this->woid = $fields["woid"]; } else { $this->woid = 0; } if(isset($fields['object_id'])) { $match = WebAppRaiserDB::matchFieldsToSave($fields, self::valid_fields(), 'woid'); $this->order = $match['fields_to_save']; } //TODO сделать дополнительные запросы цены и картинок } public static function load($object_id, WebAppRaiserAPI $api) { $ordersData = array(); $orders = WebAppRaiserDB::select('war_objects', 'object_id', $object_id); //msg('ORDERS', $orders); $check_point = time() - (5*60); // не чаще одного запроса в 5 минут foreach ($orders as $order) { if($order['api_id'] == $api->get('war_id')){ // Загружаем заказы только если подключено правильное API if($order['updateDate'] < $check_point){ $api->getOrder($order); $fields = WebAppRaiserDB::select('war_objects', 'woid', $order['woid']); $ordersData[$order['woid']] = new WebAppRaiserOrder($fields[0]); } else { $ordersData[$order['woid']] = new WebAppRaiserOrder($order); } } } return $ordersData; } public static function create(array $fields) { //$valid_fields = self::valid_fields(); //$match = WebAppRaiserDB::matchFieldsToSave($fields, $valid_fields, 'woid'); $order = new WebAppRaiserOrder($fields); return $order; } public static function save($fields) { $valid_fields = self::valid_fields(); $woid = WebAppRaiserDB::save('war_objects', $fields, $valid_fields, 'woid'); return $woid; } public static function delete($order_id) { return WebAppRaiserDB::delete('war_objects', 'order_id', $order_id); /*if(isset($this->order['woid'])) { return WebAppRaiserDB::delete('war_objects', 'woid', $this->order['woid']); } elseif(isset($this->order['order_id'])) { return WebAppRaiserDB::delete('war_objects', 'order_id', $this->order['order_id']); } else { return false; } // */ } // Отображение заказа на главной странице заказов. public function render() { $order = $this->order; $header = '

%s

'; $button = function($title, $url, $style = '') { return ''.$title.''; }; $button2 = function($text, $title, $url, $style = '') { return '
'.$text.'
'.PHP_EOL; }; $button3 = function($text, $title, $url, $style = '') { return ''.$text.''.PHP_EOL; }; $view_field = function($field) use($order) {return $this->viewField($field, $order[$field]);}; $html_field = function($title, $field) use($view_field) { $html = '
'.$title.'
'.PHP_EOL; $html .= '
'.$view_field($field).'
'.PHP_EOL; $html .= '
'.PHP_EOL; return $html; }; $output = '
'.sprintf($header, 'Заказ / '.$this->viewField('number', $order['number'].' ['.$order['order_id'].']')).'
'.PHP_EOL; // Сведения о заказе $output .= '
'.PHP_EOL; $output .= '
'.PHP_EOL; $output .= $html_field('Тип заказа', 'serviceType'); $output .= $html_field('Объект оценки', 'objectType'); $output .= $html_field('Цель оценки', 'reportUsageType'); $output .= $html_field('Адрес объекта', 'address'); $output .= $html_field('Банк', 'bankId'); $output .= '
'.PHP_EOL; $output .= '
'.PHP_EOL; $output .= $html_field('Стоимость в договоре', 'contractCost'); $output .= $html_field('Email менеджера', 'managerEmail'); $output .= $html_field('Комментарий менеджера', 'managerComment'); $output .= '
'.PHP_EOL; $output .= '
'.PHP_EOL; $output .= $html_field('Номер', 'number'); $output .= $html_field('Дата', 'requestDate'); $output .= $html_field('Статус', 'state'); $output .= $html_field('Документы проверены', 'documentsChecked'); $output .= $html_field('Оплата', 'payed'); $output .= $html_field('Отчет готов', 'reportReady'); $output .= $html_field('Отчет распечатан', 'reportPrinted'); $output .= '
'.PHP_EOL; $output .= '
'.PHP_EOL; if($order['serviceType'] == 'CALCULATION'){ $output .= $html_field('Стоимость, полученная в результате расчета', 'preliminaryCalculationValue'); } $output .= $html_field('ФИО менеджера оценочной компании', 'appraisalManagerName'); $output .= '
'.PHP_EOL; $output .= '
'.PHP_EOL; // Сведения о заказчике / заемщике $output .= '
'.PHP_EOL; $output .= '
'.PHP_EOL; $output .= sprintf($header, 'Заказчик / заемщик').PHP_EOL; $output .= $html_field('ФИО клиента', 'customerName'); $output .= $html_field('Контактный телефон клиента', 'customerPhone'); $output .= $html_field('Email клиента', 'customerEmail'); $output .= '
'.PHP_EOL; // Менеджер банка $output .= '
'.PHP_EOL; $output .= sprintf($header, 'Менеджер банка').PHP_EOL; $output .= $html_field('ФИО менеджера банка', 'bankManagerName'); $output .= $html_field('Email менеджера банка', 'bankManagerEmail'); $output .= '
'.PHP_EOL; $output .= '
'.PHP_EOL; // Осмотр $output .= '
'.PHP_EOL; $output .= '
'.PHP_EOL; $output .= sprintf($header, 'Осмотр').PHP_EOL; $output .= $html_field('Требуется осмотр', 'inspectionRequired'); $output .= $html_field('Осмотр согласован', 'inspectionConfirmed'); $output .= $html_field('Дата осмотра', 'inspectionDate'); $output .= $html_field('ФИО, ответственного за осмотр', 'inspectionContactName'); $output .= $html_field('Контактный телефон, ответственного за осмотр', 'inspectionContactPhone'); $output .= $html_field('Осмотр проведен', 'inspected'); $output .= '
'.PHP_EOL; // Доставка $output .= '
'.PHP_EOL; $output .= sprintf($header, 'Доставка').PHP_EOL; $output .= $html_field('Требуется доставка', 'deliveryRequired'); if($order['deliveryRequired']){ $output .= $html_field('Адрес доставки', 'deliveryAddress'); $output .= $html_field('Контактное лицо', 'deliveryContactName'); $output .= $html_field('Номер телефона контакта', 'deliveryContactPhone'); } $output .= '
'.PHP_EOL; $output .= '
'.PHP_EOL; // Ответственный агент $output .= '
'.PHP_EOL; $output .= '
'.PHP_EOL; $output .= sprintf($header, 'Ответственный агент').PHP_EOL; $output .= $html_field('ФИО контактного лица', 'сontactName'); $output .= $html_field('Номер телефона контактного лица', 'сontactPhone'); $output .= $html_field('Email контактного лица', 'сontactEmail'); $output .= '
'.PHP_EOL; $output .= '
'.PHP_EOL; // Статус заказа, документы, оплата, осмотр, отчет $output .= '
'.sprintf($header, 'Операции с заказом').'
'.PHP_EOL; $output .= $button3('Документы', 'Отправить документы', '/war-object-report.php?op=order_docs&id='.$order['object_id'].'&order_id='.$order['order_id'], 'color: #237ef7 !important; border-color: #3a8efa !important;').'   '.PHP_EOL; $output .= $button3('Сообщения', 'Отправить сообщение', '/war-object-report.php?op=msg_list&id='.$order['object_id'].'&order_id='.$order['order_id'], '').'   '.PHP_EOL; if($order['reportReady']){ $output .= $button3('Отчет', 'Скачать отчет', '/war-object-report.php?op=order_report&id='.$order['object_id'].'&order_id='.$order['order_id'], 'color: #4CAF50; border-color: rgb(67, 160, 71);').'   '.PHP_EOL; } if($order['state'] == 'SENT') { // $output .= $button3('Удалить', 'Удалить заказ', '/war-object-report.php?op=order_del&id='.$order['object_id'].'&order_id='.$order['order_id'], 'background: rgba(226, 87, 76, .85); border-color: rgba(148, 54, 41, .37) !important; color: #ffffff !important;float: right !important;').'   '.PHP_EOL; } //$output .= '"'.$order['state'].'"'; $output .= '
 
'.PHP_EOL; return $output; } public function viewField($field_name, $field_value) { switch($field_name) { case 'state': $colors = WebAppRaiserAPI::getDict('ORDER_STATE_COLOR'); if(empty($field_value)) { return 'Не определен'; } else { $state_text = WebAppRaiserAPI::getDict('ORDER_STATE', $field_value); return ''.$state_text.''; } break; case 'number': if(empty($field_value)) { return 'Новый'; } else { return $field_value; } break; case 'type': case 'messageType': return WebAppRaiserAPI::getDict('MESSAGE_TYPE', $field_value); break; case 'serviceType': return WebAppRaiserAPI::getDict('APPRAISAL_SERVICE_TYPE', $field_value); break; case 'objectType': return WebAppRaiserAPI::getDict('OBJECT_TYPE', $field_value); break; case 'reportUsageType': return WebAppRaiserAPI::getDict('REPORT_USAGE_TYPE', $field_value); break; case 'bankId': global $WebAppRaiserAPI; $banks = $WebAppRaiserAPI->loadBanks(); if(isset($banks[$field_value])) { return $banks[$field_value]; } else { return 'Код банка не найден: '.$field_value; } break; case 'preliminaryCalculationValue': case 'contractCost': return number_format($field_value, 0, ',', ' ') . ' Руб.'; break; case 'requestDate': case 'inspectionDate': case 'updateDate': case 'date': if(is_numeric($field_value) && $field_value > 0) { return date('d.m.Y', $field_value); } elseif(empty($field_value)){ return ''; } else { return $field_value; } break; case 'payed': case 'reportPrinted': case 'reportReady': case 'deliveryRequired': case 'documentsChecked': case 'inspectionRequired': case 'inspectionConfirmed': case 'inspected': if($field_value == 1){ return 'Да'; // зеленый } elseif($field_value == 0) { return 'Нет'; // красный } else { return ''; } break; default: return $field_value; break; } } public static function updateMessages(WebAppRaiserAPI $api) { //todo получить список сообщений $messages = $api->getMessages(); if ($messages['status'] == 'success'){ //msg('messages', $messages); foreach($messages['result'] as $item){ $item_result = $api->getMessage($item['id']); //msg('Item Result', $item_result); if($item_result['status'] == 'success'){ //$api->deleteMessage($item['id']); } } } //todo понять какие сообщения уже есть в базе данных //todo удалить сообщения, которые уже есть //todo загрузить сообщения, которых еще нет в базе //todo как альтернатива - удалять сообщения которые были сохранены } public static function msgTable($object_id, $order_id, $is_chat = true) { //return 'В разработке.'; $output = ''; $records = array(); $operator = ($is_chat)?'=':'<>'; $sql = 'SELECT * FROM war_msg WHERE orderId = '.$order_id.' AND type '.$operator.' "CHAT_MESSAGE" ORDER BY date ASC'; $res = mysql_query($sql); while ($row = mysql_fetch_assoc($res)) { $records[] = $row; } if(empty($records)) { $output .= '

Записей нет.

'; } else { //msg('RECORDS', $records); $output .= '
'.PHP_EOL; $output .= ' '.PHP_EOL; $output .= ' '.PHP_EOL; $output .= ' '.PHP_EOL; if($is_chat){ $output .= ' '.PHP_EOL; $output .= ' '.PHP_EOL; } else { $output .= ' '.PHP_EOL; } $output .= ' '.PHP_EOL; $output .= ' '.PHP_EOL; foreach($records as $record){ if($record['type'] == 'REQUEST_STATE_UPDATED'){ continue; } $fields = unserialize(base64_decode($record['fields'])); //msg('fields', [$record['fields'], $fields]); $text = ''; foreach(['comment', 'value', 'text'] as $key){ if(isset($fields[$key])) $text .= ' '.$fields[$key]; } $output .= ' '.PHP_EOL; $output .= ' '.PHP_EOL; if(isset($fields['sourceType'])){ $output .= ' '.PHP_EOL; $output .= ' '.PHP_EOL; } else { $output .= ' '.PHP_EOL; } if(mb_strlen($text) > 120){ $pre_text = mb_substr($text, 0, 120); $post_text = mb_substr($text, 0); $element_id = 'rec-'.$record['id']; $output .= ' '.PHP_EOL; } else { $output .= ' '.PHP_EOL; } $output .= ' '.PHP_EOL; } $output .= '
ДатаОтправительИмяТип события
'.date('d.m.Y H:i', $record['date']).''.WebAppRaiserAPI::getDict('ACCOUNT_TYPE', $fields['sourceType']).''.$fields['userName'].''.WebAppRaiserAPI::getDict('MESSAGE_TYPE', $record['type']).'
'.$pre_text.'... подробнее
'; $output .= ' '; $output .= '
'.$text.'
'.PHP_EOL; } return $output; } public static function msgTableStatus($object_id, $order_id){ $output = ''; $records = array(); $sql = 'SELECT * FROM war_msg WHERE orderId = ' . $order_id . ' AND type <> "CHAT_MESSAGE_RECEIVED"'; $res = mysql_query($sql); while ($row = mysql_fetch_assoc($res)) { $records[] = $row; } if(empty($records)) { $output .= '

Записей нет.

'; } } public function get($name){ if(isset($this->$name)) { return $this->$name; } else { return false; } } }