From: Alexander Smirnov Date: Fri, 11 Oct 2024 11:20:08 +0000 (+0300) Subject: [ERP-222] рефактор weekly_report_subscription в tg_subscription X-Git-Tag: 1.6~39^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=dfc64f00c482fccd90e79aae37c65c553fe5587d;p=erp24_rep%2Fyii-erp24%2F.git [ERP-222] рефактор weekly_report_subscription в tg_subscription --- diff --git a/erp24/actions/tg/SubscriptionAction.php b/erp24/actions/tg/SubscriptionAction.php new file mode 100644 index 00000000..9a99f044 --- /dev/null +++ b/erp24/actions/tg/SubscriptionAction.php @@ -0,0 +1,54 @@ +request->isPost) { + $action = Yii::$app->request->post('action'); + if ($action == "addNew") { + $name = Yii::$app->request->post('name'); + $chatId = Yii::$app->request->post('chat_id'); + + $sub = new TgSubscription; + $sub->name = $name; + $sub->chat_id = $chatId; + $sub->active = 0; + + $sub->save(); + if ($sub->getErrors()) { + throw new \Exception(Json::encode($sub->getErrors())); + } + return $this->controller->redirect('subscription'); + } + if ($action == "changeSub") { + $subId = Yii::$app->request->post('id'); + $name = Yii::$app->request->post('name'); + $chatId = Yii::$app->request->post('chatId'); + $active = Yii::$app->request->post('active'); + + $sub = TgSubscription::findOne($subId); + $sub->name = $name; + $sub->chat_id = $chatId; + $sub->active = $active; + $sub->save(); + if ($sub->getErrors()) { + throw new \Exception(Json::encode($sub->getErrors())); + } + + return 'ok'; + } + } + + $subscriptions = TgSubscription::find()->orderBy(['id' => SORT_DESC])->all(); + + return $this->controller->render('subscription', compact('subscriptions')); + } +} \ No newline at end of file diff --git a/erp24/actions/weeklyReport/SubscriptionAction.php b/erp24/actions/weeklyReport/SubscriptionAction.php deleted file mode 100644 index a960a502..00000000 --- a/erp24/actions/weeklyReport/SubscriptionAction.php +++ /dev/null @@ -1,54 +0,0 @@ -request->isPost) { - $action = Yii::$app->request->post('action'); - if ($action == "addNew") { - $name = Yii::$app->request->post('name'); - $chatId = Yii::$app->request->post('chat_id'); - - $sub = new WeeklyReportSubscription; - $sub->name = $name; - $sub->chat_id = $chatId; - $sub->active = 0; - - $sub->save(); - if ($sub->getErrors()) { - throw new \Exception(Json::encode($sub->getErrors())); - } - return $this->controller->redirect('subscription'); - } - if ($action == "changeSub") { - $subId = Yii::$app->request->post('id'); - $name = Yii::$app->request->post('name'); - $chatId = Yii::$app->request->post('chatId'); - $active = Yii::$app->request->post('active'); - - $sub = WeeklyReportSubscription::findOne($subId); - $sub->name = $name; - $sub->chat_id = $chatId; - $sub->active = $active; - $sub->save(); - if ($sub->getErrors()) { - throw new \Exception(Json::encode($sub->getErrors())); - } - - return 'ok'; - } - } - - $subscriptions = WeeklyReportSubscription::find()->orderBy(['id' => SORT_DESC])->all(); - - return $this->controller->render('subscription', compact('subscriptions')); - } -} \ No newline at end of file diff --git a/erp24/api3/modules/v1/controllers/TgController.php b/erp24/api3/modules/v1/controllers/TgController.php new file mode 100644 index 00000000..6b83bde6 --- /dev/null +++ b/erp24/api3/modules/v1/controllers/TgController.php @@ -0,0 +1,12 @@ +where(['active' => 1])->all(); + } +} \ No newline at end of file diff --git a/erp24/api3/modules/v1/controllers/WeeklyReportController.php b/erp24/api3/modules/v1/controllers/WeeklyReportController.php deleted file mode 100644 index d114d78d..00000000 --- a/erp24/api3/modules/v1/controllers/WeeklyReportController.php +++ /dev/null @@ -1,12 +0,0 @@ -where(['active' => 1])->all(); - } -} \ No newline at end of file diff --git a/erp24/controllers/TgController.php b/erp24/controllers/TgController.php new file mode 100644 index 00000000..61750e04 --- /dev/null +++ b/erp24/controllers/TgController.php @@ -0,0 +1,15 @@ + \yii_app\actions\tg\SubscriptionAction::class, + ]; + } +} \ No newline at end of file diff --git a/erp24/controllers/WeeklyReportController.php b/erp24/controllers/WeeklyReportController.php deleted file mode 100644 index 377ee09d..00000000 --- a/erp24/controllers/WeeklyReportController.php +++ /dev/null @@ -1,15 +0,0 @@ - \yii_app\actions\weeklyReport\SubscriptionAction::class, - ]; - } -} \ No newline at end of file diff --git a/erp24/migrations/m241010_150710_create_table_weekly_report_subscribtion.php b/erp24/migrations/m241010_150710_create_table_weekly_report_subscribtion.php index eadf9016..6b007b86 100755 --- a/erp24/migrations/m241010_150710_create_table_weekly_report_subscribtion.php +++ b/erp24/migrations/m241010_150710_create_table_weekly_report_subscribtion.php @@ -7,7 +7,7 @@ use yii\db\Migration; */ class m241010_150710_create_table_weekly_report_subscribtion extends Migration { - const TABLE_NAME = 'erp24.weekly_report_subscription'; + const TABLE_NAME = 'erp24.tg_subscription'; /** * {@inheritdoc} diff --git a/erp24/records/TgSubscription.php b/erp24/records/TgSubscription.php new file mode 100644 index 00000000..00bc9d33 --- /dev/null +++ b/erp24/records/TgSubscription.php @@ -0,0 +1,50 @@ + null], + [['chat_id', 'active'], 'integer'], + [['name'], 'string', 'max' => 36], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Name', + 'chat_id' => 'Chat ID', + 'active' => 'Active', + ]; + } +} diff --git a/erp24/records/WeeklyReportSubscription.php b/erp24/records/WeeklyReportSubscription.php deleted file mode 100644 index a4522d06..00000000 --- a/erp24/records/WeeklyReportSubscription.php +++ /dev/null @@ -1,50 +0,0 @@ - null], - [['chat_id', 'active'], 'integer'], - [['name'], 'string', 'max' => 36], - ]; - } - - /** - * {@inheritdoc} - */ - public function attributeLabels() - { - return [ - 'id' => 'ID', - 'name' => 'Name', - 'chat_id' => 'Chat ID', - 'active' => 'Active', - ]; - } -} diff --git a/erp24/views/tg/subscription.php b/erp24/views/tg/subscription.php new file mode 100644 index 00000000..f784b38a --- /dev/null +++ b/erp24/views/tg/subscription.php @@ -0,0 +1,55 @@ +registerJsFile('/js/weekly-report/subscription.js', ['position' => \yii\web\View::POS_END]); + +?> + +
+ + + +
+
+ Имя: +
+
+ chat_id: 'number'])?> +
+
+ 'btn btn-success btn-sm', 'name' => 'action', 'value' => 'addNew'])?> +
+
+ + + +
+
+ + + + + + + + + + + + + + + + + +
Имяchat_idАктивен
active == 1 ? 'checked="checked"' : '' ?> onclick="saveChanges(this)" />
+
+
+ +
diff --git a/erp24/views/weekly-report/subscription.php b/erp24/views/weekly-report/subscription.php deleted file mode 100644 index 36a13ce1..00000000 --- a/erp24/views/weekly-report/subscription.php +++ /dev/null @@ -1,55 +0,0 @@ -registerJsFile('/js/weekly-report/subscription.js', ['position' => \yii\web\View::POS_END]); - -?> - -
- - - -
-
- Имя: -
-
- chat_id: 'number'])?> -
-
- 'btn btn-success btn-sm', 'name' => 'action', 'value' => 'addNew'])?> -
-
- - - -
-
- - - - - - - - - - - - - - - - - -
Имяchat_idАктивен
active == 1 ? 'checked="checked"' : '' ?> onclick="saveChanges(this)" />
-
-
- -