예제 #1
0
 public function actionIndex($cid = '')
 {
     $key = Yii::$app->request->get('key');
     if ($key) {
         $where = ['like', 'name', $key];
     } else {
         $where = [];
     }
     $query = Goods::find()->where($where);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeProduct']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     return $this->render('index', ['models' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination, 'totalItems' => $dataProvider->getTotalCount()]);
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Goods::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'price' => $this->price, 'category_id' => $this->category_id, 'quantity' => $this->quantity, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'item', $this->item])->andFilterWhere(['like', 'descr', $this->descr]);
     return $dataProvider;
 }
예제 #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Goods::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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->andFilterWhere(['id' => $this->id, 'rubric_id' => $this->rubric_id, 'price' => $this->price]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
예제 #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Goods::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'price' => $this->price, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'guige', $this->guige])->andFilterWhere(['like', 'danwei', $this->danwei])->andFilterWhere(['like', 'beizhu', $this->beizhu]);
     return $dataProvider;
 }
예제 #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Goods::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'type_id' => $this->type_id, 'brand_id' => $this->brand_id, 'account_count' => $this->account_count, 'status' => $this->status, 'modified_time' => $this->modified_time, 'create_time' => $this->create_time]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'unit', $this->unit])->andFilterWhere(['like', 'thumbnail', $this->thumbnail])->andFilterWhere(['like', 'attributes', $this->attributes])->andFilterWhere(['like', 'show_pictures', $this->show_pictures])->andFilterWhere(['like', 'seo_title', $this->seo_title])->andFilterWhere(['like', 'seo_keyword', $this->seo_keyword])->andFilterWhere(['like', 'seo_description', $this->seo_description])->andFilterWhere(['like', 'detail_link', $this->detail_link])->andFilterWhere(['like', 'goods_sku', $this->goods_sku]);
     return $dataProvider;
 }
 public function actionAdd($id)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     if (!Goods::find()->where(['id' => $id, 'store_id' => Yii::$app->user->identity->store_id, 'status' => [Goods::STATUS_NORMAL, Goods::STATUS_OFF_SHELVES]])->exists() || Purchase::hasGoods($id)) {
         throw new BadRequestHttpException('拒绝操作。');
     }
     $model = new Purchase();
     $model->goods_id = $id;
     $model->store_id = Yii::$app->user->identity->store_id;
     $model->count = 1;
     if ($model->save(false)) {
         return ['status' => 'success', 'data' => []];
     } else {
         return ['status' => 'fail', 'data' => ['message' => '加入失败。']];
     }
 }
예제 #7
0
 public function search($params)
 {
     $query = Goods::find()->where(['and', ['store_id' => Yii::$app->user->identity->store_id], ['<>', 'status', Goods::STATUS_DELETED]]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => 20]]);
     // load the seach form data and validate
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->_addDigitalFilter($query, 'price');
     $this->_addDigitalFilter($query, 'sales');
     $this->_addDigitalFilter($query, 'surplus');
     $dateBegin = strtotime($this->date);
     $dateEnd = $dateBegin + 86400;
     // adjust the query by adding the filters
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['category_id' => $this->category_id])->andFilterWhere(['like', 'unit', $this->unit])->andFilterWhere(['status' => $this->status])->andFilterWhere(['>=', 'created_at', $this->date ? $dateBegin : null])->andFilterWhere(['<', 'created_at', $this->date ? $dateEnd : null]);
     return $dataProvider;
 }
