Esempio n. 1
0
 public function run()
 {
     $w = new \GearmanWorker();
     $w->addServers($this->module->gman_server);
     $w->addFunction('kepco_work_suc2', function ($job) {
         try {
             $workload = Json::decode($job->workload());
             $this->stdout("%2%kkepco> [낙찰2] {$workload['id']} {$workload['no']} {$workload['name']}%n\n");
             $cookie = $this->module->redis_get('kepco.cookie');
             $token = $this->module->redis_get('kepco.token');
             $suc = new SucWorker2(['id' => $workload['id'], 'cookie' => $cookie, 'token' => $token]);
             $data = $suc->run();
             //print_r($data);
             $this->stdout(" > 공고번호 : {$data['notinum']}\n");
             $this->stdout(" > 예정가격 : {$data['yega']}\n");
             //$this->stdout(" > 복수예가 : {$data['multispare']}\n");
             $this->stdout(" > 1순위 : {$data['officenm1']}\n");
             $this->stdout(" > 참여수 : {$data['innum']}\n");
             $this->stdout(" > 진행상태 : {$data['bidproc']}\n");
             if (strlen($data['notinum']) < 10) {
                 return;
             }
             list($notino, $revno) = explode('-', $data['notinum']);
             if (preg_match('/^\\d{10}$/', $notino, $m)) {
                 $old_noti = substr($notino, 0, 4) . '-' . substr($notino, 4);
             } else {
                 $old_noti = substr($notino, 0, 3) . '-' . substr($notino, 3, 2) . '-' . substr($notino, 5);
             }
             $query = BidKey::find()->where(['whereis' => '03']);
             $query->andWhere("notinum like '{$old_noti}%' or notinum like '{$notino}%'");
             $bidkey = $query->orderBy('bidid desc')->limit(1)->one();
             if ($bidkey === null) {
                 return;
             }
             $data['bidid'] = $bidkey->bidid;
             $this->stdout(" > 개찰정보 저장 : {$bidkey->notinum} {$bidkey->constnm} ({$bidkey->state} {$bidkey->bidproc})\n");
             $this->module->gman_do('i2_auto_suc', Json::encode($data));
         } catch (\Exception $e) {
             $this->stdout("%r{$e}%n\n");
             \Yii::error($e, 'kepco');
         }
         $this->module->db->close();
         $this->memory_usage();
         sleep(1);
     });
     while ($w->work()) {
     }
 }
Esempio n. 2
0
 public function run()
 {
     while (true) {
         try {
             $cookie = $this->module->redis_get('kepco.cookie');
             $token = $this->module->redis_get('kepco.token');
             $suc = new SucWatcher(['cookie' => $cookie, 'token' => $token]);
             $suc->on('kepco-login', function ($event) {
                 $this->stdout(" > %g로그인을 요청합니다.%n\n");
                 $this->module->gman_talk("로그인을 요청합니다. 확인하십시요.", [142, 149, 150]);
             });
             $suc->watch(function ($row) {
                 $this->stdout("한전낙찰> %g[watcher]%n {$row['no']} {$row['revision']} {$row['name']}");
                 if (preg_match('/^\\d{10}$/', $row['no'], $m)) {
                     $old_noti = substr($row['no'], 0, 4) . '-' . substr($row['no'], 4);
                 } else {
                     if (preg_match('/^[A-Z]\\d{9}$/', $row['no'], $m)) {
                         $old_noti = substr($row['no'], 0, 3) . '-' . substr($row['no'], 3, 2) . '-' . substr($row['no'], 5);
                     } else {
                         $this->stdout(" %rERROR: {$row['no']}%n\n");
                         sleep(5);
                         return;
                     }
                 }
                 $noti = $row['no'];
                 $notinum = $row['no'] . '-' . $row['revision'];
                 $bidkey = BidKey::find()->where("notinum like '{$noti}%'")->andWhere(['whereis' => '03'])->orderBy('bidid desc')->limit(1)->one();
                 $oldBidkey = BidKey::find()->where("notinum like '{$old_noti}%'")->andWhere(['whereis' => '03'])->orderBy('bidid desc')->limit(1)->one();
                 if ($bidkey === null or $bidkey !== null and $oldBidkey !== null and (($bidkey->bidproc == 'S' or $bidkey->bidproc == 'F') and ($oldBidkey->bidproc != 'S' and $oldBidkey->bidproc != 'F')) or $bidkey !== null and $oldBidkey === null and ($bidkey->bidproc == 'S' or $bidkey->bidproc == 'F')) {
                     $this->stdout("\n");
                     return;
                 }
                 $this->stdout(" %yNEW%n\n");
                 $this->module->gman_do('kepco_work_suc', $row);
                 sleep(1);
             });
             // end watch()
         } catch (\Exception $e) {
             $this->stdout("%r{$e}%n\n");
             \Yii::error($e, 'kepco');
         }
         $this->module->db->close();
         $this->memory_usage();
         sleep(1);
     }
 }
