--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+class m251223_145226_add_error_text_field_to_create_checks_table extends Migration
+{
+ const TABLE_NAME = 'erp24.create_checks';
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $table = $this->db->schema->getTableSchema(self::TABLE_NAME);
+ if ($table === null) {
+ return;
+ }
+
+ if (!$this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('error_text')) {
+ $this->addColumn(
+ self::TABLE_NAME,
+ 'error_text',
+ $this->text()->null()->comment('Текст ошибки при создании чека в 1С')
+ );
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ if ($this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('error_text')) {
+ $this->dropColumn(self::TABLE_NAME, 'error_text');
+ }
+ }
+}
* @property string|null $marketplace_order_id
* @property int|null $is_marketplace признак продажи через маркетплейс
* @property string|null $marketplace_name название маркетплейса
+ * @property string|null $error_text Текст ошибки при создании чека в 1С
*/
class CreateChecks extends \yii\db\ActiveRecord
{
return [
[[/*'kkm_id', */'store_id', /*'order_id', */'check_id', 'guid', /*'name', 'sales_check',*/ 'items', /*'payments',*/ 'held', 'date'/*, 'comments'*/], 'required'],
[['order_id', 'held', 'status', 'is_marketplace'], 'integer'],
- [['type', 'items', 'payments', 'phone'], 'string'],
+ [['type', 'items', 'payments', 'phone', 'error_text'], 'string'],
[['date', 'delivery_date', 'date_up', 'phone'], 'safe'],
[['kkm_id', 'seller_id', 'store_id', 'check_id', 'guid', 'sales_check', 'order_guid', 'marketplace_order_id', 'marketplace_name'], 'string', 'max' => 36],
[['name', 'comments'], 'string', 'max' => 255],
'marketplace_order_id' => 'Marketplace Order ID',
'is_marketplace' => 'Is Marketplace',
'marketplace_name' => 'Marketplace Name',
+ 'error_text' => 'Error Text',
];
}
if (!empty($result['created_checks'])) {
foreach ($result["created_checks"] as $idp => $arr2) {
- if (!empty($arr2["error"])) { // Если есть ошибки
+ if (!empty($arr2["error"]) || !empty($arr2["errors"])) { // Если есть ошибки
// // обновляем GUID на новый
// try {
// $createChecks = CreateChecks::find()->select(['order_id'])->where(['check_id' => $arr2["id"]])->one();
// } catch (Exception $e) {
// file_put_contents(self::OUT_DIR . '/log_created_check_error.txt', PHP_EOL . date("d.m.Y H:i:s",time()). $e->getMessage(), FILE_APPEND);
// }
+ // Формируем текст ошибки
+ $errorText = null;
+ if (!empty($arr2["errors"]) && is_array($arr2["errors"])) {
+ $errorDescriptions = [];
+ foreach ($arr2["errors"] as $err) {
+ if (!empty($err["error_description"])) {
+ $errorDescriptions[] = $err["error_description"];
+ }
+ }
+ $errorText = implode('; ', $errorDescriptions);
+ }
+ // Fallback на $arr2["error"] если error_description пустой
+ if (empty($errorText) && !empty($arr2["error"])) {
+ $errorText = is_array($arr2["error"])
+ ? json_encode($arr2["error"], JSON_UNESCAPED_UNICODE)
+ : $arr2["error"];
+ }
CreateChecks::updateAll([
'status' => CreateChecks::STATUS_CHECK_ERROR_1C,
'guid' => $arr2["id"],
'date_up' => date('Y-m-d H:i:s'),
+ 'error_text' => $errorText,
], ['check_id' => $arr2["id"]]);
LogService::apiErrorLog(json_encode(["error_id" => 31, "error" => 'ОШИБКА В 1С - СОЗДАНИЕ ЧЕКА ЗАКАЗА id=' . $arr2["id"]], JSON_UNESCAPED_UNICODE));
- $txt = date("d.m.Y H:i:s", time()) . " $idp СОЗДАНИЕ ЧЕКА ОШИБКА id=" . $arr2["id"] . " " . $arr2["error"];
+ $txt = date("d.m.Y H:i:s", time()) . " $idp СОЗДАНИЕ ЧЕКА ОШИБКА id=" . $arr2["id"] . " " . $errorText;
file_put_contents(self::OUT_DIR . '/log_created_check_error.txt', PHP_EOL . $txt, FILE_APPEND);
} else { // Если ошибок нет
if (/* $arr2["held"] == true and */ !empty($arr2["name"]) and !empty($arr2["id"])) { // Если заполнен name b id