示例#1
0
 public function run()
 {
     DB::table('auctions')->delete();
     $collection = [];
     foreach ($collection as $record) {
         Auction::create($record);
     }
 }
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $model->scenario = 'create';
     if ($model->load(Yii::$app->request->post())) {
         $image1 = UploadedFile::getInstance($model, 'image1');
         if ($image1 != NULL) {
             $name1 = date('Y_m_d_H_i_s_') . $image1->baseName . '.' . $image1->extension;
             $model->image1 = $name1;
         }
         $image2 = UploadedFile::getInstance($model, 'image2');
         if ($image2 != NULL) {
             $name2 = date('Y_m_d_H_i_s_') . $image2->baseName . '.' . $image2->extension;
             $model->image2 = $name2;
         }
         $image3 = UploadedFile::getInstance($model, 'image3');
         if ($image3 != NULL) {
             $name3 = date('Y_m_d_H_i_s_') . $image3->baseName . '.' . $image3->extension;
             $model->image3 = $name3;
         }
         if ($model->save()) {
             if ($model->auction == "YES") {
                 $auction = new Auction();
                 $auction->product_id = $model->id;
                 $auction->value = $model->price;
                 $auction->save();
             }
             if ($image1 != NULL) {
                 $image1->saveAs('img/products/' . $name1);
             }
             if ($image2 != NULL) {
                 $image2->saveAs('img/products/' . $name2);
             }
             if ($image3 != NULL) {
                 $image3->saveAs('img/products/' . $name3);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#3
0
 public function actionWinner($id)
 {
     $auction = Auction::findOne($id);
     if ($auction) {
         $auction->status = 'INACTIVE';
         if ($auction->save()) {
             $return = $id . '-';
             if (!$auction->user_id) {
                 $return .= '/';
             } elseif ($auction->user_id == Yii::$app->user->id) {
                 $return .= '+';
             } else {
                 $return .= $auction->user_id;
             }
             echo $return;
         } else {
             echo "no save " . $id;
         }
     } else {
         echo "no auction " . $id;
     }
 }
示例#4
0
 public function getAuctions()
 {
     return $this->hasMany(Auction::className(), ['product_id' => 'id']);
 }
 public function actionRankList()
 {
     $user = Yii::$app->session->get('user');
     if (empty($user)) {
         echo json_encode(['status' => 0, 'message' => 'Wrong request'], JSON_PRETTY_PRINT);
         exit;
     }
     $request = Yii::$app->request;
     $auctionId = $request->post('auctionId');
     if (empty($auctionId)) {
         echo json_encode(['status' => 0, 'message' => 'Wrong params'], JSON_PRETTY_PRINT);
         exit;
     }
     $auction = Auction::find()->select('week, seats')->where(['id' => $auctionId])->limit(1)->one();
     $query = new Query();
     $rankInfoAry = $query->select('bid.offer, bid.created, `user`.family_name')->from('bid')->leftJoin('`user`', '`bid`.`user_id` = `user`.`id`')->where(['auction_id' => $auctionId])->orderBy(['bid.offer' => SORT_DESC, 'bid.id' => SORT_ASC])->all();
     $lang = Util::getLanguage();
     $view = $lang == 'en' ? 'rankList' : 'rankList-cn';
     Util::setLanguage($lang);
     return $this->render($view, compact('auction', 'rankInfoAry'));
 }
示例#6
0
 public function listOne($id)
 {
     //show single
     $auction = Auction::with($this->related)->findOrFail($id);
     return view('auctions.single', compact('auction'));
 }