Пример #1
0
 public function getV3BidValue()
 {
     return $this->hasOne(V3BidValue::className(), ['bidid' => 'bidid']);
 }
Пример #2
0
 public function i2conv_run($job)
 {
     $workload = $job->workload();
     $workload = Json::decode($workload);
     try {
         $this->module->i2db->close();
         $this->module->infodb->close();
         $bidKey = BidKey::findOne($workload['bidid']);
         if ($bidKey === null) {
             return;
         }
         $bidvalue = $bidKey->bidValue;
         if ($bidvalue === null) {
             return;
         }
         if (!ArrayHelper::isIn($bidKey->state, ['Y', 'N', 'D'])) {
             return;
         }
         if ($bidKey->bidproc === 'J') {
             return;
         }
         if (empty($bidKey->location)) {
             return;
         }
         switch ($bidKey->bidtype) {
             case 'con':
                 echo Console::renderColoredString('%y[공사]%n');
                 break;
             case 'ser':
                 echo Console::renderColoredString('%g[용역]%n');
                 break;
             case 'pur':
                 echo Console::renderColoredString('%b[구매]%n');
                 break;
             default:
                 return;
         }
         echo $bidKey->constnm;
         echo '[' . $bidKey->notinum . ']';
         echo '(' . $bidKey->state . ',' . $bidKey->bidproc . ')';
         //------------------------------------------------------
         // v3_bid_key
         //------------------------------------------------------
         $v3bidkey = V3BidKey::findNew($bidKey->bidid);
         $this->stdout($v3bidkey->isNewRecord ? "[NEW]\n" : "\n", Console::FG_RED);
         $v3bidkey->attributes = ['whereis' => $bidKey->whereis, 'bidtype' => $bidKey->bidtype, 'con' => strpos($bidKey->bidview, 'con') === false ? 'N' : 'Y', 'ser' => strpos($bidKey->bidview, 'ser') === false ? 'N' : 'Y', 'pur' => strpos($bidKey->bidview, 'pur') === false ? 'N' : 'Y', 'notinum' => $bidKey->notinum, 'orgcode' => $bidKey->orgcode_i, 'constnm' => $bidKey->constnm, 'org' => $bidKey->org_i, 'bidproc' => $bidKey->bidproc, 'contract' => $bidKey->contract, 'bidcls' => $bidKey->bidcls, 'succls' => $bidKey->succls, 'conlevel' => $bidKey->toV3BidKey_conlevel(), 'ulevel' => $bidKey->opt, 'concode' => $bidKey->toV3BidKey_concode(), 'sercode' => $bidKey->toV3BidKey_sercode(), 'purcode' => $bidKey->toV3BidKey_purcode(), 'location' => $bidKey->location ? $bidKey->location : 0, 'convention' => $bidKey->convention == '3' ? '2' : $bidKey->convention, 'presum' => $bidKey->presum ? $bidKey->presum : 0, 'basic' => $bidKey->basic ? $bidKey->basic : 0, 'pct' => $bidKey->pct ? $bidKey->pct : '', 'registdate' => strtotime($bidKey->registdt) > 0 ? date('Y-m-d', strtotime($bidKey->registdt)) : '', 'explaindate' => strtotime($bidKey->explaindt) > 0 ? date('Y-m-d', strtotime($bidKey->explaindt)) : '', 'agreedate' => strtotime($bidKey->agreedt) > 0 ? date('Y-m-d', strtotime($bidKey->agreedt)) : '', 'opendate' => strtotime($bidKey->opendt) > 0 ? date('Y-m-d', strtotime($bidKey->opendt)) : '', 'closedate' => strtotime($bidKey->closedt) > 0 ? date('Y-m-d', strtotime($bidKey->closedt)) : '', 'constdate' => strtotime($bidKey->constdt) > 0 ? date('Y-m-d', strtotime($bidKey->constdt)) : '', 'writedate' => strtotime($bidKey->writedt) > 0 ? date('Y-m-d', strtotime($bidKey->writedt)) : '', 'reswdate' => strtotime($bidKey->resdt) > 0 ? date('Y-m-d', strtotime($bidKey->resdt)) : '', 'state' => $bidKey->state, 'in_id' => 91];
         //------------------------------------------------------
         // v3_bid_value
         //------------------------------------------------------
         $v3BidValue = V3BidValue::findNew($v3bidkey->bidid);
         $v3BidValue->attributes = ['scrcls' => $bidvalue->scrcls, 'scrid' => $bidvalue->scrid, 'constno' => $bidvalue->constno, 'refno' => $bidvalue->refno, 'realorg' => $bidvalue->realorg, 'yegatype' => $bidvalue->yegatype, 'yegarng' => str_replace('|', '/', $bidvalue->yegarng), 'prevamt' => $bidvalue->prevamt, 'parbasic' => $bidvalue->parbasic, 'lvcnt' => $bidvalue->lvcnt, 'charger' => str_replace('|', '/', $bidvalue->charger), 'multispare' => str_replace('|', '/', str_replace(',', '', $bidvalue->multispare)), 'contper' => $bidvalue->contper, 'noticedt' => strtotime($bidKey->noticedt) > 0 ? strtotime($bidKey->noticedt) : 0, 'registdt' => strtotime($bidKey->registdt) > 0 ? strtotime($bidKey->registdt) : 0, 'explaindt' => strtotime($bidKey->explaindt) > 0 ? strtotime($bidKey->explaindt) : 0, 'agreedt' => strtotime($bidKey->agreedt) > 0 ? strtotime($bidKey->agreedt) : 0, 'opendt' => strtotime($bidKey->opendt) > 0 ? strtotime($bidKey->opendt) : 0, 'closedt' => strtotime($bidKey->closedt) > 0 ? strtotime($bidKey->closedt) : 0, 'constdt' => strtotime($bidKey->constdt) > 0 ? strtotime($bidKey->constdt) : 0, 'writedt' => strtotime($bidKey->writedt) > 0 ? strtotime($bidKey->writedt) : 0, 'editdt' => strtotime($bidKey->editdt) > 0 ? strtotime($bidKey->editdt) : 0];
         //공동도급지역코드 (사용하나??)
         $arr = explode('|', $bidvalue->contloc);
         foreach ($arr as $val) {
             if (empty($val)) {
                 continue;
             }
             $m = BidLocal::findOne(['bidid' => $v3bidkey->bidid, 'name' => iconv('utf-8', 'euckr', $val)]);
             if ($m !== null) {
                 $v3BidValue->contloc = $m->code;
                 break;
                 //v3_bid_key.contloc char(4) 때문 1개 지역만 처리...
             }
         }
         //------------------------------------------------------
         // v3_bid_itemcode
         //------------------------------------------------------
         V3BidItemcode::deleteAll(['bidid' => $v3bidkey->bidid]);
         $bidItemcodes = $bidKey->toV3BidItemcodes_attributes();
         foreach ($bidItemcodes as $row) {
             $v3BidItemcode = V3BidItemcode::findNew($v3bidkey->bidid, $row['bidtype'], $row['code']);
             $v3BidItemcode->name = $row['name'];
             $v3BidItemcode->save();
         }
         //------------------------------------------------------
         // v3_bid_local
         //------------------------------------------------------
         V3BidLocal::deleteAll(['bidid' => $v3bidkey->bidid]);
         $bidlocals = $bidKey->bidLocals;
         foreach ($bidlocals as $bidlocal) {
             $v3BidLocal = new V3BidLocal(['bidid' => $v3bidkey->bidid, 'code' => $bidLocal->code, 'name' => $bidLocal->name]);
             $v3BidLocal->save();
         }
         //------------------------------------------------------
         // v3_bid_subcode
         //------------------------------------------------------
         V3BidSubcode::deleteAll(['bidid' => $v3bidkey->bidid]);
         $subcodes = $bidKey->bidSubcodes;
         foreach ($subcodes as $subcode) {
             $v3BidSubcode = new V3BidSubcode(['bidid' => $v3bidkey->bidid, 'g2b_code' => $subcode->g2b_code, 'g2b_code_nm' => $subcode->g2b_code_nm, 'i2_code' => $subcode->i2_code, 'itemcode' => $subcode->itemcode, 'pri_cont' => $subcode->pri_cont, 'share' => $subcode->share]);
             $v3BidSubcode->save();
         }
         //-------------------------------------------------------
         // v3_bid_content
         //-------------------------------------------------------
         $bidcontent = $bidKey->bidContent;
         if ($bidcontent !== null) {
             $v3content = V3BidContent::findNew($v3bidkey->bidid);
             $v3content->attributes = ['content_bid' => $bidcontent->bid_html, 'important_suc' => $bidcontent->nbidcomment, 'content_suc' => $bidcontent->nbid_html, 'upfile_bid' => $bidcontent->bid_file, 'upfile_suc' => $bidcontent->nbid_file, 'important_bid' => !empty($bidcontent->bidcomment_mod) ? $bidcontent->bidcomment_mod . '\\n<hr/>\\n' . $bidcontent->bidcomment : $bidcontent->bidcomment];
             $v3content->save();
             $v3BidValue->origin_lnk = $bidcontent->orign_lnk;
             $v3BidValue->attchd_lnk = $bidcontent->attchd_lnk;
         }
         //-----------------------------------------------------
         // v3_bid_goods
         //-----------------------------------------------------
         $bidGoods = $bidKey->bidGoods;
         V3BidGoods::deleteAll(['bidid' => $v3bidkey->bidid]);
         foreach ($bidGoods as $g) {
             $v3BidGood = new V3BidGoods();
             $v3BidGood->attributes = $g->attributes;
             $v3BidGood->save();
         }
         //-------------------------------------------------------
         // v3_bid_res,v3_bid_succom
         //-------------------------------------------------------
         $bidRes = $bidKey->bidRes;
         if (ArrayHelper::isIn($bidKey->bidproc, ['S', 'F']) && $bidRes !== null) {
             $v3BidResult = V3BidResult::findNew($v3bidkey->bidid);
             $v3BidResult->attributes = ['yega' => $bidRes->yega, 'innum' => $bidRes->innum, 'officenm1' => $bidRes->officenm1, 'prenm1' => $bidRes->prenm1, 'officeno1' => $bidRes->officeno1, 'success1' => $bidRes->success1, 'resdt' => strtotime($bidKey->resdt) > 0 ? strtotime($bidKey->resdt) : 0, 'reswdt' => strtotime($bidRes->reswdt) > 0 ? strtotime($bidRes->reswdt) : 0];
             $arr = explode('|', $bidRes->selms);
             $selms = [];
             foreach ($arr as $v) {
                 if ($v == '') {
                     continue;
                 }
                 $selms[] = intval($v) - 1;
             }
             $v3BidResult->selms = implode('-', $selms);
             $v3BidResult->save();
             if ($bidKey->whereis != '08' && $bidKey->bidproc != 'F') {
                 $v3BidValue->multispare = str_replace('|', '/', str_replace(',', '', $bidRes->multispare));
             }
             $v3BidValue->save();
             if ($bidRes->innum > 0) {
                 $succoms = $bidKey->succoms;
                 if (count($succoms) == $bidRes->innum) {
                     V3BidSuccom::deleteAll(['constdate' => $v3bidkey->constdate, 'bidid' => $v3bidkey->bidid]);
                     Console::startProgress(0, $bidRes->innum);
                     $n = 1;
                     foreach ($succoms as $s) {
                         $v3succom = V3BidSuccom::findNew($v3bidkey->constdate, $v3bidkey->bidid, $s->seq);
                         $v3succom = new V3BidSuccom(['constdate' => $v3bidkey->constdate, 'bidid' => $v3bidkey->bidid, 'seq' => $s->seq, 'regdt' => strtotime($s->regdt) > 0 ? strtotime($s->regdt) : 0, 'pct' => $s->pct, 'prenm' => $s->prenm == null ? '' : $s->prenm, 'officenm' => $s->officenm, 'officeno' => $s->officeno, 'success' => $s->success, 'etc' => $s->etc, 'rank' => $s->rank]);
                         $v3succom->save();
                         Console::updateProgress($n, $bidRes->innum);
                         $n++;
                     }
                     Console::endProgress();
                 }
             }
         }
         $v3BidValue->save();
         $v3bidkey->save();
         $gman_client = new GearmanClient();
         $gman_client->addServers($this->module->gman_server);
         $gman_client->doBackground('i2conv_legacy', Json::encode($workload));
     } catch (\Exception $e) {
         echo Console::ansiFormat($e, [Console::FG_RED]), PHP_EOL;
         Yii::error($e, 'i2conv');
         $gman_client = new GearmanClient();
         $gman_client->addServers('192.168.1.242');
         $gman_client->doBackground('send_chat_message_from_admin', Json::encode(['recv_id' => 149, 'message' => iconv('cp949', 'utf-8', $e) . "\n[i2conv]"]));
     }
     $this->stdout(sprintf("[%s] Peak memory usage: %s MB\n", date('Y-m-d H:i:s'), memory_get_peak_usage(true) / 1024 / 1024), Console::FG_GREY);
 }
