]> gitweb.erp-flowers.ru Git - yii-erp24/.git/commitdiff
Страница с заказами
authorkirostumm <kirostumm@gmail.com>
Tue, 26 Dec 2023 12:13:03 +0000 (15:13 +0300)
committerkirostumm <kirostumm@gmail.com>
Tue, 26 Dec 2023 12:13:03 +0000 (15:13 +0300)
erp24/controllers/OrdersController.php [new file with mode: 0644]
erp24/records/OrdersAmo.php
erp24/records/OrdersAmoSearch.php [new file with mode: 0644]
erp24/views/orders/delivery.php [new file with mode: 0644]

diff --git a/erp24/controllers/OrdersController.php b/erp24/controllers/OrdersController.php
new file mode 100644 (file)
index 0000000..cc45be4
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+
+namespace app\controllers;
+
+use Yii;
+use yii\web\Controller;
+use yii_app\records\OrdersAmoSearch;
+
+class OrdersController extends Controller
+{
+
+    public function actionDelivery()
+    {
+        $searchModel = new OrdersAmoSearch();
+        $dataProvider = $searchModel->searchDelivery(Yii::$app->request->queryParams);
+
+        return $this->render('delivery',[
+           'searchModel' => $searchModel,
+           'dataProvider' => $dataProvider
+        ]);
+    }
+}
\ No newline at end of file
index e570d3ccfc121d200f94abbaf47c3eeeb1f08cbd..7a717532be5bc762b13dfd97677cd5bf6c9eafa9 100644 (file)
@@ -134,6 +134,11 @@ use Yii;
  * @property int $1c_send Отправлено в 1c
  * @property string $check_id_arr
  * @property string $data_md5
+ *
+ * @property Sales $sales
+ * @property CityStore $storeObj
+ * @property Admin $courierObj
+ * @property Admin $floristObj
  */
 class OrdersAmo extends \yii\db\ActiveRecord
 {
@@ -309,4 +314,27 @@ class OrdersAmo extends \yii\db\ActiveRecord
             'data_md5' => 'Data Md5',
         ];
     }
+
+    public function getSales()
+    {
+        return $this->hasMany(Sales::class, ['order_id' => 'id'])
+            ->orderBy([
+                'date' => SORT_ASC
+            ]);
+    }
+
+    public function getStoreObj()
+    {
+        return $this->hasOne(CityStore::class, ['id' => 'store_id']);
+    }
+
+    public function getFloristObj()
+    {
+        return $this->hasOne(Admin::class, ['id' => 'florist_id']);
+    }
+
+    public function getCourierObj()
+    {
+        return $this->hasOne(Admin::class, ['id' => 'courier_id']);
+    }
 }
