Example #1
0
 public function onBidData($event)
 {
     $row = $event->row;
     \Yii::info('[' . __METHOD__ . '] $row' . PHP_EOL . VarDumper::dumpAsString($row), 'kwater');
     $this->stdout(Console::renderColoredString("[KWATER] %g{$row['notinum']}%n [{$row['bidtype']}] {$row['constnm']} \n"));
     try {
         $bidkey = BidKey::find()->where(['whereis' => \kwater\Module::WHEREIS, 'notinum' => $row['notinum']])->orderBy('bidid desc')->limit(1)->one();
         if ($bidkey === null) {
             //------------------------------------
             // bid data save
             //------------------------------------
             $bidkey = new BidKey();
             $bidkey->bidid = date('ymd') . 'K' . str_replace('-', '', $row['notinum']) . '-00-00-01';
             $bidkey->notinum = $row['notinum'];
             $bidkey->whereis = \kwater\Module::WHEREIS;
             $bidkey->bidtype = $row['bidtype'];
             $bidkey->bidview = $row['bidview'];
             $bidkey->constnm = $row['constnm'];
             $bidkey->succls = $row['succls'];
             $bidkey->noticedt = $row['noticedt'];
             $bidkey->basic = $row['basic'];
             $bidkey->contract = $row['contract'];
             $bidkey->registdt = $row['registdt'];
             $bidkey->opendt = $row['opendt'];
             $bidkey->closedt = $row['closedt'];
             $bidkey->constdt = $row['constdt'];
             $bidkey->pqdt = $row['pqdt'];
             $bidkey->convention = $row['convention'];
             $bidkey->state = 'N';
             $bidkey->bidproc = 'B';
             $bidkey->writedt = date('Y-m-d H:i:s');
             $bidkey->editdt = date('Y-m-d H:i:s');
             $bidkey->org_i = $row['org_i'];
             $codeorg = CodeOrgI::findByOrgname($bidkey->org_i);
             if ($codeorg !== null) {
                 $bidkey->orgcode_i = $codeorg->org_Scode;
             }
             $bidkey->save();
             $bidvalue = new BidValue();
             $bidvalue->bidid = $bidkey->bidid;
             $bidvalue->yegatype = '25';
             $bidvalue->yegarng = '-2.5|2.5';
             $bidvalue->charger = $row['charger'];
             $bidvalue->multispare = $row['multispare'];
             $bidvalue->save();
             $bidcontent = new BidContent();
             $bidcontent->bidid = $bidkey->bidid;
             $bidcontent->orign_lnk = 'http://ebid.kwater.or.kr/fz?bidno=' . $row['notinum'];
             $bidcontent->attchd_lnk = $row['attchd_lnk'];
             $bidcontent->bidcomment = $row['bidcomment'];
             $bidcontent->save();
         }
         //-------------------------------
         // check bid modified
         //-------------------------------
         $bidcheck = BidModifyCheck::findOne($bidkey->bidid);
         if ($bidcheck === null) {
             $bidcheck = new BidModifyCheck(['bidid' => $bidkey->bidid]);
         }
         $bid_hash = md5(join('', $row));
         $noticeDoc = BidFile::findNoticeDoc($row['attchd_lnk']);
         if ($noticeDoc !== null && $noticeDoc->download()) {
             $file_hash = md5_file($noticeDoc->saveDir . '/' . $noticeDoc->savedName);
             $noticeDoc->remove();
         }
         if (!empty($bidcheck->bid_hash) and $bidcheck->bid_hash != $bid_hash) {
             $this->stdout(" > check : bid_hash diff\n", Console::FG_RED);
             $this->sendMessage("수자원공사 공고정보 확인필요! [{$row['notinum']}]");
         } else {
             if (!empty($bidcheck->file_hash) and $bidcheck->file_hash != $file_hash) {
                 $this->stdout(" > check : file_hash diff\n", Console::FG_RED);
                 $this->sendMessage("수자원공사 공고원문 확인필요! [{$row['notinum']}]");
             }
         }
         $bidcheck->bid_hash = $bid_hash;
         $bidcheck->file_hash = $file_hash;
         $bidcheck->check_at = time();
         $bidcheck->save();
     } catch (\Exception $e) {
         $this->stdout("{$e}\n", Console::FG_RED);
         \Yii::error($e, 'kwater');
     }
 }
 public function onRow($event)
 {
     $row = $event->row;
     $out[] = "[KWATER] [{$row['bidtype']}] %g{$row['notinum']}%n {$row['constnm']} ({$row['contract']},{$row['status']})";
     $bidkey = BidKey::find()->where(['whereis' => \kwater\Module::WHEREIS, 'notinum' => $row['notinum']])->orderBy('bidid desc')->limit(1)->one();
     if ($bidkey === null) {
         if (!ArrayHelper::isIn($row['status'], ['입찰완료', '적격신청', '결과발표']) and !ArrayHelper::isIn($row['contract'], ['지명경쟁', '수의계약(시담)'])) {
             $out[] = "%rNEW%n";
             $this->gman_client->doBackground('kwater_work_bid', Json::encode($row));
             $sleep = 1;
         }
     } else {
         $out[] = "({$bidkey->bidproc})";
         if ($bidkey->bidproc === 'B' and $bidkey->state === 'Y') {
             $bidcheck = BidModifyCheck::findOne($bidkey->bidid);
             if ($bidcheck === null) {
                 $out[] = "%yCHECK%n";
                 $this->gman_client->doBackground('kwater_work_bid', Json::encode($row));
             } else {
                 $diff = time() - $bidcheck->check_at;
                 if ($diff >= 60 * 60 * 1) {
                     $out[] = "%yCHECK%n";
                     $this->gman_client->doBackground('kwater_work_bid', Json::encode($row));
                     $bidcheck->check_at = time();
                     $bidcheck->save();
                     $sleep = 1;
                 }
             }
         }
     }
     $this->stdout(Console::renderColoredString(join(' ', $out)) . PHP_EOL);
     if (isset($sleep)) {
         sleep(3);
     }
 }