public function actionShop1() { $model = new Shop(); if ($model->load(yii::$app->request->post()) && $model->validate()) { yii::$app->session->setFlash('success', 'You have entered the data correctly'); } return $this->render('shopForm', ['model' => $model]); }
public function __construct(Route $route) { $this->middleware(function ($request, $next) { // if session is not set get it from .env SHOP_CODE if (!$request->session()->has('shop')) { $shop = Shop::where('code', config('app.shop_code'))->first(); $request->session()->put('shop', $shop->id); } // if limit is not set default pagination limit if (!$request->session()->has('limit')) { $request->session()->put('limit', 100); } // if session is not set reset the session for the language if (!$request->session()->has('language')) { $request->session()->put('language', config('app.locale')); } // if session is not set reset the session for the basket if (!$request->session()->has('basket')) { $request->session()->put('basket', ['subtotal' => 0, 'count' => 0, 'items' => []]); } // global list of categories $categories = Category::where('shop_id', $request->session()->get('shop'))->orderBy('order', 'asc')->get(); // share globals view()->share('language', $request->session()->get('language')); view()->share('categories', $categories); return $next($request); }); // add controller & action to the body class $currentAction = $route->getActionName(); list($controller, $method) = explode('@', $currentAction); $controller = preg_replace('/.*\\\\/', '', $controller); $action = preg_replace('/.*\\\\/', '', $method); view()->share('body_class', $controller . '-' . $action); }
public function __construct() { $this->middleware(function ($request, $next) { // get all shops $shops = Shop::all(); // if there are no shops force user to add one if (count($shops) == 0) { $request->session()->flash('warning', trans('shops.required')); return redirect('shops/create'); } // if session is not set or the shop doesn't exist reset the session for the shop if (!$request->session()->has('shop') || Shop::where('_id', '=', $request->session()->get('shop'))->count() == 0) { $shop = Shop::first(); $request->session()->put('shop', $shop->id); $request->session()->put('shop_url', $shop->url); } // if session is not set reset the session for the language if (!$request->session()->has('language')) { $request->session()->put('language', config('app.locale')); } // if limit is not set default pagination limit if (!$request->session()->has('limit')) { $request->session()->put('limit', 100); } view()->share('select_shops', $shops); view()->share('languages', Language::LANGUAGES); view()->share('language', $request->session()->get('language')); return $next($request); }); }
public function actionSaveallot() { $uid = Yii::$app->request->post('uid'); $shops = Yii::$app->request->post('shop'); Shop::updateAll(['uid' => 0], ['uid' => $uid]); foreach ($shops as $shop) { Shop::updateAll(['uid' => $uid], ['id' => $shop]); } echo '<script>alert("保存成功!");location.href="/user/index";</script>'; }
/** * Handle the command. * * @param CreateShopCommand $command * @return void */ public function handle(CreateShopCommand $command) { $shop = Shop::create(['scheduled' => $command->scheduled, 'title' => $command->title, 'amount' => $command->amount, 'reimbursement' => $command->reimbursement, 'postcode' => $command->postcode, 'description' => $command->description, 'proof' => $command->proof, 'client_id' => $command->client_id, 'key_id' => $command->key_id, 'geocoding_id' => 1]); if (!empty($shop)) { //Create Geocoding Job $job = (new UpdateShopGeocoding($shop))->delay(5); $this->dispatch($job); //Create shop calendar event // $job = (new CreateShopCalendarEvent($shop))->delay(5); // $this->dispatch($job); $this->calendar->save($shop); return $shop; } return false; }
/** * 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); } }
/** * Handle the command. * * @param UpdateShopCommand $command * @return void */ public function handle(UpdateShopCommand $command) { $shop = Shop::whereId($command->id)->first(); if (!empty($shop)) { $shop->scheduled = $command->scheduled; $shop->title = $command->title; $shop->amount = $command->amount; $shop->reimbursement = $command->reimbursement; $shop->postcode = $command->postcode; $shop->description = $command->description; $shop->proof = $command->proof; //$shop->payment = $command->payment; $shop->client_id = $command->client_id; $shop->key_id = $command->key_id; if ($shop->save()) { return $shop; } } return false; }
/** * Получить объект магазина * @return null | \app\models\Shop */ public function getShop() { return Shop::find(['union_id' => $this->getId()]); }
public function get($month, $year) { return \App\Models\Shop::with('key', 'client', 'geocoding')->where(DB::raw('MONTH(shops.scheduled)'), '=', $month)->where(DB::raw('YEAR(shops.scheduled)'), '=', $year)->orderBy('scheduled')->get(); }
/** * Show the application dashboard. * * @return Response */ public function index() { $shops = Shop::paginate(12); return view('home', compact('shops')); }
<?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">
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)); }
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]); } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $shop = Shop::whereId($id)->first(); if (empty($shop)) { return $this->saveResponse(false); } return $this->saveResponse($shop->delete()); }
/** * @return \yii\db\ActiveQuery */ public function getShops0() { return $this->hasMany(Shop::className(), ['driver_id' => 'user_id']); }
/** * 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'); }
/** * @return \yii\db\ActiveQuery */ public function getShop() { return $this->hasOne(Shop::className(), ['id' => 'shop_id']); }