diff --git a/erp24/records/OrdersAmoSearch.php b/erp24/records/OrdersAmoSearch.php
new file mode 100644 (file)
index 0000000..b0cb6c1
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+
+namespace yii_app\records;
+
+use yii\base\Model;
+use yii\data\ActiveDataProvider;
+use yii_app\records\OrdersAmo;
+
+/**
+ * OrdersAmoSearch represents the model behind the search form of `yii_app\records\OrdersAmo`.
+ */
+class OrdersAmoSearch extends OrdersAmo
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['id', 'created_id', 'amo_id', 'pipeline_id', 'status_id', 'price', 'bonus', 'istochnik_id', 'setka_id', 'site_id', 'city_id', 'client_anonim', 'courier_id', 'florist_id', 'florist_sborka_night', 'florist_soglas', 'florist_pravki', 'responsible_user_id', 'manager_id', 'price_dostavka', 'price_dostavka_zatrat', 'price_dostavka_povtor', 'price_dostavka_povtor_zatrat', 'client_adress_zamena', 'client_adress_zamena_cnt', 'client_pravki_cnt', 'client_foro_prosmotr', 'status_logist', 'problem_status', 'problem_id', 'problem_price', 'reshenie_id', 'uber_time', 'manager_time', 'amo_sync', 'client_id', 'contact_id', 'courier_opozdal', 'sms_foto', 'sms_samovivoz', 'sms_predano', 'sms_dostavleno', 'sms_oplata', 'sms_status_order', 'is_mobile', 'opozdanie_status', 'opozdanie_user_id', '1c_send', 'employee_id'], 'integer'],
+            [['nomer', 'created_at', 'update_at', 'name', 'istochnik', 'phone_source', 'brend', 'site_url', 'city', 'povod', 'order_text', 'shariki', 'toper', 'text_card', 'phone', 'phone_client', 'email', 'client', 'pol_name', 'pol_phone', 'delivery', 'delivery_date', 'delivery_time', 'delivery_time_extend', 'delivery_adress', 'delivery_rayon', 'delivery_oblast', 'courier', 'courier_zabor', 'courier_dostavil', 'courier_gps', 'florist', 'florist_peredano', 'florist_zabor', 'florist_foto', 'florist_sobrano', 'florist_comment', 'responsible_user', 'manager', 'manager_courier_time', 'comment', 'pay', 'pay_text', 'payment_type_id', 'store', 'store_id', 'dostavka_povtor_tip', 'dostavka_comment', 'otkaz_id', 'otkaz_text', 'otkaz_manager', 'otkaz_id_rop', 'tags_arr', 'tags', 'client_comment_foto', 'client_ip', 'status_logist_time', 'problem_date', 'problem_text', 'problem_manager', 'problem_comment', 'problem_comment_manager', 'problem_reshenie_date', 'key_code', 'updated_at', 'closed_at', 'amo_sync_time', 'utm_source', 'utm_term', 'utm_medium', 'utm_campaign', 'utm_content', 'os', 'ip', 'sid', 'opozdanie_text', 'products_json', 'check_id_arr', 'data_md5'], 'safe'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function scenarios()
+    {
+        // bypass scenarios() implementation in the parent class
+        return Model::scenarios();
+    }
+
+    /**
+     * Creates data provider instance with search query applied
+     *
+     * @param array $params
+     *
+     * @return ActiveDataProvider
+     */
+    public function searchDelivery($params)
+    {
+        $query = OrdersAmo::find();
+        $query->with('sales');
+
+        // add conditions that should always apply here
+
+        $dataProvider = new ActiveDataProvider([
+            'query' => $query,
+            'sort' => [
+                'defaultOrder' => [
+                    'delivery_date' => SORT_DESC,
+                    'update_at' => SORT_DESC
+                ]
+            ]
+        ]);
+
+        $this->load($params);
+
+        if (!$this->validate()) {
+            // uncomment the following line if you do not want to return any records when validation fails
+            // $query->where('0=1');
+            return $dataProvider;
+        }
+
+        $query->where([
+            '<=',
+            'delivery_date',
+            date('Y-m-d H:i:s')
+        ]);
+
+        return $dataProvider;
+    }
+}
diff --git a/erp24/views/orders/delivery.php b/erp24/views/orders/delivery.php
new file mode 100644 (file)
index 0000000..4de7a9a
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+
+use yii\data\ActiveDataProvider;
+use yii\grid\GridView;
+use yii\helpers\Html;
+use yii\helpers\Url;
+use yii\web\View;
+use yii_app\records\OrdersAmo;
+use yii_app\records\OrdersAmoSearch;
+
+/**
+ * @var $this View
+ * @var $searchModel OrdersAmoSearch
+ * @var $dataProvider ActiveDataProvider
+ */
+?>
+
+<div class="p-8">
+    <?= GridView::widget([
+        'filterModel' => $searchModel,
+        'dataProvider' => $dataProvider,
+        'options' => [
+            'style' => [
+                'overflow-x' => 'scroll'
+            ]
+        ],
+        'columns' => [
+            [
+                'label' => 'Информация о доставке',
+                'format' => 'raw',
+                'contentOptions' => function (OrdersAmo $model) {
+                    return [
+                        'class' => ($model->sales ? 'table-success' : 'table-danger'),
+                    ];
+                },
+                'value' => function (OrdersAmo $model) {
+
+                    $div = '<div class="w-100 text-center">';
+
+                    $div .= Html::a(
+                        $model->delivery_date,
+                        'https://bazacvetov24.amocrm.ru/leads/detail/' . $model->amo_id,
+                        [
+                            'target' => 'new' . $model->amo_id
+                        ]
+                    );
+
+                    $div .= '</div>';
+
+                    $div .= '<div>Магазин: <span class="" >' . ($model->storeObj->name ?? '-') . '</span></div>';
+
+                    $div .= '<div> Доставка: <span class="">' . $model->delivery . '</span></div>';
+
+                    $div .= '<div> Адрес доставки: <span class="">' . $model->delivery_adress . '</span></div>';
+
+                    return $div;
+                }
+            ],
+            [
+                'label' => 'Статусы',
+                'format' => 'raw',
+                'value' => function (OrdersAmo $model) {
+                    if ($model->status_id === 142) {
+                        $div = '<span class="badge bg-success">Успешно</span>';
+                    } else if ($model->status_id === 143) {
+                        $div = '<span class="badge bg-danger">Отказ</span>';
+                    } else {
+                        $div = '<span class="badge bg-info">' . $model->status_id .'</span>';
+                    }
+
+                    return $div;
+                }
+            ],
+            [
+                'label' => '',
+                'format' => 'raw',
+                'value' => function (OrdersAmo $model) {
+                    if ($model->floristObj) {
+                        $div = '<div>Флорист: ' . ($model->floristObj->name ?? '-') . '</div>';
+                    } else {
+                        $div = '<div class="bg-danger">Флорист: ' . 'Укажите верного ID флориста в АМО! И обновите данные по заказам - иначе чек не пробьется! 
+У каждого чека должен быть актуальный продавец' . '</div>';
+                    }
+
+                    $div .= '<div>Курьер: ' . ($model->courierObj->name ?? '-') . '</div>';
+                    return $div;
+                }
+            ],
+            [
+                'label' => 'Информация по чекам',
+                'format' => 'raw',
+                'value' => function (OrdersAmo $model) {
+                    $table = '<table class="table text-center"><thead><td>GUID</td><td>Операция</td></thead><tbody>';
+
+                    if (!$model->sales) {
+                        $tr = '<tr class="table-danger"><td>-</td><td>-</td></tr>';
+                        $table .= $tr;
+                    }
+
+                    foreach ($model->sales as $sale) {
+                        if ($sale->operation === 'Продажа') {
+                            $tr = '<tr class="table-success"><td>' . $sale->id . '</td><td>' . $sale->operation . '</td></tr>';
+
+                        } else if ($sale->operation === 'Возврат') {
+                            $tr = '<tr class="table-warning"><td>' . $sale->id . '</td><td>' . $sale->operation . '</td></tr>';
+
+                        } else {
+                            $tr = '<tr class="table-info"><td>' . $sale->id . '</td><td>' . $sale->operation . '</td></tr>';
+
+                        }
+
+                        $table .= $tr;
+                    }
+
+                    $table .= '</tbody></table>';
+
+                    return $table;
+                }
+            ],
+        ]
+    ]) ?>
+</div>