1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
discount_convert.php
См. документацию.
1<?
3
5{
6 public static $intConvertPerStep = 0;
7 public static $intNextConvertPerStep = 0;
8 public static $intConverted = 0;
9 public static $intLastConvertID = 0;
10 public static $boolEmptyList = false;
11 public static $intErrors = 0;
12 public static $arErrors = array();
13 public static $strSessID = '';
14
15 public function __construct()
16 {
17
18 }
19
20 public static function InitStep()
21 {
22 if ('' == self::$strSessID)
23 self::$strSessID = 'DC'.time();
24 if (array_key_exists(self::$strSessID, $_SESSION) && is_array($_SESSION[self::$strSessID]))
25 {
26 if (isset($_SESSION[self::$strSessID]['ERRORS_COUNT']) && 0 < intval($_SESSION[self::$strSessID]['ERRORS_COUNT']))
27 self::$intErrors = intval($_SESSION[self::$strSessID]['ERRORS_COUNT']);
28 if (isset($_SESSION[self::$strSessID]['ERRORS']) && is_array($_SESSION[self::$strSessID]['ERRORS']))
29 self::$arErrors = $_SESSION[self::$strSessID]['ERRORS'];
30 }
31 }
32
33 public static function SaveStep()
34 {
35 if ('' == self::$strSessID)
36 self::$strSessID = 'DC'.time();
37 if (!array_key_exists(self::$strSessID, $_SESSION) || !is_array($_SESSION[self::$strSessID]))
38 $_SESSION[self::$strSessID] = array();
39 if (0 < self::$intErrors)
40 {
41 $_SESSION[self::$strSessID]['ERRORS_COUNT'] = self::$intErrors;
42 }
43 if (!empty(self::$arErrors))
44 {
45 $_SESSION[self::$strSessID]['ERRORS'] = self::$arErrors;
46 }
47 }
48
49 public static function GetErrors()
50 {
51 return self::$arErrors;
52 }
53
54 public static function GetCountOld()
55 {
56 global $DB;
57
58 $strSql = "SELECT COUNT(*) CNT FROM b_sale_discount WHERE VERSION=".CSaleDiscount::VERSION_OLD;
59
60 $res = $DB->Query($strSql);
61 if (!$res)
62 return 0;
63
64 if ($row = $res->Fetch())
65 return intval($row['CNT']);
66 }
67
68 public static function GetCount()
69 {
70 global $DB;
71
72 $strSql = "SELECT COUNT(*) CNT FROM b_sale_discount WHERE 1=1";
73
74 $res = $DB->Query($strSql);
75 if (!$res)
76 return 0;
77
78 if ($row = $res->Fetch())
79 return intval($row['CNT']);
80 }
81
82 public static function ConvertDiscount($intStep = 100, $intMaxExecutionTime = 15)
83 {
84 global $DB;
85 global $APPLICATION;
86
88
89 $intStep = intval($intStep);
90 if (0 >= $intStep)
91 $intStep = 100;
92 $startConvertTime = microtime(true);
93
94 $obDiscount = new CSaleDiscount();
95
96 $strTableName = 'b_catalog_discount';
97
99 if (0 == $intCount)
100 {
101
102 }
103 $strStatus = (1 < $intCount ? 'N' : 'Y');
104
105 $arBaseCurrencies = array();
106 $rsSites = CSite::GetList("id", "asc");
107 while ($arSite = $rsSites->Fetch())
108 {
109 $arBaseCurrencies[$arSite['ID']] = CSaleLang::GetLangCurrency($arSite['ID']);
110 }
111 CTimeZone::Disable();
112
113 $rsDiscounts = CSaleDiscount::GetList(
114 array('ID' => 'ASC'),
115 array(
116 'VERSION' => CSaleDiscount::VERSION_OLD,
117 ),
118 false,
119 array('nTopCount' => $intStep),
120 array(
121 'ID', 'SITE_ID', 'MODIFIED_BY', 'TIMESTAMP_X',
122 'PRICE_FROM', 'PRICE_TO', 'CURRENCY',
123 'DISCOUNT_VALUE', 'DISCOUNT_TYPE'
124 )
125 );
126 while ($arDiscount = $rsDiscounts->Fetch())
127 {
128 $arFields = array();
129 $arFields['MODIFIED_BY'] = $arDiscount['MODIFIED_BY'];
130
131 $arConditions = array(
132 'CLASS_ID' => 'CondGroup',
133 'DATA' => array(
134 'All' => 'AND',
135 'True' => 'True',
136 ),
137 'CHILDREN' => array(),
138 );
139 $arActions = array(
140 'CLASS_ID' => 'CondGroup',
141 'DATA' => array(
142 'All' => 'AND',
143 'True' => 'True',
144 ),
145 'CHILDREN' => array(),
146 );
147
148 $boolCurrency = ($arDiscount['CURRENCY'] == $arBaseCurrencies[$arDiscount['SITE_ID']]);
149
150 $strFrom = '';
151 $strTo = '';
152 $strValue = '';
153 $arDiscount['PRICE_FROM'] = doubleval($arDiscount['PRICE_FROM']);
154 $arDiscount['PRICE_TO'] = doubleval($arDiscount['PRICE_TO']);
155 $arDiscount['DISCOUNT_VALUE'] = doubleval($arDiscount['DISCOUNT_VALUE']);
156 if (0 < $arDiscount['PRICE_FROM'])
157 {
158 $dblValue = roundEx(($boolCurrency ? $arDiscount['PRICE_FROM'] : CCurrencyRates::ConvertCurrency($arDiscount['PRICE_FROM'], $arDiscount['CURRENCY'], $arBaseCurrencies[$arDiscount['SITE_ID']])), SALE_VALUE_PRECISION);
159 $arConditions['CHILDREN'][] = array(
160 'CLASS_ID' => 'CondBsktAmtGroup',
161 'DATA' => array(
162 'logic' => 'EqGr',
163 'Value' => (string)$dblValue,
164 'All' => 'AND',
165 ),
166 'CHILDREN' => array(
167 ),
168 );
169 if (!$boolCurrency)
170 {
171 $arFields['PRICE_FROM'] = $dblValue;
172 }
173 $strFrom = str_replace('#VALUE#', $dblValue.' '.$arBaseCurrencies[$arDiscount['SITE_ID']], GetMessage('BT_MOD_SALE_DSC_FORMAT_NAME_FROM'));
174 }
175 if (0 < $arDiscount['PRICE_TO'])
176 {
177 $dblValue = roundEx($boolCurrency ? $arDiscount['PRICE_TO'] : CCurrencyRates::ConvertCurrency($arDiscount['PRICE_TO'], $arDiscount['CURRENCY'], $arBaseCurrencies[$arDiscount['SITE_ID']]), SALE_VALUE_PRECISION);
178 $arConditions['CHILDREN'][] = array(
179 'CLASS_ID' => 'CondBsktAmtGroup',
180 'DATA' => array(
181 'logic' => 'EqLs',
182 'Value' => (string)$dblValue,
183 'All' => 'AND',
184 ),
185 'CHILDREN' => array(
186 ),
187 );
188 if (!$boolCurrency)
189 {
190 $arFields['PRICE_TO'] = $dblValue;
191 }
192 $strTo = str_replace('#VALUE#', $dblValue.' '.$arBaseCurrencies[$arDiscount['SITE_ID']], GetMessage('BT_MOD_SALE_DSC_FORMAT_NAME_TO'));
193 }
194 if (CSaleDiscount::OLD_DSC_TYPE_PERCENT == $arDiscount['DISCOUNT_TYPE'])
195 {
196 $arActions['CHILDREN'][] = array(
197 'CLASS_ID' => 'ActSaleBsktGrp',
198 'DATA' => array(
199 'Type' => 'Discount',
200 'Value' => (string)roundEx($arDiscount['DISCOUNT_VALUE'], SALE_VALUE_PRECISION),
201 'Unit' => 'Perc',
202 'All' => 'AND',
203 ),
204 'CHILDREN' => array(
205 ),
206 );
207 $strValue = $arDiscount['DISCOUNT_VALUE'].' %';
208 }
209 else
210 {
211 $dblValue = roundEx(($boolCurrency ? $arDiscount['DISCOUNT_VALUE'] : CCurrencyRates::ConvertCurrency($arDiscount['DISCOUNT_VALUE'], $arDiscount['CURRENCY'], $arBaseCurrencies[$arDiscount['SITE_ID']])), SALE_VALUE_PRECISION);
212 $arActions['CHILDREN'][] = array(
213 'CLASS_ID' => 'ActSaleBsktGrp',
214 'DATA' => array(
215 'Type' => 'Discount',
216 'Value' => (string)$dblValue,
217 'Unit' => 'CurAll',
218 'All' => 'AND',
219 ),
220 'CHILDREN' => array(
221 ),
222 );
223 if (!$boolCurrency)
224 {
225 $arFields['DISCOUNT_VALUE'] = $dblValue;
226 }
227 $strValue = $dblValue.' '.$arBaseCurrencies[$arDiscount['SITE_ID']];
228 }
229
230 if ('' != $strFrom || '' != $strTo)
231 {
232 $strName = str_replace(array('#VALUE#','#FROM#', '#TO#'), array($strValue, $strFrom, $strTo), GetMessage('BT_MOD_SALE_DSC_FORMAT_NAME'));
233 }
234 else
235 {
236 $strName = str_replace('#VALUE#', $strValue, GetMessage('BT_MOD_SALE_DSC_FORMAT_SHORT_NAME'));
237 }
238
239 $arFields['CONDITIONS'] = $arConditions;
240 $arFields['ACTIONS'] = $arActions;
241 $arFields['NAME'] = $strName;
242 if (!$boolCurrency)
243 {
244 $arFields['CURRENCY'] = $arBaseCurrencies[$arDiscount['SITE_ID']];
245 }
246
247 if ('N' == $strStatus)
248 {
249 $arFields['ACTIVE'] = 'N';
250 }
251
252 $mxRes = $obDiscount->Update($arDiscount['ID'], $arFields);
253 if (!$mxRes)
254 {
255 self::$intErrors++;
256 $strError = '';
257 if ($ex = $APPLICATION->GetException())
258 {
259 $strError = $ex->GetString();
260 }
261 if (empty($strError))
262 $strError = GetMessage('');
263 self::$arErrors[] = array(
264 'ID' => $arDiscount['ID'],
265 'NAME' => $strName,
266 'ERROR' => $strError,
267 );
268 }
269 else
270 {
271 $arTimeFields = array('~TIMESTAMP_X' => $DB->CharToDateFunction($arDiscount['TIMESTAMP_X'], "FULL"));
272 $strUpdate = $DB->PrepareUpdate($strTableName, $arTimeFields);
273 if (!empty($strUpdate))
274 {
275 $strQuery = "UPDATE ".$strTableName." SET ".$strUpdate." WHERE ID = ".$arDiscount['ID'];
276 $DB->Query($strQuery);
277 }
278
279 self::$intConverted++;
280 self::$intConvertPerStep++;
281 }
282
283 if ($intMaxExecutionTime > 0 && (microtime(true) - $startConvertTime > $intMaxExecutionTime))
284 break;
285 }
286
287 CTimeZone::Enable();
288
289 if ($intMaxExecutionTime > (2*(microtime(true) - $startConvertTime)))
290 self::$intNextConvertPerStep = $intStep*2;
291 else
292 self::$intNextConvertPerStep = $intStep;
293
295 }
296}
297?>
global $APPLICATION
Определения include.php:80
static ConvertCurrency($valSum, $curFrom, $curTo, $valDate="")
Определения currency_rate.php:393
const OLD_DSC_TYPE_PERCENT
Определения discount.php:16
const VERSION_OLD
Определения discount.php:12
static GetCountOld()
Определения discount_convert.php:54
static $boolEmptyList
Определения discount_convert.php:10
static GetCount()
Определения discount_convert.php:68
static $arErrors
Определения discount_convert.php:12
static $intErrors
Определения discount_convert.php:11
static ConvertDiscount($intStep=100, $intMaxExecutionTime=15)
Определения discount_convert.php:82
static SaveStep()
Определения discount_convert.php:33
static $intLastConvertID
Определения discount_convert.php:9
static GetErrors()
Определения discount_convert.php:49
static InitStep()
Определения discount_convert.php:20
static $intConverted
Определения discount_convert.php:8
static $strSessID
Определения discount_convert.php:13
static $intConvertPerStep
Определения discount_convert.php:6
static $intNextConvertPerStep
Определения discount_convert.php:7
Определения discount.php:6
static GetList($arOrder=array(), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения discount.php:15
static GetLangCurrency($siteId)
Определения settings.php:52
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$rsSites
Определения options.php:477
$res
Определения filter_act.php:7
$strError
Определения options_user_settings.php:4
global $DB
Определения cron_frame.php:29
roundEx($value, $prec=0)
Определения tools.php:4635
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
const SALE_VALUE_PRECISION
Определения include.php:46