public function actionUpload_product() { if (Yii::$app->request->isAjax) { $model = new ProductCategory(); $Product = new Product(); $ProductImageRel = new ProductImageRel(); $ProductCategoryRel = new ProductCategoryRel(); $model_cat_title = UploadedFile::getInstance($model, 'cat_title'); $time = time(); $model_cat_title->saveAs('product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension); if ($model_cat_title) { $response = []; $Product->title = $_POST['title']; $Product->desc = $_POST['desc']; $Product->status = 1; if ($Product->save()) { $ProductCategoryRel->category_id = $_POST['id']; $ProductCategoryRel->product_id = $Product->id; $ProductImageRel->product_id = $Product->id; $ProductImageRel->image = $time . $model_cat_title->baseName . '.' . $model_cat_title->extension; if ($ProductCategoryRel->save() && $ProductImageRel->save()) { $response['files'][] = ['name' => $time . $model_cat_title->name, 'type' => $model_cat_title->type, 'size' => $model_cat_title->size, 'url' => Url::base() . '/product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension, 'deleteUrl' => Url::to(['delete_uploaded_file', 'file' => $model_cat_title->baseName . '.' . $model_cat_title->extension]), 'deleteType' => 'DELETE']; $response['base'] = $time . $model_cat_title->baseName; $response['view'] = $this->renderAjax('uploaded_product', ['url' => Url::base() . '/product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension, 'basename' => $time . $model_cat_title->baseName, 'id' => $ProductImageRel->id, 'model' => $Product]); } } else { $response['errors'] = $product->getErrors(); } return json_encode($response); } } }
public static function getButtons($model) { $result = ''; $result .= Html::tag('p', '<b>Цена: ' . Product::getPriceOrOldPrice($model) . ' ' . $model->currency . ' ' . self::getAvail($model) . '</b>'); $result .= Html::tag('p', Html::a('<button class="btn btn-danger">Купить</button>', ['/cart/add', 'id' => $model->id])); return $result; }
public function actionUpdate($id, $quantity) { $product = Product::findOne($id); if ($product) { \Yii::$app->cart->update($product, $quantity); $this->redirect(['cart/list']); } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product::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, 'gallery_id' => $this->gallery_id]); $query->andFilterWhere(['like', 'product', $this->product])->andFilterWhere(['like', 'file_name', $this->file_name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product::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, 'power' => $this->power, 'light_source' => $this->light_source, 'input_voltage' => $this->input_voltage, 'load_capacity' => $this->load_capacity, 'high_cut' => $this->high_cut, 'low_cut' => $this->low_cut, 'created' => $this->created, 'created_by' => $this->created_by]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'warranty', $this->warranty])->andFilterWhere(['like', 'case', $this->case])->andFilterWhere(['like', 'body_color', $this->body_color])->andFilterWhere(['like', 'ip_grade', $this->ip_grade])->andFilterWhere(['like', 'quality_approved', $this->quality_approved])->andFilterWhere(['like', 'place_of_origin', $this->place_of_origin]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product::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, 'availability' => $this->availability, 'price' => $this->price, 'rating' => $this->rating, 'top' => $this->top, 'user_id' => $this->user_id, 'category_id' => $this->category_id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'brand', $this->brand])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'short_description', $this->short_description])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'image_alt', $this->image_alt])->andFilterWhere(['like', 'currency', $this->currency])->andFilterWhere(['like', 'vendor', $this->vendor]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product::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, 'is_featured' => $this->is_featured, 'status' => $this->status, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'desc', $this->desc]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $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, 'price' => $this->price, 'original_price' => $this->original_price, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status, 'is_active' => $this->is_active, 'is_hot' => $this->is_hot, 'position' => $this->position, 'published_at' => $this->published_at, 'view_count' => $this->view_count, 'comment_count' => $this->comment_count, 'share_count' => $this->share_count, 'like_count' => $this->like_count, 'available_quantity' => $this->available_quantity, 'order_quantity' => $this->order_quantity, 'sold_quantity' => $this->sold_quantity, 'total_quantity' => $this->total_quantity, 'total_revenue' => $this->total_revenue]); $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'old_slugs', $this->old_slugs])->andFilterWhere(['like', 'image_path', $this->image_path])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'banner', $this->banner])->andFilterWhere(['like', 'created_by', $this->created_by])->andFilterWhere(['like', 'updated_by', $this->updated_by]); return $dataProvider; }
/** * 产品列表 * @return type */ public function actionIndex() { $view = \Yii::$app->view; $view->params['moduleName'] = '产品管理'; $request = \Yii::$app->request; $status = $request->_get('status', 'waiting'); $search = $request->_get('search', ''); $total = Product::getTotal($status, $search); $pagination = new Pagination(['defaultPageSize' => \Yii::$app->params['pageSize'], 'totalCount' => $total]); $data = Product::getProducts($status, $search, $pagination->limit, $pagination->offset); $token = Token::getToken(); $userId = \Yii::$app->user->id; $changestatusIdentity = EasyHelpers::dataEncrypt('changestatus,' . $userId); return $this->render('index', ['data' => $data, 'pagination' => $pagination, 'status' => $status, 'search' => $search, 'token' => $token, 'changestatusIdentity' => $changestatusIdentity]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product::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->joinWith('user'); $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'user.username', $this->user_id]); return $dataProvider; }
/** * function ::create ($data) */ public static function create($data) { $now = strtotime('now'); $username = Yii::$app->user->identity->username; $model = new Product(); if ($model->load($data)) { if ($log = new UserLog()) { $log->username = $username; $log->action = "Create"; $log->object_class = "Product"; $log->created_at = $now; $log->is_success = 0; $log->save(); } $model->created_at = $now; $model->created_by = $username; $model->published_at = strtotime($model->published_at); do { $path = FileUtils::generatePath($now); } while (file_exists(Yii::$app->params['images_folder'] . $path)); $model->image_path = $path; $targetFolder = Yii::$app->params['images_folder'] . $model->image_path; $targetUrl = Yii::$app->params['images_url'] . $model->image_path; if (!empty($data['product-image'])) { $copyResult = FileUtils::copyImage(['imageName' => $model->image, 'fromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'resize' => array_values(Product::$image_resizes), 'removeInputImage' => true]); if ($copyResult['success']) { $model->image = $copyResult['imageName']; } } if (!empty($data['product-banner'])) { $copyResult = FileUtils::copyImage(['imageName' => $model->banner, 'fromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'removeInputImage' => true]); if ($copyResult['success']) { $model->banner = $copyResult['imageName']; } } if ($model->save()) { if ($log) { $log->object_pk = $model->id; $log->is_success = 1; $log->save(); } return $model; } $model->getErrors(); return $model; } return false; }
public function getproducts() { return $this->hasMany(Product::className(), ['id' => 'product_id'])->viaTable('product_category_rel', ['category_id' => 'id']); }
?> <div class="order-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'user_id')->textInput(array('readonly' => true, 'value' => Yii::$app->user->identity->id)); ?> <?php echo $form->field($model, 'username')->textInput(array('readonly' => true, 'value' => Yii::$app->user->identity->username)); ?> <?php $products = Product::find()->all(); $listData = ArrayHelper::map($products, 'id', 'name'); echo $form->field($model, 'product_id')->dropDownList($listData, ['prompt' => 'Select Product...']); ?> <?php echo $form->field($model, 'qty')->textInput(['maxlength' => 45]); ?> <?php echo $form->field($model, 'date')->textInput(['maxlength' => 45]); ?> <?php echo $form->field($model, 'Status')->textInput(['maxlength' => 255]); ?>
public function updateProduct($productId, $productName, $productBrief, $productStatus, $productPrice, $productStock) { $model = Product::findOne($productId); if (!$model) { return false; } $model->productName = $productName; $model->productBrief = $productBrief; $model->productStock = intval($productStock); $model->productStatus = $productStatus; switch ($productStatus) { case 0: $model->onSaleTime = date('Y-m-d H:i:s', time()); break; case 1: $model->offSaleTime = date('Y-m-d H:i:s', time()); break; case 2: $model->onSaleTime = date('Y-m-d H:i:s', time()); break; } $model->productPrice = $productPrice; if ($model->save()) { return true; } return false; }
/** * Updates an existing PurchaseOrder model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $username = Yii::$app->user->identity->username; if ($model = $this->findModel($id)) { $this->purchase_order_id = $model->id; $old_status = $model->status; if (Yii::$app->request->isPost && $model->update2(Yii::$app->request->post())) { $new_status = $model->status; $details = PurchaseOrderDetail::find()->where(['purchase_order_id' => $model->id])->all(); switch ($old_status) { case PurchaseOrder::STATUS_NEW: case PurchaseOrder::STATUS_PENDING: switch ($new_status) { case PurchaseOrder::STATUS_SUCCESS: foreach ($details as $item) { if ($product = Product::findOne($item->product_id)) { $product->order_quantity -= $item->quantity; $product->sold_quantity += $item->quantity; $product->total_revenue += $item->quantity * $item->unit_price; $product->save(); } } break; case PurchaseOrder::STATUS_REJECT: case PurchaseOrder::STATUS_CANCELLED: case PurchaseOrder::STATUS_FAIL: foreach ($details as $item) { if ($product = Product::findOne($item->product_id)) { $product->order_quantity -= $item->quantity; $product->available_quantity += $item->quantity; $product->save(); } } default: } break; case PurchaseOrder::STATUS_SUCCESS: switch ($new_status) { case PurchaseOrder::STATUS_NEW: case PurchaseOrder::STATUS_PENDING: foreach ($details as $item) { if ($product = Product::findOne($item->product_id)) { $product->sold_quantity -= $item->quantity; $product->order_quantity += $item->quantity; $product->total_revenue -= $item->quantity * $item->unit_price; $product->save(); } } break; case PurchaseOrder::STATUS_REJECT: case PurchaseOrder::STATUS_CANCELLED: case PurchaseOrder::STATUS_FAIL: foreach ($details as $item) { if ($product = Product::findOne($item->product_id)) { $product->sold_quantity -= $item->quantity; $product->available_quantity += $item->quantity; $product->total_revenue -= $item->quantity * $item->unit_price; $product->save(); } } default: } break; case PurchaseOrder::STATUS_REJECT: case PurchaseOrder::STATUS_CANCELLED: case PurchaseOrder::STATUS_FAIL: switch ($new_status) { case PurchaseOrder::STATUS_NEW: case PurchaseOrder::STATUS_PENDING: foreach ($details as $item) { if ($product = Product::findOne($item->product_id)) { $product->available_quantity -= $item->quantity; $product->order_quantity += $item->quantity; $product->save(); } } break; case PurchaseOrder::STATUS_SUCCESS: foreach ($details as $item) { if ($product = Product::findOne($item->product_id)) { $product->available_quantity -= $item->quantity; $product->sold_quantity += $item->quantity; $product->total_revenue += $item->quantity * $item->unit_price; $product->save(); } } default: } break; default: } return $this->goBack(Url::previous()); } else { return $this->render('update', ['username' => $username, 'model' => $model]); } } else { throw new NotFoundHttpException(); } }
public function actionEditproduct() { $user = new AdminUser(); if (!$user->checkUserIsLogin()) { $this->redirect(Variable::$home_url); return; } $req = Yii::$app->request; //创建一个请求对象 $form = new ProductForm(); $form->setScenario('update'); $id = trim($req->get('id')); if (!is_numeric($id) || $id == 0) { $this->redirect(Variable::$productManger_url); return; } $productModel = Product::findOne($id); $form->productName = $productModel->productName; $form->productBrief = $productModel->productBrief; $form->productStock = $productModel->productStock; $form->productPrice = $productModel->productPrice; $form->productStatus = $productModel->productStatus; $form->productStock = $productModel->productStock; //修改 if ($form->load($req->post()) && $form->validate()) { $isSuccess = (new Product())->updateProduct($id, $form->productName, $form->productBrief, $form->productStatus, $form->productPrice, $form->productStock); if ($isSuccess) { $form->addError('', '资料更新成功'); } else { $form->addError('', '资料更新失败'); } } return $this->render(Variable::$editProduct_view, ['model' => $form, 'productModel' => $productModel]); }
/** * Finds the Product model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Product the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Product::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionReviewCreate() { $model = new Review(); $products = Product::find()->where(['top' => Product::STATUS_TOP, 'category_id' => 1])->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->sendEmail('Новый Отзыв', 'review'); Yii::$app->session->addFlash('success', 'Спасибо за Ваш отзыв! Отзыв проходит модерацию.'); return $this->goHome(); } else { return $this->render('index', ['review' => $model, 'products' => $products]); } }
/** * @return \yii\db\ActiveQuery */ public function getProduct() { return $this->hasOne(Product::className(), ['id' => 'product_id']); }
/** * @return \yii\db\ActiveQuery */ public function getProducts() { return $this->hasMany(Product::className(), ['category_id' => 'id']); }