示例#1
0
 public function search($params)
 {
     $query = Store::find();
     $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;
     }
     $dateBegin = strtotime($this->date);
     $dateEnd = $dateBegin + 86400;
     // adjust the query by adding the filters
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['school_id' => $this->school_id])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['status' => $this->status])->andFilterWhere(['>=', 'created_at', $this->date ? $dateBegin : null])->andFilterWhere(['<', 'created_at', $this->date ? $dateEnd : null]);
     return $dataProvider;
 }
示例#2
0
 public function actionIndex()
 {
     $sliders = slider::find()->all();
     $cat = Category::find()->all();
     $blogs = BLOG::find()->all();
     $store = Store::find()->all();
     $userModel = new SignupForm();
     $storeModel = new Store();
     $about_us = CMS::find()->where("cms_name = 'ABOUT US'")->one();
     $contact_us = CMS::find()->where("cms_name = 'CONTACT US'")->one();
     $pp = CMS::find()->where("cms_name = 'PRIVACY POLICY'")->one();
     $tc = CMS::find()->where("cms_name = 'TERMS & CONDITIONS'")->one();
     $testimonials = TESTIMONIALS::find()->all();
     return $this->render('index', ['categories' => array_chunk($cat, 5), 'stores' => array_chunk($store, 5), 'userModel' => $userModel, 'storeModel' => $storeModel, 'about_us' => $about_us, 'contact_us' => $contact_us, 'testimonials' => $testimonials, 'pp' => $pp, 'tc' => $tc, 'blogs' => $blogs, 'sliders' => $sliders]);
 }
示例#3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $stores = [];
     if (\Yii::$app->user->identity->id != 1) {
         $stores = UserStore::find()->select('store_id')->where(['user_id' => Yii::$app->user->identity->id])->all();
         $stores = ArrayHelper::getColumn($stores, 'store_id');
     }
     $query = Store::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(['store_id' => $this->store_id]);
     $query->andFilterWhere(['like', 'store_name', $this->store_name])->andFilterWhere(['like', 'store_desc', $this->store_desc])->andFilterWhere(['like', 'store_picture', $this->store_picture])->andFilterWhere(['in', 'store_id', $stores]);
     return $dataProvider;
 }
 /**
  * 将商品克隆到新的店铺
  * 
  * @param array $id  源商品ID或一个ID列表
  * @param string $to 目标店铺
  * @return string
  */
 public function actionClone(array $id, $to, $surplus = null)
 {
     if (!Store::find()->where(['id' => $to])->exists()) {
         echo "The parameter error.\n";
         return static::EXIT_CODE_ERROR;
     }
     $query = Goods::find()->where(['id' => $id]);
     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' => $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' => $surplus ?: $goods['surplus'], ':surplus_after' => $surplus ?: $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;
     }
 }
示例#5
0
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     // echo Yii::getAlias('@common'); exit;
     $model = new Product();
     $modelProdMeta = new ProductMeta();
     $stores = [];
     if (\Yii::$app->user->identity->id == 1) {
         $stores = \common\models\UserStore::find()->select('store_id')->where(['user_id' => Yii::$app->user->identity->id])->all();
         $stores = \yii\helpers\ArrayHelper::getColumn($stores, 'store_id');
         $storeList = \common\models\Store::find()->where(['IN', 'store_id', $stores])->all();
     } else {
         $storeList = \common\models\Store::find()->all();
     }
     if ($postData = Yii::$app->request->post()) {
         if ($model->load($postData) && $model->save()) {
             $prod_id = $model->prod_id;
             foreach ($model->cat_id as $cat) {
                 $catModel = new ProdCat();
                 $catModel->cat_id = $cat;
                 $catModel->prod_id = $prod_id;
                 $catModel->save();
             }
             $file = UploadedFile::getInstances($model, 'images');
             $model->file = $file[0];
             $image_path = Yii::getAlias('@frontend') . '/web/uploads/product/' . $model->file->baseName . '_' . $prod_id . '.' . $model->file->extension;
             $model->file->saveAs($image_path);
             $this->updateProductMeta($id, 'prod_img', $model->file->baseName . '_' . $prod_id . '.' . $model->file->extension);
             foreach ($postData['PMeta'] as $key => $meta_value) {
                 $this->updateProductMeta($id, $key, $meta_value);
             }
             return $this->redirect(['view', 'id' => $model->prod_id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'modelProdMeta' => $modelProdMeta, 'storeList' => $storeList]);
     }
 }