From: kirostumm Date: Wed, 27 Dec 2023 14:43:25 +0000 (+0300) Subject: Страница с заказами X-Git-Tag: 1.1~196^2~1 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=bf3586eb9cbede26fe629f16198ce59ed07836ce;p=erp24_rep%2Fyii-erp24%2F.git Страница с заказами --- diff --git a/erp24/controllers/OrdersController.php b/erp24/controllers/OrdersController.php index cc45be40..f3234649 100644 --- a/erp24/controllers/OrdersController.php +++ b/erp24/controllers/OrdersController.php @@ -2,8 +2,13 @@ namespace app\controllers; +include_once('../inc/base_new.php'); +include_once('../inc/amo_inc.php'); + use Yii; use yii\web\Controller; +use yii_app\records\CreateChecks; +use yii_app\records\OrdersAmo; use yii_app\records\OrdersAmoSearch; class OrdersController extends Controller @@ -11,12 +16,140 @@ class OrdersController extends Controller public function actionDelivery() { + if (!empty($_REQUEST["umoup"])) { + + $date1 = mktime(0, 0, 0, date("n"), date("d", time() - 86400), date("Y")); + $date2 = mktime(0, 0, 0, date("n"), date("d"), date("Y")); + //include_once "/var/www/www-root/data/www/amo.bazacvetov24.ru/amo/amo_inc.php"; + $dt = "updated_at"; + + $statuses = [38932165, 142]; + $unix0 = $unix0 ?? ''; + $delivery__date = '&filter[' . $dt . '][from]=' . $unix0 . '&filter[' . $dt . '][to]=' . $date1 . ''; + $delivery__date = '&filter[custom_fields_values][647935][from]=' . $date1 . '&filter[custom_fields_values][647935][to]=' . $date2 . ''; + + $k = 0; + foreach ($statuses as $status) { + + $deal0 = amo_rest($ACCESS_TOKEN, '/api/v4/leads?order[updated_at]=desc&limit=250&filter[statuses][0][pipeline_id]=4021495&filter[statuses][0][status_id]=' . $status . '' . $delivery__date . '', 'GET', []); + + foreach ($deal0["_embedded"]["leads"] as $lid_id3 => $arr0) { + foreach ($arr0["custom_fields_values"] as $fid => $arr20) { + if ($arr20["field_id"] == 655357) $lid_id5 = $arr20["values"][0]["value"]; + if ($arr20["field_id"] == 647929) $store = $arr20["values"][0]["value"]; // store + if ($arr20["field_id"] == 647927) $delivery = $arr20["values"][0]["value"]; // delivery + + + } + + $k++; + echo "
$k) Сделка " . $arr0["id"] . " lid_id=$lid_id5 " . $arr0["name"] . " price= " . $arr0["name"] . " status_id=" . $arr0["status_id"] . " "; + + $dat = OrdersAmo::find()->select(['status_id', 'price', 'delivery_date']) + ->where([ + 'amo_id' => $arr0["id"] + ]) + ->asArray() + ->one(); + + if (empty($dat)) echo "
" . $dat["delivery_date"] . " " . $dat["status_id"] . " Заказа нет в системе " . $dat["id"] . " " . $dat["price"] . "
"; + + + if ($arr0["price"] != $dat["price"]) { + echo "Сумма заказа не равна ! " . $arr0["price"] . "!=" . $dat["price"] . ""; + OrdersAmo::updateAll(['price' => $arr0['price']], ['amo_id' => $arr0['id'], 'id' => $lid_id5]); + + } + + if ($dat["status_id"] != $arr0["status_id"]) { + if ($arr0["status_id"] == 142) { + OrdersAmo::updateAll(['status_id' => $arr0['status_id'], 'price' => $arr0['price']], ['amo_id' => $arr0['id'], 'id' => $lid_id5]); + + } + + } + + + if (!empty($arr0["id"])) { + OrdersAmo::updateAll(['store' => $store, $delivery => $delivery], ['amo_id' => $arr0['id']]); + + } + } + } + } + $searchModel = new OrdersAmoSearch(); $dataProvider = $searchModel->searchDelivery(Yii::$app->request->queryParams); - return $this->render('delivery',[ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider + return $this->render('delivery', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider ]); } + + public function actionAjax_return_check() + { + $salesCheck = Yii::$app->request->post('sales_check'); + $type = "Возврат"; + $sales_check = htmlentities($salesCheck); + $this->VozvratCheck($sales_check); + + } + + public function VozvratCheck($id) + { + + $order_id = CreateChecks::find()->select(['order_id'])->where(['check_id' => $id])->asArray()->one()['order_id']; + $date = CreateChecks::find()->select([ + 'date' => 'UNIX_TIMESTAMP(date)' + ]) + ->where([ + 'AND', + ['order_id' => $order_id], + ['type' => 'Возврат'] + ]) + ->orderBy([ + 'date' => SORT_DESC + ]) + ->asArray() + ->one(); + + $error = ""; + + if (!empty($date['date']) && $date['date'] > (time() - 60)) { + $error = "Возврат не создан так как прошло менее 60 секунд после создания чека на возврат"; + error_mess($error); + return; + } + + $data = CreateChecks::findOne(['check_id' => $id, 'type' => 'Продажа']); + + if (!empty($data)) { + $createCheck = new CreateChecks([ + 'date' => date('Y-m-d H:i:s'), + 'status' => 0, + 'type' => 'Возврат', + 'kkm_id' => $data->kkm_id, + 'seller_id' => $data->seller_id, + 'store_id' => $data->store_id, + 'order_id' => $data->order_id, + 'check_id' => create_guid(), + 'guid' => '-', + 'name' => '-', + 'held' => 1, + 'comments' => '-', + 'sales_check' => $data->check_id, + 'items' => $data->items, + 'payments' => $data->payments + ]); + + if ($createCheck->save()) { + mess("Чек на возврат создан"); + } else { + mess("Возникла ошибка оздния чека"); + var_dump($createCheck->errors); + } + } + + } } \ No newline at end of file diff --git a/erp24/inc/amo_inc.php b/erp24/inc/amo_inc.php new file mode 100644 index 00000000..2e80c44a --- /dev/null +++ b/erp24/inc/amo_inc.php @@ -0,0 +1,48 @@ +hasOne(Admin::class, ['id' => 'courier_id']); } + + public function getStatus() + { + return $this->hasOne(OrdersStatus::class, ['status_id' => 'status_id']); + } } diff --git a/erp24/records/OrdersAmoSearch.php b/erp24/records/OrdersAmoSearch.php index b0cb6c1a..871a8979 100644 --- a/erp24/records/OrdersAmoSearch.php +++ b/erp24/records/OrdersAmoSearch.php @@ -42,6 +42,10 @@ class OrdersAmoSearch extends OrdersAmo { $query = OrdersAmo::find(); $query->with('sales'); + $query->with('storeObj'); + $query->with('courierObj'); + $query->with('floristObj'); + $query->with('status'); // add conditions that should always apply here diff --git a/erp24/records/OrdersStatus.php b/erp24/records/OrdersStatus.php new file mode 100644 index 00000000..a97d0651 --- /dev/null +++ b/erp24/records/OrdersStatus.php @@ -0,0 +1,65 @@ + 255], + [['tip', 'type'], 'string', 'max' => 20], + [['color'], 'string', 'max' => 25], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'client_id' => 'Client ID', + 'name' => 'Name', + 'name_public' => 'Name Public', + 'status_id' => 'Status ID', + 'pipeline_id' => 'Pipeline ID', + 'account_id' => 'Account ID', + 'tip' => 'Tip', + 'color' => 'Color', + 'type' => 'Type', + 'posit' => 'Posit', + ]; + } +} diff --git a/erp24/views/orders/delivery.php b/erp24/views/orders/delivery.php index 4de7a9a0..e008ea43 100644 --- a/erp24/views/orders/delivery.php +++ b/erp24/views/orders/delivery.php @@ -13,9 +13,28 @@ use yii_app\records\OrdersAmoSearch; * @var $searchModel OrdersAmoSearch * @var $dataProvider ActiveDataProvider */ + +$this->registerJs(<<
+

Заказы из amo и чеки в магазинах '&date2=''" target="new" class="btn btn-info"> + импортировать заказы из amo с датой доставки

+ синхронизировать заказы с amo $searchModel, 'dataProvider' => $dataProvider, @@ -38,7 +57,7 @@ use yii_app\records\OrdersAmoSearch; $div = '
'; $div .= Html::a( - $model->delivery_date, + 'Заказ в AMO', 'https://bazacvetov24.amocrm.ru/leads/detail/' . $model->amo_id, [ 'target' => 'new' . $model->amo_id @@ -47,6 +66,8 @@ use yii_app\records\OrdersAmoSearch; $div .= '
'; + $div .= '
Дата доставки: ' . $model->delivery_date . '
'; + $div .= '
Магазин: ' . ($model->storeObj->name ?? '-') . '
'; $div .= '
Доставка: ' . $model->delivery . '
'; @@ -57,18 +78,15 @@ use yii_app\records\OrdersAmoSearch; } ], [ - 'label' => 'Статусы', + 'label' => 'Статус', 'format' => 'raw', 'value' => function (OrdersAmo $model) { - if ($model->status_id === 142) { - $div = 'Успешно'; - } else if ($model->status_id === 143) { - $div = 'Отказ'; + if ($model->status) { + return '

' . $model->status->name .'

'; } else { - $div = '' . $model->status_id .''; + return '

' . $model->status_id .'

'; } - return $div; } ], [ @@ -90,25 +108,27 @@ use yii_app\records\OrdersAmoSearch; 'label' => 'Информация по чекам', 'format' => 'raw', 'value' => function (OrdersAmo $model) { - $table = ''; + $table = '
GUIDОперация
'; if (!$model->sales) { - $tr = ''; + $tr = ''; $table .= $tr; } foreach ($model->sales as $sale) { if ($sale->operation === 'Продажа') { - $tr = ''; + $tr = ''; } else if ($sale->operation === 'Возврат') { - $tr = ''; + $tr = ''; } else { - $tr = ''; + $tr = ''; } + + $table .= $tr; } @@ -120,3 +140,20 @@ use yii_app\records\OrdersAmoSearch; ] ]) ?> + + \ No newline at end of file
GUIDОперацияДатаКто провел чек
--
-----
' . $sale->id . '' . $sale->operation . '
' . $sale->id . '' . $sale->operation . '' . $sale->date . '' . $sale->sellerById->name . '
' . $sale->id . '' . $sale->operation . '
' . $sale->id . '' . $sale->operation . ': ' . ($sale->sales_check != '' ? $sale->sales_check : '-') . '' . $sale->date . '' . $sale->sellerById->name . '
' . $sale->id . '' . $sale->operation . '
' . $sale->id . '' . $sale->operation . '' . $sale->date . '' . $sale->sellerById->name . '