Exemple #1
0
 /**
  * Отклонение заявки
  * меняем статус, уведомляем исполнителя и менеджера и создаем новый bid (указание причины)
  * Проверен (21.12.15)
  */
 public function actionRefuse()
 {
     if (isset($_POST['bid_id'])) {
         $bid = Bid::findOne($_POST['bid_id']);
         if ($bid) {
             $bid->status = R::BID_REFUSED_BY_CLIENT;
             $bid->notify_status = R::NOTIFY_ACTIVE;
             $bid->save();
         }
         $feed = new Bid();
         $feed->name = 'Test';
         $feed->text = $_POST['text'];
         $feed->status = 0;
         $feed->user_id = Yii::$app->user->identity->id;
         $feed->obj_id = $bid->stage->id;
         $feed->bid_id = $bid->id;
         $feed->create_time = time();
         $feed->update_time = time();
         $feed->save();
         if ($feed->save()) {
             $feed->uploadFiles(Yii::$app->session['cs_' . Yii::$app->user->identity->id]);
             echo '1';
         }
     }
 }
 public function actionBid()
 {
     $request = Yii::$app->request;
     $user = Yii::$app->session->get('user');
     if (empty($user)) {
         echo json_encode(['status' => 0, 'message' => 'Wrong request'], JSON_PRETTY_PRINT);
         exit;
     }
     $inAuctionIds = [];
     $inAuctions = Auction::find()->select('id, seats')->where('start_time <= NOW() AND end_time > NOW()')->orderBy('start_time, end_time, type')->indexBy('id')->asArray()->all();
     foreach ($inAuctions as $auction) {
         array_push($inAuctionIds, $auction['id']);
     }
     $auctionToPrice = [];
     $bidSuccess = [];
     $priceCount = 0;
     $lang = Util::getLanguage();
     for ($i = 1; $i <= 3; $i++) {
         $auctionId = trim($request->post('auction' . $i));
         $price = trim($request->post('price' . $i));
         if (in_array($auctionId, $inAuctionIds) && is_numeric($price) && $price > 0) {
             $priceCount++;
             $auctionToPrice[$auctionId] = $price;
             $bidSuccess[$auctionId] = $lang == 'en' ? 'Late offer, unsuccessful!' : '被人抢先,提交失败!';
         }
     }
     $auctionIds = array_keys($auctionToPrice);
     $topOffers = $this->getTopOfferHash($auctionIds);
     $topWhacks = $this->getTopWhackHash($auctionIds);
     $myOffers = $this->getMyTopOfferHash($user->id, $auctionIds);
     $success = 0;
     foreach ($auctionToPrice as $tmpAuction => $tmpPrice) {
         if (!empty($myOffers[$tmpAuction]) && $tmpPrice <= $myOffers[$tmpAuction]['top']) {
             $bidSuccess[$tmpAuction] = $lang == 'en' ? 'Late offer, unsuccessful!' : '被人抢先,提交失败!';
             continue;
         }
         $query = new Query();
         $query->select('user_id, MAX(top_whack) top')->from('bid')->where(['auction_id' => $tmpAuction])->andWhere(['not', ['user_id' => $user->id]])->andWhere(['>=', 'top_whack', $tmpPrice])->groupBy('user_id')->indexBy('top');
         $bigWhacks = $query->all();
         krsort($bigWhacks);
         if (!empty($bigWhacks) && max(array_keys($bigWhacks)) == $tmpPrice) {
             $query = new Query();
             $query->select('top_whack, COUNT(*) count')->from('bid')->where(['auction_id' => $tmpAuction])->andWhere(['not', ['user_id' => $user->id]])->andWhere(['=', 'top_whack', $tmpPrice])->groupBy('top_whack')->orderBy(['top_whack' => SORT_DESC])->indexBy('top_whack');
             $whackList = $query->all();
             if ($whackList[$tmpPrice]['count'] < $inAuctions[$tmpAuction]['seats'] + 1) {
                 foreach ($bigWhacks as $whack) {
                     $bid = new Bid();
                     $bid->user_id = $whack['user_id'];
                     $bid->auction_id = $tmpAuction;
                     $bid->offer = $whack['top'];
                     $bid->top_whack = $whack['top'];
                     $bid->save();
                 }
                 $bid = new Bid();
                 $bid->user_id = $user->id;
                 $bid->auction_id = $tmpAuction;
                 $bid->offer = $tmpPrice;
                 $bid->top_whack = $tmpPrice;
                 $bid->save();
                 $bidSuccess[$tmpAuction] = $lang == 'en' ? 'Successful!' : '提交成功!';
                 $success++;
                 continue;
             }
         }
         foreach ($bigWhacks as $whack) {
             $bid = new Bid();
             $bid->user_id = $whack['user_id'];
             $bid->auction_id = $tmpAuction;
             $bid->offer = $tmpPrice;
             $bid->top_whack = $whack['top'];
             $bid->save();
         }
         $priceExist = Bid::find()->where(['auction_id' => $tmpAuction, 'offer' => $tmpPrice])->exists();
         if ($priceExist) {
             continue;
         }
         if (isset($topWhacks[$tmpAuction]) && isset($myOffers[$tmpAuction]) && $topWhacks[$tmpAuction]['top'] == $myOffers[$tmpAuction]['top']) {
             $bid = Bid::find()->where(['user_id' => $user->id])->andWhere(['auction_id' => $tmpAuction])->andWhere(['top_whack' => $myOffers[$tmpAuction]['top']])->one();
             $bid->top_whack = $tmpPrice;
             $bid->save();
             $bidSuccess[$tmpAuction] = $lang == 'en' ? 'Successful!' : '提交成功!';
             $success++;
         } else {
             if (empty($topOffers[$tmpAuction])) {
                 $offer = Yii::$app->params['auctionStep'];
             } else {
                 if ($topOffers[$tmpAuction]['top'] < $tmpPrice) {
                     $offer = $topOffers[$tmpAuction]['top'] + Yii::$app->params['auctionStep'];
                 } else {
                     //top >= price
                     $offer = $tmpPrice;
                 }
             }
             $bid = new Bid();
             $bid->user_id = $user->id;
             $bid->auction_id = $tmpAuction;
             $bid->offer = $offer;
             $bid->top_whack = $tmpPrice;
             $bid->save();
             $bidSuccess[$tmpAuction] = $lang == 'en' ? 'Successful!' : '提交成功!';
             $success++;
         }
     }
     $data = $bidSuccess;
     echo json_encode(compact('data', 'success'), JSON_PRETTY_PRINT);
     exit;
 }
Exemple #3
0
 /**
  * Отправка отчета менеджеру о выполнении поручения
  * создаем отчет, меняем статус поручения и уведомляем менеджера об отправки отчетности
  * Проверен (21.12.15)
  */
 public function actionSentAssign()
 {
     if (isset($_POST)) {
         $bid = new Bid();
         $bid->text = $_POST['text'];
         $bid->name = "Test";
         $bid->status = R::BID_SENT_TO_MANAGER;
         $bid->user_id = Yii::$app->user->identity->id;
         $bid->obj_id = $_POST['assignment_id'];
         $bid->bid_type = R::BID_ASSIGNMENT;
         $bid->notify_status = R::NOTIFY_ACTIVE;
         $bid->create_time = time();
         $bid->update_time = time();
         $bid->save();
         if ($bid->save()) {
             $bid->uploadFiles(Yii::$app->session['cs_' . Yii::$app->user->identity->id]);
             $assignment = Assignment::findOne($bid->obj_id);
             $assignment->status = R::ASSIGNMENT_PROCESS;
             $assignment->save();
             echo '1';
         }
     }
 }