Esempio n. 3
0
 public function actionSuc()
 {
     $this->i2_gman_func = 'i2_auto_suc';
     $w = new \GearmanWorker();
     $w->addServers($this->module->gman_server);
     $w->addFunction('kepco_work_suc', function ($job) {
         try {
             $workload = Json::decode($job->workload());
             $this->stdout2("kepco> %g[worker]%n {$workload['no']} {$workload['revision']} {$workload['name']} %g{$workload['id']}%n\n");
             $cookie = $this->module->redis_get('kepco.cookie');
             $token = $this->module->redis_get('kepco.token');
             if (preg_match('/^\\d{10}$/', $workload['no'], $m)) {
                 $old_noti = substr($workload['no'], 0, 4) . '-' . substr($workload['no'], 4);
             } else {
                 $old_noti = substr($workload['no'], 0, 3) . '-' . substr($workload['no'], 3, 2) . '-' . substr($workload['no'], 5);
             }
             $notinum = $workload['no'] . '-' . $workload['revision'];
             $worker = new SucWorker(['id' => $workload['id'], 'cookie' => $cookie, 'token' => $token]);
             $data = $worker->run();
             $notinum = $data['notinum'] . '-' . $data['revision'];
             list($noti, $revision) = explode('-', $notinum);
             $bidkey = BidKey::find()->where("notinum like '{$noti}%' or notinum like '{$old_noti}%'")->andWhere(['whereis' => '03'])->orderBy('bidid desc')->limit(1)->one();
             if ($bidkey === null) {
                 return;
             }
             if ($data['bidproc'] === null) {
                 return;
             }
             $this->stdout2(" %yNEW%n\n");
             $data['notinum'] = $notinum;
             $data['constnm'] = $bidkey['constnm'];
             $data['bidid'] = $bidkey['bidid'];
             $this->stdout2("%g > do {$this->i2_gman_func} {$data['bidid']} {$data['bidproc']}%n\n");
             $this->module->gman_do($this->i2_gman_func, Json::encode($data));
         } catch (\Exception $e) {
             $this->stdout2("%r{$e}%n\n");
             \Yii::error($e, 'kepco');
         }
         $this->module->db->close();
         $this->stdout2(sprintf("[%s] Peak memory usage: %sMb\n", date('Y-m-d H:i:s'), memory_get_peak_usage(true) / 1024 / 1024), Console::FG_GREY);
         sleep(1);
     });
     while ($w->work()) {
     }
 }