예제 #8
0
파일: index.php 프로젝트: RStuffGit/mebel
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel common\models\OrderSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Заказы';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="order-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['label' => 'Товар', 'format' => 'raw', 'attribute' => 'goods_id', 'value' => function ($model) {
    return Html::a($model->goods->name, ['view', 'id' => $model->id]);
}, 'filter' => Html::activeDropDownList($searchModel, 'goods_id', ArrayHelper::map(\common\models\Goods::find()->asArray()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Выберите товар'])], ['label' => 'Пользователь', 'attribute' => 'user_id', 'value' => function ($model) {
    return $model->user->username;
}, 'filter' => Html::activeDropDownList($searchModel, 'user_id', ArrayHelper::map(\common\models\User::find()->asArray()->all(), 'id', 'username'), ['class' => 'form-control', 'prompt' => 'Выберите пользователя'])], 'datetime', ['label' => 'Статус', 'attribute' => 'active', 'value' => function ($model) {
    return $model->active ? "Новый" : "Выполнен";
}, 'filter' => Html::activeDropDownList($searchModel, 'active', [0 => 'Выполнен', 1 => "Новый"], ['class' => 'form-control', 'prompt' => 'Выберите статус'])], ['label' => 'Действие', 'attribute' => '', 'format' => 'raw', 'value' => function ($model) {
    return $model->active == 1 ? Html::a("Принять", ['accept', 'id' => $model->id]) : '';
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view}']]]);
?>

</div>
예제 #9
0
 * QQ:6232967
 * Create at 2015-12-30 17:47:31
 */
?>
<div class="rmzt">
    <div class="rmzt-tit lm-tb"><span><a href="<?php 
echo Yii::$app->urlManager->createUrl(['price/index']);
?>
">更多</a></span>建筑材料信息价</div>	
    <div><img src="<?php 
echo Yii::$app->params['staticsPath'];
?>
images/yubin_55.jpg" width="280" height="104" alt="" /></div>
    <ul class="kbxx-nr">
        <?php 
$goods = \common\models\Goods::find()->orderBy(['updated_at' => SORT_DESC])->limit(11)->all();
?>
        <?php 
foreach ($goods as $k => $v) {
    ?>
        <li><a href="<?php 
    echo Yii::$app->urlManager->createUrl(['price/index', 'key' => $v->name]);
    ?>
"><?php 
    echo date("Y", $v->updated_at);
    ?>
年<?php 
    echo date("m", $v->updated_at);
    ?>
月<?php 
    echo $v->name;
예제 #10
0
 function actionProducts()
 {
     $categoria_id = Yii::$app->request->get('categoria');
     $brand_id = Yii::$app->request->get('brand');
     if ($categoria_id) {
         $query = Goods::find()->where(['status' => 1, 'category_id' => $categoria_id]);
     } elseif ($brand_id) {
         $query = Goods::find()->where(['status' => 1, 'brend_id' => $brand_id]);
     } else {
         $query = Goods::find()->where(['status' => 1]);
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 2]);
     $modelsGoods = $query->offset($pages->offset)->limit(3)->all();
     $data = $this->getCommonDate();
     $iP = Yii::$app->session->id;
     $quantityInCart = Cart::getQountAllByIp($iP);
     $model = Cart::getAllByIp($iP);
     $modelBrends = Brend::find()->all();
     $modelNewGoods = Goods::getNewest(15);
     $modelGoodsCategories = GoodsCategory::find()->all();
     return $this->render('products', ['modelsGoods' => $modelsGoods, 'pages' => $pages, 'data' => $data, 'modelNewGoods' => $modelNewGoods, 'modelGoodsCategories' => $modelGoodsCategories, 'model' => $model, 'modelBrends' => $modelBrends, 'quantityInCart' => $quantityInCart]);
 }
예제 #11
0
 /**
  * 将商品从一个店铺克隆到另一个店铺
  * 
  * @param string $from     源商品所在店铺ID
  * @param string $to       目标店铺ID
  * @param string $category 过滤商品类型
  * @param string $status   过滤商品状态
  * @return string
  */
 public function actionCloneAll($from, $to, $category = 'all', $status = 'all')
 {
     $modelFrom = Store::findOne($from);
     $modelTo = Store::findOne($to);
     if (!$modelFrom || !$modelTo) {
         echo "The parameter error.\n";
         return static::EXIT_CODE_ERROR;
     }
     if ($modelFrom->type !== $modelTo->type) {
         if (!static::confirm("The types of two stores are not the same, continue?")) {
             echo "Cancelled.\n";
             return static::EXIT_CODE_NORMAL;
         }
     }
     unset($modelFrom, $modelTo);
     $query = Goods::find()->where(['store_id' => $from]);
     if ($category !== 'all') {
         $modelCate = Category::findOne(['slug' => $category]);
         if ($modelCate) {
             $query->andWhere(['category_id' => $modelCate->id]);
             unset($modelCate);
         } else {
             echo "The category \"{$category}\" can not be exists.\n";
             return static::EXIT_CODE_ERROR;
         }
     }
     if ($status !== 'all') {
         if (in_array($status, [Goods::STATUS_NORMAL, Goods::STATUS_OFF_SHELVES, Goods::STATUS_DELETED])) {
             $query->andWhere(['status' => $status]);
         } else {
             echo "The status was error.\n";
             return static::EXIT_CODE_ERROR;
         }
     }
     if (($count = $query->count()) > 0) {
         if (!static::confirm("Next we will clone {$count} goods, are you sure?")) {
             echo "Cancelled.\n";
             return static::EXIT_CODE_NORMAL;
         }
     } else {
         echo "The goods count is 0.\n";
         return static::EXIT_CODE_NORMAL;
     }
     $goodsList = $query->asArray()->all();
     $time = time();
     $sql = "INSERT INTO {{%goods}} (name, store_id, category_id, cover, price, price_original, cost, description, status, surplus, sales, unit, is_new, is_hot, is_promotion, created_at, updated_at) VALUES (:name, :store_id, :category_id, :cover, :price, :price_original, :cost, :description, :status, :surplus, :sales, :unit, :is_new, :is_hot, :is_promotion, :created_at, :updated_at)";
     $sql2 = "INSERT INTO {{%goods_img}} (name, goods_id) VALUES (:name, :goods_id)";
     $sql3 = "INSERT INTO {{%goods_surplus}} (goods_id, surplus_before, amount, surplus_after, remark, created_at, updated_at) VALUES (:goods_id, :surplus_before, :amount, :surplus_after, :remark, :created_at, :updated_at)";
     $transaction = Yii::$app->db->beginTransaction();
     try {
         foreach ($goodsList as $goods) {
             Yii::$app->db->createCommand($sql, [':name' => $goods['name'], ':store_id' => $to, ':category_id' => $goods['category_id'], ':cover' => $goods['cover'], ':price' => $goods['price'], ':price_original' => $goods['price_original'], ':cost' => $goods['cost'], ':description' => $goods['description'], ':status' => $goods['status'], ':surplus' => $goods['surplus'], ':sales' => '0', ':unit' => $goods['unit'], ':is_new' => $goods['is_new'], ':is_hot' => $goods['is_hot'], ':is_promotion' => $goods['is_promotion'], ':created_at' => $time, ':updated_at' => $time])->execute();
             $goodsId = Yii::$app->db->getLastInsertID();
             $goodsImgList = GoodsImg::find()->where(['goods_id' => $goods['id']])->asArray()->all();
             foreach ($goodsImgList as $goodsImg) {
                 Yii::$app->db->createCommand($sql2, [':name' => $goodsImg['name'], ':goods_id' => $goodsId])->execute();
             }
             Yii::$app->db->createCommand($sql3, [':goods_id' => $goodsId, ':surplus_before' => 0, ':amount' => $goods['surplus'], ':surplus_after' => $goods['surplus'], ':remark' => '初始化库存。', ':created_at' => $time, ':updated_at' => $time])->execute();
         }
         $transaction->commit();
         echo "Success!\n";
         return static::EXIT_CODE_NORMAL;
     } catch (\Exception $e) {
         $transaction->rollBack();
         echo $e->getMessage();
         return static::EXIT_CODE_ERROR;
     }
 }
예제 #12
0
 public function actionCart()
 {
     $session = Yii::$app->getSession();
     $cart = $session->has('cart') ? $session->get('cart') : [];
     $goods_id = ArrayHelper::getColumn($cart, 'id');
     $goods = Goods::find()->where(['id' => $goods_id])->asArray()->indexBy('id')->all();
     $amount = 0;
     foreach ($cart as $one_goods) {
         $amount += $one_goods['count'] * $goods[$one_goods['id']]['price'];
     }
     return $this->render('cart', ['cart' => $cart, 'goods' => $goods, 'amount' => $amount]);
 }
예제 #13
0
 /**
  * 回收站列表
  */
 public function actionTrash()
 {
     if (!$this->is_access('goods/trash')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $query = Goods::find()->where(['is_delete' => 1]);
     if (!empty($_GET['goods_name'])) {
         $query = $query->andWhere("goods_name like '%{$_GET['goods_name']}%'");
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'Sort' => ['defaultOrder' => ['goods_id' => SORT_DESC]]]);
     Yii::$app->view->params['meta_title'] = '商品回收站';
     return $this->render('trash', ['dataProvider' => $dataProvider]);
 }
예제 #14
0
 /**
  * 更新配置文件的sitemap
  * @param string $config
  */
 public static function updateConfigSitemap($config, $sm, $domain, $today)
 {
     if (!static::updateAll(['value' => serialize($config)], "code='sitemap'")) {
         return false;
     }
     $res = Category::find()->select(['id', 'cat_name'])->orderBy('parent_id')->column();
     foreach ($res as $row) {
         $smi =& new GoogleSitemapItem($domain . UtilD::build_uri('category', [$row['id']], $row['cat_name']), $today, $config['category_changefreq'], $config['category_priority']);
         $sm->add_item($smi);
     }
     $res = ArticleCat::find()->select(['id', 'cat_name'])->where(['cat_type' => 1])->column();
     foreach ($res as $row) {
         $smi =& new GoogleSitemapItem($domain . UtilD::build_uri('article_cat', ['acid' => $row['id']], $row['cat_name']), $today, $config['category_changefreq'], $config['category_priority']);
         $sm->add_item($smi);
     }
     $res = Goods::find()->select(['id', 'goods_name'])->where('is_delete=0')->column();
     foreach ($res as $row) {
         $smi =& new GoogleSitemapItem($domain . UtilD::build_uri('goods', ['gid' => $row['id']], $row['goods_name']), $today, $config['content_changefreq'], $config['content_priority']);
         $sm->add_item($smi);
     }
     //文章
     $res = Article::find()->select(['id', 'title', 'file_url', 'open_type'])->where('is_open=1')->column();
     foreach ($res as $row) {
         $article_url = $row['open_type'] != 1 ? UtilD::build_uri('article', ['aid' => $row['id']], $row['title']) : trim($row['file_url']);
         $smi =& new GoogleSitemapItem($domain . $article_url, $today, $config['content_changefreq'], $config['content_priority']);
         $sm->add_item($smi);
     }
     $sm_file = 'sitemaps.xml';
     if ($sm->build($sm_file)) {
         return true;
     } else {
     }
 }
예제 #15
0
 /**
  * @return mixed
  */
 public function actionView($id)
 {
     $goods = Goods::find()->where(['id' => $id])->one();
     $orders = ArrayHelper::getColumn(Order::find()->where(['user_id' => \Yii::$app->user->getId(), 'active' => 1])->all(), 'goods_id');
     return $this->render('view', ['goods' => $goods, 'orders' => $orders]);
 }
예제 #16
0
 public function getGoodsCount()
 {
     return Goods::find()->where(['store_id' => $this->id, 'status' => Goods::STATUS_NORMAL])->count();
 }
예제 #17
0
 public function actionGetGoodsByPriceRange()
 {
     $cur = Yii::$app->request->post('valute');
     $data = Yii::$app->request->post('data');
     $dataFrom = $data['0'];
     $dataTo = $data['1'];
     //vd($dataFrom.'|' . $dataTo);
     // $modelGoods = Goods::getGoodsByPriceRange($dataFrom ,$dataTo,$cur);
     $query = Goods::find()->where(['>', 'price', $dataFrom])->AndWhere(['<', 'price', $dataTo])->AndWhere(['status' => Goods::STATUS_ACTIVE]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 2]);
     $modelsGoods = $query->offset($pages->offset)->limit(3)->all();
     Yii::$app->response->format = Response::FORMAT_JSON;
     $iP = Yii::$app->session->id;
     $quantityInCart = Cart::getQountAllByIp($iP);
     $data = $this->getCommonDate();
     $modelBest = Goods::getBest(3);
     return $this->renderAjax('products-ajax', ['modelsGoods' => $modelsGoods, 'pages' => $pages, 'modelBest' => $modelBest ? $modelBest : false]);
 }