use yii_app\records\MarketplaceOrderStatusHistory;
use yii_app\records\MarketplaceOrderStatusTypes;
use yii_app\records\MarketplaceStore;
+use yii_app\records\Prices;
use yii_app\records\PricesDynamic;
use yii_app\records\Products1c;
use yii_app\records\ProductsClass;
$searchModel = new MarketplaceOrdersSearch();
$dataProvider = $searchModel->search($this->request->queryParams);
+ $dataProvider->sort->defaultOrder = [
+ 'creation_date' => SORT_DESC,
+ ];
+
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
$marketplaceClass = ProductsClass::find()
->where(['tip' => [ProductsClass::MARKETPLACE]])->one();
$product = Products1c::find()
- ->where(['tip' => 'products'])
- ->andWhere(['parent_id' => $marketplaceClass->category_id])
- ->andWhere(['not', ['articule' => null]])
+ ->alias('p')
+ ->innerJoin(
+ Prices::tableName() . ' pr',
+ 'pr.product_id = p.id'
+ )
+ ->where([
+ 'p.tip' => 'products',
+ 'p.parent_id' => $marketplaceClass->category_id,
+ ])
+ ->andWhere(['not', ['p.articule' => null]])
+ ->andWhere(['>', 'pr.price', 0])
->orderBy('RANDOM()')
->one();
Yii::$app->session->setFlash('error', 'Не найден ни один товар в products_1c.');
return $this->redirect(['index']);
}
- $priceRecord = PricesDynamic::find()
+ $priceRecord = Prices::find()
->where([
'product_id' => $product->id,
- 'active' => 1,
- 'region_id' => 52,
- ])
- ->orderBy(['date_from' => SORT_DESC])
- ->one();
+ ])->one();
$price = $priceRecord ? $priceRecord->price : 0;
$orderNumber = mt_rand(10_000_000, 99_999_999);
$now = date('Y-m-d H:i:s');
if ($mp == 1) {
-
-
$orderDetails = [
'number' => $orderNumber,
'date' => $now,
'fake' => true,
];
- // 4) Создаём модель заказа
$m = new MarketplaceOrders();
$m->marketplace_order_id = (string)$orderNumber;
$m->marketplace_id = 1;
return $this->redirect(['index']);
}
if ($mp == 2) {
-
$raw = [
"id" => $orderNumber,
"status" => "PROCESSING",
return $this->redirect(['index']);
}
-
$hist = new MarketplaceOrderStatusHistory();
$hist->order_id = $m->id;
$hist->status_id = $status->id;