当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::findOne方法代码示例

本文整理汇总了PHP中common\models\Product::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::findOne方法的具体用法?PHP Product::findOne怎么用?PHP Product::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\Product的用法示例。


在下文中一共展示了Product::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateTrans

 /**
  * @brief 根据用户的输入产生交易记录
  *
  * @return  public function 
  * @retval   
  * @see 
  * @note 
  * @author 吕宝贵
  * @date 2015/12/19 20:39:07
  **/
 public function generateTrans()
 {
     $product = Product::findOne(['pid' => $this->booking->pid]);
     $buyerAccount = Yii::$app->account->getUserAccount(Yii::$app->user->identity['uid']);
     //根据booking_id生成交易记录
     $trans = new Trans();
     $trans->pay_mode = Trans::PAY_MODE_VOUCHPAY;
     $trans->trans_type_id = Trans::TRANS_TYPE_TRADE;
     $trans->currency = 1;
     $trans->total_money = $this->booking->price_final;
     $trans->profit = $this->booking->price_for_platform;
     $trans->money = $trans->total_money - $trans->profit;
     //保证金,目前还没有上
     //$trans->earnest_money = $this->booking->earnest_money;
     $trans->trans_id_ext = $this->booking_id;
     $trans->from_uid = $buyerAccount->uid;
     $trans->to_uid = $this->booking->hug_uid;
     $trans->status = Trans::PAY_STATUS_WAITPAY;
     //1为等待支付状态
     if ($trans->save()) {
         return $trans;
     } else {
         $this->addErrors($trans->getErrors());
         return false;
     }
 }
开发者ID:lubaogui,项目名称:yii2-account,代码行数:36,代码来源:PayForm.php

示例2: actionProductpic

 /**
  * 上传商品图片
  */
 public function actionProductpic()
 {
     $user_id = \Yii::$app->user->getId();
     $p_params = Yii::$app->request->get();
     $product = Product::findOne($p_params['id']);
     if (!$product) {
         throw new NotFoundHttpException(Yii::t('app', 'Page not found'));
     }
     $picture = new UploadForm();
     $picture->file = UploadedFile::getInstance($product, 'product_s_img');
     if ($picture->file !== null && $picture->validate()) {
         Yii::$app->response->getHeaders()->set('Vary', 'Accept');
         Yii::$app->response->format = Response::FORMAT_JSON;
         $response = [];
         if ($picture->productSave()) {
             $response['files'][] = ['name' => $picture->file->name, 'type' => $picture->file->type, 'size' => $picture->file->size, 'url' => '/' . $picture->getImageUrl(), 'thumbnailUrl' => '/' . $picture->getOImageUrl(), 'deleteUrl' => Url::to(['/uploadfile/deletepropic', 'id' => $picture->getID()]), 'deleteType' => 'POST'];
         } else {
             $response[] = ['error' => Yii::t('app', '上传错误')];
         }
         @unlink($picture->file->tempName);
     } else {
         if ($picture->hasErrors()) {
             $response[] = ['error' => '上传错误'];
         } else {
             throw new HttpException(500, Yii::t('app', '上传错误'));
         }
     }
     return $response;
 }
开发者ID:uqiauto,项目名称:wxzuan,代码行数:32,代码来源:UploadfileController.php

示例3: actionView

 public function actionView($slug)
 {
     $productModel = new Product();
     $productData = $productModel->findOne(['slug' => $slug]);
     $relatedProduct = $productModel->find()->where(['category_id' => $productData->category_id])->andWhere(['<>', 'id', $productData->id])->limit(9)->orderBy(['id' => SORT_ASC])->all();
     return $this->render('view', ['node' => $productData, 'relateNodes' => $relatedProduct]);
 }
开发者ID:nguyentuansieu,项目名称:phutungoto,代码行数:7,代码来源:ProductController.php

示例4: findModel

 /**
  * 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.');
     }
 }
开发者ID:phpsong,项目名称:ExtJS5-Yii2,代码行数:15,代码来源:ProductController.php

示例5: actionUpdate

 public function actionUpdate($id, $quantity)
 {
     $product = Product::findOne($id);
     if ($product) {
         \Yii::$app->cart->update($product, $quantity);
         $this->redirect(['cart/list']);
     }
 }
开发者ID:ibrarturi,项目名称:yii2-shop,代码行数:8,代码来源:CartController.php

示例6: findById

 public function findById($id)
 {
     if (($model = Product::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('请求页面不存在');
     }
 }
开发者ID:xiaomige,项目名称:giishop,代码行数:8,代码来源:ProductServiceImpl.php

示例7: findModel

 /**
  * Finds the Product model based on its slug.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $slug
  * @return Product the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($slug)
 {
     if (($model = Product::findOne(['slug' => $slug])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('frontend', 'The requested page does not exist.'));
     }
 }
开发者ID:cyanofresh,项目名称:yii2shop,代码行数:15,代码来源:CatalogController.php

示例8: actionRemove

 /**
  * Remove a product from the cart.
  * @param $id
  * @throws NotFoundHttpException
  */
 public function actionRemove($id)
 {
     $model = Product::findOne($id);
     if ($model) {
         \Yii::$app->cart->remove($model);
         $this->redirect(['index']);
     }
     throw new NotFoundHttpException();
 }