Пример #3
0
 private function update_old($v3key, $bidtype)
 {
     $workload = $this->_workload;
     if ($bidtype === 'con') {
         $keyClass = ConKey::className();
         $valClass = ConValue::className();
         $skeyClass = ConSucKey::className();
         $svalClass = ConSucValue::className();
         $succomClass = ConSucCom::className();
     } else {
         if ($bidtype === 'ser') {
             $keyClass = SerKey::className();
             $valClass = SerValue::className();
             $skeyClass = SerSucKey::className();
             $svalClass = SerSucValue::className();
             $succomClass = SerSucCom::className();
         } else {
             return;
         }
     }
     switch ($v3key->whereis) {
         case '03':
             $succomClass = KepcoSucCom::className();
             break;
         case '05':
             $succomClass = JuSucCom::className();
             break;
         case '10':
             $succomClass = DpaSucCom::className();
             break;
         case '52':
             $succomClass = KrSucCom::className();
             break;
     }
     list($bidno, $bidseq, $rebidno, $divno) = explode('-', $v3key->bidid);
     //----------------------------------------------
     // xxxKey
     //----------------------------------------------
     $v3val = $v3key->v3BidValue;
     $tkey = $keyClass::findNew($v3val->keyid);
     $tkey->attributes = ['item_code' => $v3key->concode, 'location' => $v3key->location, 'constname' => $v3key->constnm, 'organization' => $v3key->org, 'notinum' => $v3key->notinum, 'basic' => $v3key->basic, 'presum' => $v3key->presum, 'constdate' => $v3val->constdt, 'writedate' => $v3val->writedt, 'spot_explain' => $v3val->explaindt, 'ulevel' => $v3key->ulevel, 'in_id' => $v3key->in_id, 'state' => $v3key->state, 'pct' => $v3key->pct, 'level_cnt' => $v3val->lvcnt, 'org_code' => $v3key->orgcode, 'registdate' => $v3val->closedt];
     switch ($v3key->whereis) {
         case '01':
             $tkey->whereis = 'G2B';
             break;
         case '03':
             $tkey->whereis = 'KEPCO';
             break;
         case '08':
             $tkey->whereis = 'EX';
             break;
         case '10':
             $tkey->whereis = 'DPA';
             break;
         case '96':
             $tkey->whereis = 'KHNP';
             break;
         case '52':
             $tkey->whereis = 'KR';
             break;
         default:
             $tkey->whereis = $v3key->whereis;
     }
     switch ($v3key->whereis) {
         case '10':
         case '07':
         case '03':
         case '06':
         case '93':
             if ($v3val->registdt > 0) {
                 $tkey->registdate = $v3val->registdt;
             }
             break;
     }
     switch ($v3key->contract) {
         case '10':
             $tkey->contract_sys = '일반';
             break;
         case '20':
             $tkey->contract_sys = '제한';
             break;
         case '30':
             $tkey->contract_sys = '지명';
             break;
         case '40':
             $tkey->contract_sys = '수의';
             break;
         case '50':
             $tkey->contract_sys = '장기';
             break;
         case '60':
             $tkey->contract_sys = '복수경쟁';
             break;
         case '70':
             $tkey->contract_sys = '역경매';
             break;
         case '80':
             $tkey->contract_sys = '실적';
             break;
         default:
             $tkey->contract_sys = '';
     }
     $tkey->save();
     if ($v3val->keyid != $tkey->id) {
         $v3val->keyid = $tkey->id;
         $v3val->save();
     }
     //----------------------------------------------------
     // xxxValue
     //----------------------------------------------------
     $tval = $valClass::findNew($tkey->id);
     $tval->attributes = ['parent' => 0, 'sun' => 0, 'hyup_enddate' => $v3val->agreedt, 'selms' => '', 'original_link' => $v3val->origin_lnk, 'par_basic' => $v3val->parbasic, 'level_cnt' => $v3val->lvcnt, 'attatched_file_lnk' => $v3val->attchd_lnk, 'filename1' => '', 'filename2' => '', 'filename3' => ''];
     if ($v3key->whereis == '08') {
         $ms = explode('/', $v3val->multispare);
         foreach ($ms as $i => $m) {
             if ($i > 14) {
                 break;
             }
             $tval->{'multispare' . ($i + 1)} = $m;
         }
     }
     if (($v3key->ulevel & pow(2, 1)) > 0) {
         $prev = V3BidValue::find()->where("bidid like '{$bidno}%' and bidid<'{$v3key->bidid}'")->orderBy('bidid desc')->limit(1)->one();
         if ($prev !== null) {
             $tval->parent = $prev->keyid;
             $parent = $valClass::findOne($prev->keyid);
             if ($parent !== null) {
                 $parent->sun = $tval->id;
                 $parent->save();
             }
         }
     }
     $tval->save();
     $v3res = $v3key->v3BidResult;
     if ($v3res !== null and ArrayHelper::isIn($v3key->bidproc, ['S', 'F'])) {
         //--------------------------------------------------
         // xxxSucKey
         //--------------------------------------------------
         $tskey = $skeyClass::findNew($v3res->sucid);
         $tskey->attributes = ['item_code' => $tkey->item_code, 'location' => $tkey->location, 'constname' => $tkey->constname, 'organization' => $tkey->organization, 'notinum' => $tkey->notinum, 'contract_sys' => $tkey->contract_sys, 'basic' => $tkey->basic, 'presum' => $tkey->presum, 'registdate' => $tkey->registdate, 'org_code' => $tkey->org_code, 'level_cnt' => $tkey->level_cnt, 'par_basic' => $tkey->par_basic, 'pct' => $tkey->pct, 'constdate' => $tkey->constdate, 'ulevel' => $tkey->ulevel, 'yega' => $v3res->yega, 'success' => $v3res->success1, 'success_name' => $v3res->officenm1, 'writedate' => $v3res->reswdt, 'in_id' => $tkey->in_id, 'whereis' => $tkey->whereis, 'state' => $tkey->state];
         $tskey->save();
         if ($v3res->sucid != $tskey->id) {
             $v3res->sucid = $tskey->id;
             $v3res->save();
         }
         //-------------------------------------------------
         // xxxSucValue
         //-------------------------------------------------
         $tsval = $svalClass::findNew($tskey->id);
         $tsval->attributes = ['selms' => $v3res->selms, 'original_link' => '', 'filename1' => $tval->filename1, 'filename2' => $tval->filename2, 'filename3' => $tval->filename3];
         $ms = explode('/', $v3val->multispare);
         foreach ($ms as $i => $m) {
             if ($i > 14) {
                 break;
             }
             $tsval->{'multispare' . ($i + 1)} = $m;
         }
         $tsval->save();
         //--------------------------------------------------
         // xxxSucCom
         //--------------------------------------------------
         $succomClass::deleteAll(['id' => $tskey->id]);
         KepcoSucCom::deleteAll(['id' => $tskey->id, 'bidtype' => $bidtype]);
         JuSucCom::deleteAll(['id' => $tskey->id]);
         DpaSucCom::deleteAll(['id' => $tskey->id, 'bidtype' => $bidtype]);
         KrSucCom::deleteAll(['id' => $tskey->id]);
         $succoms = V3BidSuccom::findAll(['constdate' => $v3key->constdate, 'bidid' => $v3key->bidid]);
         $innum = count($succoms);
         $n = 1;
         Console::startProgress(0, $innum);
         foreach ($succoms as $s) {
             $tsuccom = null;
             switch ($v3key->whereis) {
                 case '03':
                     $tsuccom = new KepcoSucCom(['id' => $tskey->id, 'bidtype' => $bidtype, 'seq' => $s->seq, 'officeno' => $s->officeno, 'officename' => $s->officenm, 'pre_name' => $s->prenm, 'success' => $s->success, 'pct' => $s->pct]);
                     break;
                 case '05':
                     if ($bidtype === 'con') {
                         $tsuccom = new JuSucCom(['id' => $tskey->id, 'officeno' => $s->officeno, 'officename' => $s->officenm, 'pre_name' => $s->prenm, 'rank' => $s->rank, 'success' => $s->success, 'pct' => $s->pct, 'result' => $s->etc]);
                     }
                     break;
                 case '10':
                     $tsuccom = new DpaSucCom(['id' => $tskey->id, 'bidtype' => $bidtype, 'officecode' => $s->officeno, 'seq' => $s->seq, 'officeno' => $s->officeno, 'officename' => $s->officenm, 'pre_name' => $s->prenm, 'success' => $s->success, 'pct' => $s->pct, 'result' => $s->etc]);
                     break;
                 case '52':
                     if ($bidtype === 'con') {
                         $tsuccom = new KrSucCom(['id' => $tskey->id, 'officeno' => $s->officeno, 'officename' => $s->officenm, 'pre_name' => $s->prenm, 'rank' => $s->rank, 'success' => $s->success, 'pct' => $s->pct]);
                     }
                     break;
                 default:
                     $tsuccom = new $succomClass(['id' => $tskey->id, 'officeno' => $s->officeno, 'officename' => $s->officenm, 'pre_name' => $s->prenm, 'rank' => $s->rank, 'success' => $s->success, 'pct' => $s->pct]);
             }
             if ($tsuccom !== null) {
                 $tsuccom->save();
             }
             Console::updateProgress($n, $innum);
             $n++;
         }
         Console::endProgress();
     }
 }