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); }
private function update_pur($v3key) { $workload = $this->_workload; if (empty($v3key->writedate) or $v3key->writedate == '0000-00-00') { return; } $v3val = $v3key->v3BidValue; $keyid = $v3val->keyid; list($bidno, $bidseq, $rebidno, $divno) = explode('-', $v3key->bidid); $subseq = intval($bidseq); $pm = PurMaster::findOne(['id' => $keyid, 'subseq' => $subseq]); if ($pm === null or $keyid == 0) { $pm = new PurMaster(); $idstart = str_replace('-', '', $v3key->writedate); $idstart . '0000'; $id = (new Query())->from('pur_master')->where("id > :idstart", [':idstart' => $idstart])->max('id', PurMaster::getDb()); if (empty($id)) { $id = $idstart; } $pm->id = $id + 1; $pm->subseq = $subseq; } $pm->attributes = ['notinum' => $v3key->notinum, 'constname' => $v3key->constnm, 'org' => $v3key->org, 'gesi_dt' => $v3val->noticedt, 'explain_dt' => $v3val->explaindt, 'ibchalgesi_dt' => $v3val->opendt, 'ibchalmagam_dt' => $v3val->closedt, 'ibchal_dt' => $v3val->constdt, 'chamgamagam_dt' => $v3val->registdt, 'write_dt' => $v3val->writedt, 'presum' => $v3key->presum, 'basic' => $v3key->basic, 'pct' => $v3key->pct, 'itemcode' => $v3key->purcode, 'location' => $v3key->location, 'state' => $v3key->state, 'register' => 'i2conv', 'islast' => 'Y', 'org_code' => $v3key->orgcode]; if (empty($pm->chamgamagam_dt) or $v3key->whereis === '01') { $pm->chamgamagam_dt = $pm->ibchalmagam_dt; } switch ($v3key->contract) { case '10': $pm->constract = '일반'; break; case '20': $pm->constract = '제한'; break; case '40': $pm->constract = '수의'; break; case '70': $pm->constract = '역경매'; break; case '80': $pm->constract = '실적'; break; default: $pm->constract = ''; } switch ($v3key->bidcls) { case '00': $pm->ibchalbangsik = '직찰'; break; case '01': $pm->ibchalbangsik = '전자입찰'; break; default: $pm->ibchalbangsik = ''; } $cmtopts = []; if (($v3key->ulevel & pow(2, 2)) > 0) { $cmtopts[] = '긴급'; } if (($v3key->ulevel & pow(2, 11)) > 0) { $cmtopts[] = '관내'; } $pm->commentoption = implode(',', $cmtopts); switch ($v3key->bidproc) { case 'B': $pm->dataprocess = 'GEN'; break; case 'C': $pm->dataprocess = 'CANCEL'; break; default: $pm->dataprocess = 'MOD'; } if (!ArrayHelper::isIn($v3key->bidproc, ['S', 'F']) && intval($rebidno) > 0) { $pm->isjeibchal = 'Y'; } switch ($v3key->whereis) { case '01': $pm->whereis = 'G2B'; break; case '08': $pm->whereis = 'EX'; break; case '03': $pm->whereis = 'KEPCO'; break; case '10': $pm->whereis = 'DPA'; break; case '96': $pm->whereis = 'KHNP'; break; case '52': $pm->whereis = 'KR'; break; default: $pm->whereis = 'ETC'; } $v3bidgoods = V3BidGoods::findAll(['bidid' => $v3key->bidid]); $pm->goods_cnt = count($v3bidgoods); $v3bidlocals = $v3key->v3BidLocals; $lockeywords = []; foreach ($v3bidlocals as $v3bidlocal) { $a = explode(' ', $v3bidlocal->name); $lockeywords[] = array_pop($a); } $pm->lockeyword = implode(',', $lockeywords); $pm->save(); $v3ctn = $v3key->v3BidContent; //---------------------------------------------- // pur_file_data //---------------------------------------------- $pfd = $pm->purFileData; if ($pfd === null) { $pfd = new PurFileData(['id' => $pm->id, 'subseq' => $pm->subseq]); } if ($v3ctn !== null) { $pfd->attributes = ['filedata1' => $v3ctn->upfile_bid, 'jungjungdata' => $v3ctn->important_bid, 'maincontents' => $v3ctn->content_bid, 'openbid_contents' => $v3ctn->content_suc]; } $pfd->urlinfo1 = $v3val->origin_lnk; $pfd->linkdata = $v3val->attchd_lnk; $pfd->save(); //---------------------------------------------- // pur_g2b_goods //---------------------------------------------- $v3goods = $v3key->v3BidGoods; foreach ($v3goods as $g) { $pgg = PurG2bGoods::findOne(['notinum' => $v3key->notinum, 'bunryu_no' => 1, 'sunbun_no' => $g->seq]); if ($pgg === null) { $pgg = new PurG2bGoods(['notinum' => $v3key->notinum, 'bunryu_no' => 1, 'sunbun_no' => $g->seq]); } $pgg->attributes = ['info_code' => 0, 'info_name' => '', 'g2b_code' => $g->gcode, 'g2b_myung' => $g->gname]; $pgg->save(); } //--------------------------------------------- // pur_res //--------------------------------------------- $v3res = $v3key->v3BidResult; if ($v3res !== null and ArrayHelper::isIn($v3key->bidproc, ['R', 'S', 'F'])) { $pres = PurRes::findOne(['id' => $pm->id, 'notinum' => $pm->notinum, 'bunryuno' => 1]); if ($pres === null) { $pres = new PurRes(['id' => $pm->id, 'notinum' => $pm->notinum, 'bunryuno' => 1]); } $pres->attributes = ['jeibchal_bunho' => intval($rebidno), 'rs_selected_num' => $v3res->selms, 'rs_gechal_ilsi' => $v3res->resdt, 'yega' => $v3res->yega, 'gichoamt' => $v3key->basic]; switch ($v3key->bidproc) { case 'R': $pres->process = 'REBID'; break; case 'F': $pres->process = 'YUCHAL'; break; default: $pres->process = 'DONE'; } $ms = explode('/', $v3val->multispare); if (isset($ms[0])) { $pres->rs_yega1 = $ms[0]; } if (isset($ms[1])) { $pres->rs_yega2 = $ms[1]; } if (isset($ms[2])) { $pres->rs_yega3 = $ms[2]; } if (isset($ms[3])) { $pres->rs_yega4 = $ms[3]; } if (isset($ms[4])) { $pres->rs_yega5 = $ms[4]; } if (isset($ms[5])) { $pres->rs_yega6 = $ms[5]; } if (isset($ms[6])) { $pres->rs_yega7 = $ms[6]; } if (isset($ms[7])) { $pres->rs_yega8 = $ms[7]; } if (isset($ms[8])) { $pres->rs_yega9 = $ms[8]; } if (isset($ms[9])) { $pres->rs_yega10 = $ms[9]; } if (isset($ms[10])) { $pres->rs_yega11 = $ms[10]; } if (isset($ms[11])) { $pres->rs_yega12 = $ms[11]; } if (isset($ms[12])) { $pres->rs_yega13 = $ms[12]; } if (isset($ms[13])) { $pres->rs_yega14 = $ms[13]; } if (isset($ms[14])) { $pres->rs_yega15 = $ms[14]; } switch ($v3key->bidproc) { case 'F': case 'S': $pm->sucprocess = 'Y'; break; case 'R': $pm->isjeibchal = 'Y'; break; } $pm->successamt = $v3res->success1; $pm->successname = $v3res->officenm1; $pres->save(); if ($v3key->bidproc === 'S') { $v3succoms = V3BidSuccom::findAll(['constdate' => $v3key->constdate, 'bidid' => $v3key->bidid]); PurResEnterprise::deleteAll(['id' => $pm->id]); $innum = count($v3succoms); $n = 1; Console::startProgress(0, $innum); foreach ($v3succoms as $s) { $pen = new PurResEnterprise(['id' => $pm->id, 'saupja_bunho' => $s->officeno, 'notinum' => $pm->notinum, 'sunwi' => $s->rank, 'upche_myung' => $s->officenm, 'depyoja' => $s->prenm, 'tuchal_gumek' => $s->success, 'tuchal_ryul' => $s->pct, 'bigo' => $s->etc, 'bunryuno' => 1]); $pen->save(); Console::updateProgress($n, $innum); $n++; } Console::endProgress(); } } if ($v3val->keyid != $pm->id) { $v3val->keyid = $pm->id; $v3val->save(); } }