Ejemplo n.º 1
0
 /**
  * remember lang/shop state.
  */
 public function remember(Request $request)
 {
     // toggle state
     if ($request->has('toggled')) {
         $request->session()->put('toggled', $request->toggled);
     }
     // toggle shop
     if ($request->has('shop')) {
         $shop = Shop::find($request->shop);
         $request->session()->put('shop', $shop->id);
         $request->session()->put('shop_url', $shop->url);
     }
     // toggle language
     if ($request->has('language')) {
         $request->session()->put('language', $request->language);
     }
 }
Ejemplo n.º 2
0
 /**
  * Delete a shop.
  *
  * @param string $id
  *
  * @return Redirect
  */
 public function destroy(Request $request, $id)
 {
     // delete
     $shop = Shop::find($id);
     $shop->delete();
     // redirect
     $request->session()->flash('success', trans('shops.shop') . ' ' . trans('crud.deleted'));
     return redirect('admin/shops');
 }
Ejemplo n.º 3
0
 /**
  * Получить объект магазина
  * @return null | \app\models\Shop
  */
 public function getShop()
 {
     return Shop::find(['union_id' => $this->getId()]);
 }
Ejemplo n.º 4
0
 public function actionUpdate($id)
 {
     $model = Commodity::findOne($id);
     if (empty($model)) {
         throw new HttpException(404, '操作失败,商品不存在!');
     }
     if ($this->user->rid != 1 && $model->uid != $this->user->id) {
         throw new HttpException(404, 'error');
     }
     $oimg = $model->img;
     if ($model->load(Yii::$app->request->post())) {
         $img = UploadedFile::getInstance($model, 'img');
         if (!is_null($img)) {
             $model->img = $img;
             $name = time() . '.' . $model->img->extension;
             $model->img->saveAs('uploads/images/' . $name);
             $model->img = '/uploads/images/' . $name;
         } else {
             $model->img = $oimg;
         }
         $platform = Platform::findOne($model->platform_id);
         $model->platform = $platform->name;
         $shop = Shop::findOne($model->shop_id);
         if (!empty($shop)) {
             $model->shop = $shop->shop_name;
         }
         $model->statu = Commodity::$_AUDIT_PEND;
         if ($model->save()) {
             $this->redirect('/commodity/index');
         } else {
             var_dump($model->errors);
         }
     }
     $shops = array();
     if ($this->user->rid == 3) {
         $shops = Shop::find()->where('uid = :uid', [':uid' => $this->user->id])->all();
     } else {
         $shops = Shop::find()->all();
     }
     $platforms = Platform::find()->all();
     return $this->render('update', array('model' => $model, 'shops' => $shops, 'platforms' => $platforms));
 }
Ejemplo n.º 5
0
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Shop::find()->orderBy('create_time desc')]);
     return $this->render('index', array('dataProvider' => $dataProvider));
 }
