--- /dev/null
+<?php
+
+/**
+ * @var $time integer
+ */
+
+use yii\db\Exception;
+use yii\helpers\ArrayHelper;
+
+use yii\helpers\Json;
+use yii_app\records\ApiCronBuh;
+use yii_app\records\Firms;
+use yii_app\records\Motivation;
+use yii_app\records\MotivationBuh;
+use yii_app\records\MotivationBuhValue;
+use yii_app\records\MotivationCostsItem;
+use yii_app\records\MotivationValue;
+use yii_app\records\MotivationValueGroup;
+use yii_app\records\Users;
+use yii_app\records\UsersBonus;
+use yii_app\api3\modules\v1\models\orders\OrdersAmo;
+use yii_app\records\Sales;
+use yii_app\records\SchedulerTaskLog;
+use yii_app\records\NotifiableUser;
+
+ini_set('max_execution_time', (string)(60 * 60 * 1)); // 1 час
+ini_set('display_errors', 'on');
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
+
+echo "time2_" . $time . "_time2 ";
+$taskNum = 33;
+$dateTask = date('Y-m-d H:i:s');
+$dateTaskStart = null;
+$dateTaskStop = null;
+$log = '';
+$error = '';
+$infoError = '';
+$infoText = '';
+$description = '';
+$result = 0;
+
+$enable = true;
+$start = false;
+$force = false;
+
+$minuetTimeInTask = date('i', $time);
+$fullTimeInTask = date('Y-m-d H:i:s', $time);
+
+try {
+ if (
+ (
+ (
+ date('H:i', $time) == "08:00" ||
+ date('H:i', $time) == "20:00"
+ )
+ || $force
+ )
+ && $enable
+ ) {
+
+ $dateTaskStart = date('Y-m-d H:i:s');
+ $info = ' ================ test Task ' . $taskNum . ' start ================';
+ echo $info;
+ $log .= $info;
+ $log .= $time;
+
+ $schedulerTaskLog = new SchedulerTaskLog();
+ $schedulerTaskLog->setTaskNum($taskNum)
+ ->setName('Task ' . $taskNum)
+ ->setDate($dateTask)
+ ->setDateStart($dateTaskStart);
+ $validate = $schedulerTaskLog->validate();
+ if ($validate) {
+ $schedulerTaskLog->save();
+ }
+
+ $motivationGroup = MotivationValueGroup::findOne(['alias' => 'week' . Motivation::getWeek()]);
+
+ $motivationBuhValue = MotivationBuhValue::find()
+ ->andWhere(['motivation_group_id' => $motivationGroup->id])
+ ->groupBy('store_id, value_id, motivation_buh_id')
+ ->select('sum(value_float) as value_float', 'motivation_buh_id, value_id')
+ ->asArray();
+
+ foreach ($motivationBuhValue as $value) {
+
+ $motivationBuh = MotivationBuh::findOne([$motivationBuhValue['motivation_buh_id']]);
+
+ $motivation = Motivation::findOne([
+ 'year' => $motivationBuh->year,
+ 'month' => $motivationBuh->month,
+ 'store_id' => $motivationBuhValue['store_id'],
+ ]);
+
+ if (!$motivation) {
+ $motivation = new Motivation();
+ $motivation->setAttributes([
+ 'year' => $motivationBuh->year,
+ 'month' => $motivationBuh->month,
+ 'store_id' => $value['store_id']
+ ]);
+ $motivation->save();
+ }
+
+ $motivationValue = new MotivationValue();
+ $motivationValue->setAttributes([
+ 'motivation_id' => $motivation->id,
+ 'motivation_group_id' => $motivationGroup->id,
+ 'value_id' => $value['value_id'],
+ 'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT,
+ 'value_float' => $value['value_float'],
+ ]);
+ }
+
+ $info = ' ================ test Task ' . $taskNum . ' stop ================';
+ echo $info;
+ $log .= $info;
+ $log .= ' date >= ' . strtotime("-1 week", time());
+ $dateTaskStop = date('Y-m-d H:i:s');
+ } else {
+ $info = ' Task ' . $taskNum . ' skip ';
+ echo $info;
+ $log .= $info;
+ }
+} catch (Exception $e) {
+ $error = 'Exception: ' . $e->getMessage() . ' ' . $e->getFile() . ' >>> ' . $e->getLine();
+}
+
+if (empty($schedulerTaskLog)) {
+ $schedulerTaskLog = new SchedulerTaskLog();
+ $schedulerTaskLog->setTaskNum($taskNum)
+ ->setName('Task ' . $taskNum)
+ ->setDate($dateTask)
+ ->setDateStart($dateTaskStart)
+ ->setDateStop($dateTaskStop)
+ ->setDescription($description)
+ ->setError($error)
+ ->setInfo($infoText)
+ ->setLog($log);
+} else {
+ $schedulerTaskLog->setDateStop($dateTaskStop)
+ ->setDescription($description)
+ ->setError($error)
+ ->setInfo($infoText)
+ ->setLog($log);
+}
+$validate = $schedulerTaskLog->validate();
+if ($validate) {
+ $schedulerTaskLog->save();
+}
\ No newline at end of file
namespace yii_app\services;
+use yii_app\records\Motivation;
use yii_app\records\MotivationBuh;
use yii_app\records\MotivationBuhValue;
use yii_app\records\StoreGuidBuh;
$month = date('m', strtotime($end));
$inn = $data['inn'];
$week = null;
-
$validate = self::validateWeek($start, $end);
if ($validate !== 'month') {
- $week = self::getWeek($start) == self::getWeek($end) ? self::getWeek($start) : null;
+ $week = Motivation::getWeek($start) == Motivation::getWeek($end) ? Motivation::getWeek($start) : null;
if (!$validate && !$week) {
LogService::apiErrorLog(json_encode(["error_id" => 45, "error" => 'Указан некорректный период'], JSON_UNESCAPED_UNICODE));
return;
$alias = $validate === 'month' ? 'month' : 'week' . $week;
$motivationValueGroup = MotivationValueGroup::findOne(['alias' => $alias]);
-
if (!empty($data['cost_items'])) {
foreach ($data['cost_items'] as $stores) {
foreach ($stores as $storeData) {
LogService::apiErrorLog(json_encode(["error_id" => 48, "error" => $exception->getMessage() . ' ' . $exception->getFile() . ' ' . $exception->getLine()], JSON_UNESCAPED_UNICODE));
}
-
}
private static function validateWeek($startTime, $endTime)
return true;
}
-
-
- static function getWeek($date)
- {
- $d = date("d", strtotime($date));
- return intval(floor(($d - 1) / 7) + 1);
- }
-
+
}