-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathhourly_reserves_docgen.php
169 lines (129 loc) · 5.63 KB
/
hourly_reserves_docgen.php
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* @deprecated Ïîêà íå èñïîëüçóåòñÿ
*/
exit;
/*
* Çàïóñêàòü êàæäûå 30 ìèíóò
* [0,30 * * * *]
*
*
* Êðîí îáíàðóæåíèÿ è ãåíåðàöèè íåäîñòîþùèé äîêóìåíòîâ
* ïî çàêðûòûì ðåçåðâàì çàêàçîâ (ÁÑ).
*
* Ýòî âðåìåííîå ðåøåíèå îò ïðîáëåìû îøèáêè ãåíåðàöèè äîêóìåíòîâ "íà ëåòó"
* Ïîêà ãåíåðàöèÿ íåáóäåò ïåðåíåñåíà â î÷åðåäü îáðàáîòêè
*/
//ini_set('display_errors',1);
//error_reporting(E_ALL ^ E_NOTICE);
ini_set('max_execution_time', 0);
ini_set('memory_limit', '512M');
if(!isset($_SERVER['DOCUMENT_ROOT']) || !strlen($_SERVER['DOCUMENT_ROOT']))
{
//@todo: óêàæèòå âìåñòî '' îòíîñèòåëüíîå ïîëîæåíèå doc_root íàïðèìåð '/../'
$_SERVER['DOCUMENT_ROOT'] = rtrim(realpath(dirname(__FILE__) . ''), '/');
}
//require_once($_SERVER['DOCUMENT_ROOT'] . "/classes/config.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/classes/stdf.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/classes/log.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/classes/multi_log.php");
require_once($_SERVER['DOCUMENT_ROOT'] . '/tu/models/TServiceOrderModel.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/classes/tservices/tservices_order_history.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/classes/DocGen/DocGenReserves.php');
//------------------------------------------------------------------------------
function getFileUrl($file)
{
if(!$file) return 0;
return WDCPREFIX . '/'.$file->path . $file->name;
}
//------------------------------------------------------------------------------
$log = new log('hourly_reserves_docgen/'.SERVER.'-%d%m%Y.log', 'a', '[%d.%m.%Y %H:%M:%S] ');
//------------------------------------------------------------------------------
//óñïåøíûå ñäåëêè
$rows = $DB->rows("
SELECT
fro.src_id,
array_agg(fro.doc_type)::int[] AS doc_types
FROM file_reserves_order AS fro
INNER JOIN reserves AS r ON r.src_id = fro.src_id
WHERE
r.status IN(20,30)
GROUP BY fro.src_id
HAVING
array_agg(fro.doc_type)::int[] @> ARRAY[10,20,30,40,50,60] = false AND
array_agg(fro.doc_type)::int[] @> ARRAY[10,20,30,40,50,60,70] = false AND
array_agg(fro.doc_type)::int[] @> ARRAY[20,30,40,50,60,70] = false
LIMIT 10;
");
if ($rows) {
$log->writeln(sprintf("BEGIN hourly for %s reserves",count($rows)));
$cnt = 0;
foreach ($rows AS $row) {
$order_id = $row['src_id'];
$doc_types = $DB->array_to_php2($row['doc_types']);
$log->writeln(sprintf("Order Id = %s", $order_id));
try
{
$orderModel = TServiceOrderModel::model();
$orderModel->attributes(array('is_adm' => true));
$orderData = $orderModel->getCard($order_id, 0);
if(!$orderData ||
!$orderModel->isStatusEmpClose() ||
!$orderModel->isReserve()) {
$log->writeln('Not isStatusEmpClose');
continue;
}
$reserveInstance = $orderModel->getReserve();
if(!$reserveInstance->isClosed()) {
$log->writeln('Not isClosed');
continue;
}
$doc_types = array_unique($doc_types);
$base_doc_types = array(10,20,30,40,50,60);
if ($reserveInstance->isArbitrage()) {
$base_doc_types = $reserveInstance->isStatusPayPayed()?
array(10,20,30,40,50,60,70):
array(20,30,40,50,60,70);
}
$doc_types = array_diff($base_doc_types, $doc_types);
$history = new tservices_order_history($order_id);
$doc = new DocGenReserves($orderData);
foreach ($doc_types as $doc_type) {
switch ($doc_type) {
case DocGenReserves::ACT_COMPLETED_FRL_TYPE:
$file_url = getFileUrl($doc->generateActCompletedFrl());
$log->writeln(sprintf("generateActCompletedFrl = %s", $file_url));
break;
case DocGenReserves::ACT_SERVICE_EMP_TYPE:
$file_url = getFileUrl($doc->generateActServiceEmp());
$log->writeln(sprintf("generateActServiceEmp = %s", $file_url));
break;
case DocGenReserves::AGENT_REPORT_TYPE:
$file_url = getFileUrl($doc->generateAgentReport());
$log->writeln(sprintf("generateAgentReport = %s", $file_url));
break;
case DocGenReserves::RESERVE_OFFER_CONTRACT_TYPE:
//case DocGenReserves::RESERVE_OFFER_AGREEMENT_TYPE:
$file_url = (int)$doc->generateOffers();
$log->writeln(sprintf("generateOffers = %s", $file_url));
break;
case DocGenReserves::LETTER_FRL_TYPE:
$file_url = getFileUrl($doc->generateInformLetterFRL());
$log->writeln(sprintf("generateInformLetterFRL = %s", $file_url));
break;
case DocGenReserves::ARBITRAGE_REPORT_TYPE:
$file_url = getFileUrl($doc->generateArbitrageReport());
$log->writeln(sprintf("generateArbitrageReport = %s", $file_url));
break;
}
}
$cnt++;
}
catch (\Exception $e)
{
$message = $e->getMessage();
$log->writeln(sprintf("Error Message: %s", iconv('cp1251', 'utf-8', $message)));
}
}
$log->writeln(sprintf("END hourly. Well done %s reserves", $cnt) . PHP_EOL);
}