Ejemplo n.º 6
0
 function actionSpent()
 {
     if ($user = Yii::$app->getRequest()->getQueryParam('user')) {
         if (!$user) {
             return 'Доступ запрещн!';
         }
         if (Yii::$app->getRequest()->getQueryParam('request')) {
             // return Yii::$app->getRequest()->getQueryParam('request');
             $shop = Shop::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('request')])->one();
             if ($shop) {
                 //return var_dump($shop->id);
                 $shop_spent_sum = Bought::find()->select(['id, spent, shop_id, COUNT(*) as cnt, SUM(spent) as sum'])->where(['user_id' => 8, 'shop_id' => $shop->id])->andWhere('id > 28')->one();
                 $shop_last_spent = Bought::find()->where(['user_id' => 8, 'shop_id' => $shop->id])->andWhere('id > 28')->orderBy('id DESC')->limit(30)->all();
                 //return var_dump($shop_spent);
                 return $this->renderPartial('spent_shop', ['spent_sum' => $shop_spent_sum, 'spents' => $shop_last_spent]);
             }
             $product = Products::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('request')])->one();
             if ($product) {
                 //return var_dump($shop->id);
                 $product_spent = Bought::find()->select(['id, spent, shop_id, COUNT(*) as cnt, SUM(spent) as sum'])->where(['user_id' => 8, 'product_id' => $product->id])->andWhere('id > 28')->one();
                 $product_last_spent = Bought::find()->where(['user_id' => 8, 'product_id' => $product->id])->andWhere('id > 28')->orderBy('id DESC')->limit(30)->all();
                 //return var_dump($product_last_spent);
                 return $this->renderPartial('spent_product', ['spent' => $product_spent, 'spents' => $product_last_spent, 'product' => $product->name]);
             }
             $product = Products::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('request')])->one();
             if ($product) {
                 //return var_dump($shop->id);
                 $product_spent = Bought::find()->select(['id, spent, shop_id, COUNT(*) as cnt, SUM(spent) as sum'])->where(['user_id' => 8, 'product_id' => $product->id])->andWhere('id > 28')->one();
                 $product_last_spent = Bought::find()->where(['user_id' => 8, 'product_id' => $product->id])->andWhere('id > 28')->orderBy('id DESC')->limit(30)->all();
                 //return var_dump($product_last_spent);
                 return $this->renderPartial('spent_product', ['spent' => $product_spent, 'spents' => $product_last_spent, 'product' => $product->name]);
             }
             $cat = Categories::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('request')])->one();
             if ($cat) {
                 $sum = 0;
                 $spent_prods = [];
                 $prods = Products::find()->where(['cat_id' => $cat->id])->all();
                 //return var_dump($prods);
                 foreach ($prods as $prod) {
                     $cat_products_ids = implode(',', ArrayHelper::map(Products::find()->where(['cat_id' => $prod->cat->id])->all(), 'id', 'id'));
                     $sum = Bought::find()->select('SUM(spent) as sum')->where('product_id IN (' . $cat_products_ids . ')')->andWhere('id > 28')->scalar();
                     $spent_prods[$prod->name] = Bought::find()->select('SUM(spent) as sum')->where(['user_id' => 8, 'product_id' => $prod->id])->andWhere('id > 28')->scalar();
                 }
                 arsort($spent_prods);
                 //return var_dump($spent_prods);
                 return $this->renderPartial('spent_cat', ['sum' => $sum, 'spent_prods' => $spent_prods, 'cat' => $cat->name]);
             }
         }
         //return 'ok';
         try {
             $spents = Bought::find()->select(['id, spent, product_id, COUNT(*) as cnt, SUM(spent) as sum'])->where(['user_id' => 8])->andWhere('id > 28')->groupBy('product_id')->orderBy('sum DESC')->limit(20)->all();
             $shop_spents = Bought::find()->select(['id, spent, shop_id, COUNT(*) as cnt, SUM(spent) as sum'])->where(['user_id' => 8])->andWhere('id > 28')->groupBy('shop_id')->orderBy('sum DESC')->limit(20)->all();
             $prod_boughts = [];
             $prods = Products::find()->select(['id, cat_id, COUNT(*) as cnt'])->groupBy('cat_id')->all();
             //return var_dump($prods);
             foreach ($prods as $prod) {
                 $cat_products_ids = implode(',', ArrayHelper::map(Products::find()->where(['cat_id' => $prod->cat->id])->all(), 'id', 'id'));
                 $prod_boughts[$prod->cat->name] = Bought::find()->select('SUM(spent) as sum')->where('product_id IN (' . $cat_products_ids . ')')->andWhere('id > 28')->scalar();
             }
             arsort($prod_boughts);
             //return var_dump($prod_boughts);
         } catch (\ErrorException $e) {
             return $e->getMessage();
         }
         return $this->renderPartial('spent', ['spents' => $spents, 'shop_spents' => $shop_spents, 'prod_boughts' => $prod_boughts]);
     }
 }
Ejemplo n.º 7
0
<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use app\models\Shop;
$this->title = 'SHOP';
$this->params['breadcrumbs'][] = $this->title;
$datas = array();
if ($_POST) {
    $datas = $_POST['ShopFormModel'];
}
/*
 * Itt van a lekérdezés !!!!
 * TODO
 */
$proba = Shop::find()->all();
//print_r($proba);
foreach ($proba as $pro) {
    print_r($pro);
    echo "<hr>";
}
?>
<a href='http://localhost/phpmyadmin/#PMAURL-1:db_structure.php?db=yii2basic&table=&server=1&target=&token=314f24ea1e8c1d29919c5038ebb6214e' target="_blank">localhost/phpmyadmin</a>
<div class="site-contact">
    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <div class = "row">
        <div class = "col-lg-5">