Esempio n. 4
0
 public function actionBid()
 {
     while (true) {
         try {
             $cookie = $this->module->redis_get('kepco.cookie');
             $token = $this->module->redis_get('kepco.token');
             $delay = new \kepco\watchers\DelayWatcher(['cookie' => $cookie, 'token' => $token]);
             $delay->on('kepco-login', function ($event) {
                 $this->stdout2(" > %g로그인을 요청합니다.%n\n");
                 $this->module->gman_talk("로그인을 요청합니다. 확인하십시요.", [142, 149, 150]);
             });
             $delay->watch(function ($row) {
                 $this->stdout2("%g한전입찰> [delay] {$row['no']} {$row['revision']} {$row['name']}\n");
                 if (preg_match('/^\\d{10}$/', $row['no'], $m)) {
                     $old_notinum = substr($row['no'], 0, 4) . '-' . substr($row['no'], 4);
                 } else {
                     $old_notinum = substr($row['no'], 0, 3) . '-' . substr($row['no'], 3, 2) . '-' . substr($row['no'], 5);
                 }
                 $query = BidKey::find()->where(['whereis' => '03'])->andWhere("notinum like '{$row['no']}%' or notinum like '{$old_notinum}%'");
                 $bidkey = $query->orderBy('bidid desc')->limit(1)->one();
                 if ($bidkey !== null) {
                     //입찰마감비교
                     $endDateTime = strtotime($row['endDateTime']);
                     $closedt = strtotime($bidkey->closedt);
                     if ($closedt < $endDateTime) {
                         $this->stdout2(" 입찰마감 : {$row['endDateTime']} != {$bidkey->closedt}\n");
                         $data['closedt'] = date('Y-m-d H:i:s', strtotime($row['endDateTime']));
                         $data['constdt'] = date('Y-m-d H:i:s', strtotime('+1 hour', strtotime($data['closedt'])));
                         if ($row['bidAttendRequestCloseDateTime']) {
                             $data['registdt'] = date('Y-m-d H:i:s', strtotime($row['bidAttendRequestCloseDateTime']));
                         }
                         $data['previd'] = $bidkey->bidid;
                         $data['bidproc'] = 'L';
                         $data['whereis'] = $bidkey->whereis;
                         $data['notinum'] = $bidkey->notinum;
                         $data['constnm'] = $bidkey->constnm;
                         $data['bidid'] = $bidkey->bidid;
                         $this->module->gman_do('i2_auto_bid', Json::encode($data));
                         sleep(1);
                     }
                 }
             });
             sleep(5);
             $bid = new BidWatcher(['cookie' => $cookie, 'token' => $token]);
             $bid->on('kepco-login', function ($event) {
                 $this->stdout2(" > %g로그인을 요청합니다.%n\n");
                 $this->module->gman_talk("로그인을 요청합니다. 확인하십시요.", [142, 149, 150]);
             });
             $bid->watch(function ($row) {
                 $this->stdout2("한전입찰> %g[watcher]%n {$row['no']} {$row['revision']} {$row['name']}");
                 $notinum = $row['no'];
                 if ($row['progressState'] == 'Close' || $row['progressState'] == 'OpenTimed' || $row['progressState'] == 'Fail' || $row['progressState'] == 'Final' && $row['resultState'] == 'Success' || $row['progressState'] == 'Final' && $row['resultState'] == 'Fail' || $row['progressState'] == 'Final' && $row['resultState'] == 'FailPrivate' || $row['progressState'] == 'Final' && $row['resultState'] == 'FailReRfx' || $row['progressState'] == 'Final' && $row['resultState'] == 'NotDetermined') {
                     $this->stdout("\n");
                     return;
                 }
                 if (preg_match('/^\\d{10}$/', $row['no'], $m)) {
                     $old_notinum = substr($row['no'], 0, 4) . '-' . substr($row['no'], 4);
                 } else {
                     $old_notinum = substr($row['no'], 0, 3) . '-' . substr($row['no'], 3, 2) . '-' . substr($row['no'], 5);
                 }
                 $bidkey = BidKey::find()->where("notinum like '{$notinum}%' or notinum like '{$old_notinum}%'")->andWhere(['whereis' => '03'])->orderBy('bidid desc')->limit(1)->one();
                 if ($bidkey !== null) {
                     if (($row['resultState'] === 'Cancel' or $row['noticeType'] === 'Cancel') and $bidkey->bidproc !== 'C') {
                         $this->stdout2("\n%g > 취소공고 입력을 요청합니다.%n\n");
                         $this->module->gman_do('kepco_work_bid', $row);
                         sleep(1);
                         return;
                     }
                     if (($row['revision'] > 1 or $row['noticeType'] === 'Correct') and $row['resultState'] !== 'Cancel') {
                         $p_notinum = str_replace('-', '', $bidkey->notinum);
                         if (strlen($p_notinum) === 10) {
                             $p_revision = 1;
                         } else {
                             $p_revision = substr($p_notinum, 10);
                         }
                         if ($p_revision < $row['revision']) {
                             $this->stdout2(" %yMODIFY%n\n");
                             $this->module->gman_do('kepco_work_bid', $row);
                             sleep(1);
                             return;
                         }
                     }
                     if ($row['noticeType'] === 'ReBidding' and $row['bidRevision'] > 1) {
                         list($a, $b, $c, $d) = explode('-', $bidkey->bidid);
                         if (intval($c) < $row['bidRevision']) {
                             $this->stdout2(" %yREBID%n\n");
                             $this->module->gman_do('kepco_work_bid', $row);
                             sleep(1);
                             return;
                         }
                     }
                     switch ($row['bidTypeCombine']) {
                         case '제한적최저가낙찰제':
                         case '제한적최저가':
                         case '적격심사(일반)':
                         case '적격심사(중소기업)':
                         case '적격심사낙찰제':
                             if (empty($bidkey->basic) or $bidkey->basic == 0) {
                                 $this->stdout2(" %yBASIC%n\n");
                                 $this->module->gman_do('kepco_work_basic', $row);
                                 sleep(1);
                                 return;
                             }
                     }
                     $this->stdout("\n");
                     //입찰마감비교
                     $endDateTime = strtotime($row['endDateTime']);
                     $closedt = strtotime($bidkey->closedt);
                     $interval = abs($endDateTime - $closedt);
                     if ($closedt != $endDateTime and $interval >= 3600 and $bidkey->state == 'Y') {
                         //if($closedt!=$endDateTime and $endDateTime-$closedt >=3600 and $bidkey->state=='Y'){
                         $this->stdout2("%y > {$row['endDateTime']} : {$bidkey->closedt}%n\n");
                         // 연기공고 없이 입찰마감일 변경됐을시에도 연기공고 처리 start (2016.10.05)
                         $data['closedt'] = date('Y-m-d H:i:s', strtotime($row['endDateTime']));
                         $data['constdt'] = date('Y-m-d H:i:s', strtotime('+1 hour', strtotime($data['closedt'])));
                         if ($row['bidAttendRequestCloseDateTime']) {
                             $data['registdt'] = date('Y-m-d H:i:s', strtotime($row['bidAttendRequestCloseDateTime']));
                         }
                         $data['previd'] = $bidkey->bidid;
                         $data['bidproc'] = 'L';
                         $data['whereis'] = $bidkey->whereis;
                         $data['notinum'] = $bidkey->notinum;
                         $data['constnm'] = $bidkey->constnm;
                         $data['bidid'] = $bidkey->bidid;
                         $this->module->gman_do('i2_auto_bid', Json::encode($data));
                         sleep(1);
                         // 연기공고 없이 입찰마감일 변경됐을시에도 연기공고 처리 end (2016.10.05)
                         //$bidkey->closedt=date('Y-m-d H:i:s',$endDateTime);
                         //$bidkey->constdt=date('Y-m-d H:i:s',strtotime('+1 hour',$endDateTime));
                         //$bidkey->save();
                         if (time() < $endDateTime) {
                             $msg = [];
                             $msg[] = "입찰마감일을 확인하세요.";
                             $msg[] = "공고번호 : {$bidkey->notinum}";
                             $msg[] = "한전=" . date('Y-m-d H:i:s', $endDateTime) . " / 인포=" . date('Y-m-d H:i:s', $closedt);
                             //if($row['purchaseType']!=='Product'){
                             $this->module->gman_talk(join("\n", $msg), [149, 155, 254, 150]);
                             //}
                         }
                     }
                     /*else if($closedt!=$endDateTime and $endDateTime-$closedt < 0 and $bidkey->state=='Y'){
                              $this->stdout2("%y > {$row['endDateTime']} : {$bidkey->closedt}%n\n");
                              
                     		// 연기공고 없이 입찰마감일 변경됐을시에도 연기공고 처리 start (2016.10.05)
                     		$data['closedt']=date('Y-m-d H:i:s',strtotime($row['endDateTime']));
                              $data['constdt']=date('Y-m-d H:i:s',strtotime('+1 hour',strtotime($data['closedt'])));
                              if($row['bidAttendRequestCloseDateTime']){
                                $data['registdt']=date('Y-m-d H:i:s',strtotime($row['bidAttendRequestCloseDateTime']));
                              }
                              $data['previd']=$bidkey->bidid;
                              $data['bidproc']='M';
                              $data['whereis']=$bidkey->whereis;
                              $data['notinum']=$bidkey->notinum;
                              $data['constnm']=$bidkey->constnm;
                              $data['bidid']=$bidkey->bidid;
                              $this->module->gman_do('i2_auto_bid',Json::encode($data));
                     		print_r($endDateTime-$closedt);
                              sleep(1);		
                     		// 연기공고 없이 입찰마감일 변경됐을시에도 연기공고 처리 end (2016.10.05)
                              //$bidkey->closedt=date('Y-m-d H:i:s',$endDateTime);
                              //$bidkey->constdt=date('Y-m-d H:i:s',strtotime('+1 hour',$endDateTime));
                              //$bidkey->save();
                              
                              if(time()<$endDateTime){
                                  $msg=[];
                                  $msg[]="입찰마감일을 확인하세요.";
                                  $msg[]="공고번호 : {$bidkey->notinum}";
                     				$msg[]="한전공고마감일이 앞으로 당겨졌습니다.";
                                  $msg[]="한전=".date('Y-m-d H:i:s',$endDateTime)." / 인포=".date('Y-m-d H:i:s',$closedt);
                                  //if($row['purchaseType']!=='Product'){
                                    $this->module->gman_talk(join("\n",$msg),[
                                      //149, //양정한
                                      //155, //박경찬
                                      //254, //김홍인
                     						150, //이광용
                                    ]);
                                  //}
                              } 
                                         
                            }*/
                     return;
                 }
                 if ($row['resultState'] === 'Cancel' or $row['noticeType'] === 'Cancel') {
                     $this->stdout2("\n%4 > 취소 전 공고가 없습니다.%n\n");
                     return;
                 }
                 $this->stdout2(" %yNEW%n\n");
                 $this->module->gman_do('kepco_work_bid', $row);
                 sleep(1);
             });
             // end watch()
         } catch (\Exception $e) {
             $this->stdout("{$e}\n", Console::FG_RED);
             \Yii::error($e, 'kepco');
         }
         $this->module->db->close();
         $this->memory_usage();
         sleep(1);
     }
 }
