function rsync($password = null) { $mssql = new PDO("odbc:Driver={SQL Server};Server=10.7.17.92;Database=GTA_QIA_QDB;", 'funddev', '123456789Aa'); $rs = $mssql->query("SELECT TOP 20 * FROM [DBO].[NEWS_NEWSINFO] ORDER BY UPDATEID DESC"); $data = $rs->fetchAll(PDO::FETCH_ASSOC); $ret = array(); foreach ($data as $item) { $updateId = iconv("GBK", "UTF-8", $item['UPDATEID']); $title = iconv("GBK", "UTF-8", $item['TITLE']); $summary = iconv("GBK", "UTF-8", $item['NEWSSUMMARY']); $content = iconv("GBK", "UTF-8", $item['NEWSCONTENT']); $declareDate = iconv("GBK", "UTF-8", $item['DECLAREDATE']); $sql = "INSERT INTO SIMU (UPDATEID,TITLE,SUMMARY,CONTENT,DECLAREDATE) VALUES({$updateId},'{$title}','{$summary}','{$content}','{$declareDate}') ON DUPLICATE KEY UPDATE DECLAREDATE='{$declareDate}' "; $ret[] = DB::runSql($sql); } echo implode(',', $ret) . PHP_EOL; }
private function toDb($result) { foreach ($result as $name => $item) { foreach ($item as $code) { $origin = DB::getLine("SELECT * FROM `invest_product` WHERE code='{$code}'"); $comments = explode(',', $origin['comment']); $comments = array_filter($comments, function ($value) { return trim($value); }); if (!in_array($name, $comments) && !empty($origin)) { $comments[] = $name; $comments = implode(',', $comments); $sql = "UPDATE `invest_product` SET comment='{$comments}' WHERE code ='{$code}' "; $ret = DB::runSql($sql); self::log("Updated {$code},Result:{$ret}"); } else { self::log("Code {$code} Already Update-To-Date"); } } } }
/** * 计算基金的万分收益 * range=前一天的unit*100% * !!!!!!已弃用 */ function range2() { $sql = "SELECT DISTINCT `code` FROM `fund_value` WHERE `range` ='' ORDER BY `code`"; $code = DB::getData($sql); self::log('total num ' . count($code)); $fillINDEX = array(); foreach ($code as $c) { $c = $c['code']; $sql = "SELECT id,`range`,unit FROM `fund_value` WHERE `code`='{$c}' ORDER BY create_date"; $data = DB::getData($sql); $id = $this->tryFillIndex($data, $c); if ($id && is_numeric($id)) { $fillINDEX[] = $id; } } if (!empty($fillINDEX)) { $str = implode(',', $fillINDEX); $sql = "UPDATE `fund_value` SET `range`='0.00%' WHERE id IN ({$str}) and `range`='' "; $ret = DB::runSql($sql); self::log('fill index num ' . count($fillINDEX) . ' result: ' . $ret); } self::log('finished'); }
public function bonusfix_for_one_per() { $symbol = "000574"; $i = $j = 0; $sql = "SELECT * FROM `fund_bonus` where code = '{$symbol}'"; var_dump($sql); $data = DB::getData("SELECT * FROM `fund_bonus` where code = '{$symbol}'"); foreach ($data as $item) { var_dump($item); $id = $item['id']; $bonus = $item['bonus']; $oldPer = $item['per']; if (preg_match_all('/.*?10.*?([\\d\\.]+)/', $bonus, $matches)) { $tmp = $matches[1][0]; $per = round($tmp / 10, 4); if ($per == 0) { exit("Zero Found {$per} {$id}"); } if ($oldPer != $per) { $i++; DB::runSql("UPDATE `fund_bonus` SET `per`='{$per}' WHERE id={$id}"); self::log("{$id} FIXED {$oldPer}=>{$per}"); } else { $j++; self::log("{$id} IS ALREADY NEW"); } } else { exit("not Match {$id}"); } } $num = count($data); self::log("FIXED {$i}, OK {$j} ,Total {$num}"); }
private static function setData($data) { $table = self::tStyle; $replace = array_merge($data, array('updateTime' => time())); unset($replace['createTime']); $k = $v = array(); foreach ($data as $key => $value) { $k[] = '`' . $key . '`'; $v[] = DB::quote($value); } $strv = implode(',', $v); $strk = implode(',', $k); $updateStr = array(); foreach ($replace as $key => $value) { $updateStr[] = '`' . $key . '`=' . DB::quote($value); } $updateStr = implode(',', $updateStr); $sql = "INSERT INTO {$table} ({$strk}) VALUES ({$strv}) ON DUPLICATE KEY UPDATE {$updateStr}"; return DB::runSql($sql) === false ? false : true; }