开发者ID:Krinnerion,项目名称:shop,代码行数:14,代码来源:CartController.php

示例9: getModel

 public function getModel($id)
 {
     $product = Product::findOne($id);
     if (!$product) {
         throw new NotFoundHttpException(Yii::t('app', 'specify product could not be found.'));
     } else {
         return $product;
     }
 }
开发者ID:su-xiaolin,项目名称:ICShop-Yii,代码行数:9,代码来源:ProductController.php

示例10: actionDetail

 public function actionDetail($id)
 {
     $product = Product::findOne(['prod_id' => $id]);
     //        echo '<pre>';
     //        print_r(Product::getMetaByName('color'));exit;
     //echo '<pre>';
     //        print_r($product->getProductImg('color')); exit;
     return $this->render('detail', ['prod' => $product]);
 }
开发者ID:syedmaaz,项目名称:marxmall-,代码行数:9,代码来源:SearchController.php

示例11: actionUpdate

 public function actionUpdate($id)
 {
     $model = Product::findOne($id);
     if ($model->load(\Yii::$app->request->post())) {
         if ($model->validate() && $model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('form', ['model' => $model]);
 }
开发者ID:afernandes465,项目名称:fafediesel,代码行数:10,代码来源:ProductController.php

示例12: actionToggle

 public function actionToggle()
 {
     $id = Yii::$app->request->post('id');
     if (($product = Product::findOne(['id' => $id])) && !$this->user->hasWish($id)) {
         $this->user->addWish($product);
         return ['status' => 'added'];
     } else {
         $this->user->removeWish($product);
         return ['status' => 'removed'];
     }
 }
开发者ID:ninetor,项目名称:yii-classifield,代码行数:11,代码来源:WishListController.php

示例13: actionProduct

 public function actionProduct($id)
 {
     if ($id) {
         $product = Product::findOne(['id' => $id]);
         if ($product === NULL) {
             throw new NotFoundHttpException("Товар № {$id} не найден");
         }
         $this->getView()->title = "Mexanika 74 - Каталог техники: " . $product->name;
         return $this->render('product_item', ['product' => $product]);
     }
 }
开发者ID:phpsong,项目名称:ExtJS5-Yii2,代码行数:11,代码来源:SiteController.php

示例14: actionDelete

 /**
  * @param $id
  * @return array
  * @throws NotFoundHttpException
  * @throws InvalidParamException
  */
 public function actionDelete($id)
 {
     $image = Image::findOne($id);
     $filePath = $image->getPathToOrigin();
     if (!$image) {
         throw new NotFoundHttpException('Image not found');
     }
     $product = Product::findOne($image->itemId);
     if (!$product) {
         throw new NotFoundHttpException('Product not found');
     }
     $product->removeImage($image);
     if (file_exists($filePath)) {
         return ['error' => 'Ошибка удаления файла'];
     } else {
         Yii::$app->getResponse()->setStatusCode(204);
     }
 }
开发者ID:andreykluev,项目名称:yii2-catalog-module,代码行数:24,代码来源:ImageController.php

示例15: actionDeleteAvatar

 /**
  * @return string
  */
 public function actionDeleteAvatar()
 {
     $imageData = Json::decode(Yii::$app->request->post('imageData'));
     $modelImageForm = new ImageForm();
     $modelImageForm->deleteImage();
     if (Yii::$app->session->get('error')) {
         echo $error = Yii::$app->session->get('error');
     } else {
         $error = false;
     }
     /* @var $model \common\models\Profile */
     if ($imageData['modelName'] == 'Carousel') {
         $model = Carousel::findOne($imageData['object_id']);
     } elseif ($imageData['modelName'] == 'Product') {
         $model = Product::findOne($imageData['object_id']);
     }
     $imagesObject = $model->imagesOfObjects;
     return $this->render('@common/widgets/ImageLoad/views/_formAutoload', ['modelName' => $imageData['modelName'], 'id' => $imageData['id'], 'object_id' => $imageData['object_id'], 'images_num' => $imageData['images_num'], 'images_label' => $imageData['images_label'], 'images_temp' => $imageData['images_temp'], 'imageSmallWidth' => $imageData['imageSmallWidth'], 'imageSmallHeight' => $imageData['imageSmallHeight'], 'imagesObject' => $imagesObject, 'modelImageForm' => $modelImageForm, 'baseUrl' => $imageData['baseUrl'], 'imagePath' => $imageData['imagePath'], 'noImage' => $imageData['noImage'], 'imageClass' => $imageData['imageClass'], 'buttonDeleteClass' => $imageData['buttonDeleteClass'], 'imageContainerClass' => $imageData['imageContainerClass'], 'formImagesContainerClass' => $imageData['formImagesContainerClass'], 'error' => $error]);
 }
开发者ID:baranov-nt,项目名称:some-2,代码行数:22,代码来源:ImagesController.php


注:本文中的common\models\Product::findOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。