Esempio n. 5
0
 public function bid_b($data)
 {
     list($noti, $revision) = explode('-', $data['notinum']);
     if (preg_match('/^\\d{10}$/', $noti, $m)) {
         $old_noti = substr($noti, 0, 4) . '-' . substr($noti, 4);
     } else {
         $old_noti = substr($noti, 0, 3) . '-' . substr($noti, 3, 2) . '-' . substr($noti, 5, 5);
     }
     $query = BidKey::find()->where(['whereis' => '03'])->andWhere("notinum like '{$noti}%' or notinum like '{$old_noti}%'");
     $bidkey = $query->orderBy('bidid desc')->limit(1)->one();
     if ($bidkey === null) {
         $data['bidid'] = sprintf('%s%s-00-00-01', date('ymdHis'), str_pad(mt_rand(0, 999), 3, '0', STR_PAD_LEFT));
         $data['bidproc'] = 'B';
         $this->stdout("%g > do {$this->i2_func} {$data['bidid']} {$data['bidproc']}%n\n");
         $this->module->gman_do($this->i2_func, Json::encode($data));
         if (!empty($data['attchd_lnk'])) {
             $this->module->gman_doBack('kepco_file_download', ['bidid' => $data['bidid'], 'attchd_lnk' => $data['attchd_lnk']]);
         }
     }
 }
Esempio n. 6
0
 public function run()
 {
     while (true) {
         try {
             $cookie = $this->module->redis_get('kepco.cookie');
             $token = $this->module->redis_get('kepco.token');
             $suc = new Suc2Watcher(['cookie' => $cookie, 'token' => $token]);
             $suc->on('kepco-login', function ($event) {
                 $this->stdout(" > 로그인을 요청합니다.\n");
             });
             $query = BidKey::find()->where(['whereis' => '03', 'bidproc' => 'B', 'state' => 'Y', 'bidcls' => '01', 'succls' => ['01', '02', '03', '04', '05', '06']]);
             $date1 = date('Y-m-d', strtotime('-15 day'));
             $date2 = date('Y-m-d H:i:s');
             $query->andWhere(['between', 'constdt', $date1, $date2]);
             $rows = $query->all();
             foreach ($rows as $row) {
                 $this->stdout("%2%kkepco> [suc2watcher] {$row['notinum']} {$row['constnm']} {$row['constdt']}%n\n");
                 //{old
                 if (preg_match('/^[A-Z]\\d{2}-\\d{2}-\\d{5}/', $row['notinum'])) {
                     list($a, $b, $c) = explode('-', $row['notinum']);
                     $no = $a . $b . $c;
                 } else {
                     if (preg_match('/^\\d{4}-\\d{6}/', $row['notinum'])) {
                         list($a, $b) = explode('-', $row['notinum']);
                         $no = $a . $b;
                     } else {
                         list($a, $b) = explode('-', $row['notinum']);
                         $no = $a;
                     }
                 }
                 $info = $suc->search($no);
                 if ($info !== null) {
                     $this->stdout(" > {$info['progressState']} {$info['resultState']} {$info['no']} {$info['id']}\n");
                     switch ($info['resultState']) {
                         case 'Fail':
                         case 'FailPrivate':
                             $data['bidid'] = $row['bidid'];
                             $data['officenm1'] = '유찰';
                             $data['bidproc'] = 'F';
                             $this->stdout("%y > 유찰 : {$row['bidid']}%n\n");
                             $this->module->gman_do('i2_auto_suc', Json::encode($data));
                             continue 2;
                     }
                     switch ($info['progressState']) {
                         case 'Final':
                         case 'OpenTimed':
                             $this->stdout("%y > 개찰수집 : kepco_work_suc2 %n\n");
                             $this->module->gman_do('kepco_work_suc2', Json::encode($info));
                     }
                 }
                 sleep(5);
             }
             //end foreach
         } catch (\Exception $e) {
             $this->stdout("%r" . $e->getMessage() . "%n\n");
             \Yii::error($e, 'kepco');
         }
         $this->module->db->close();
         $this->memory_usage();
         sleep(30);
     }
 }