setName('RefreshRefExtCache') ->setDescription('更新客服消息推广链接与ext关联关系'); } protected function execute(Input $input, Output $output) { Request::instance()->module('admin'); $batch = 1000; $count = model('Short_url')->whereLike('url', '%ext%')->count(); $times = ceil($count / 1000); $sum = 0; for ($i = 0; $i < $times; $i++) { $data = model('Short_url')->whereLike('url', '%ext=%')->limit($i * $batch, $batch)->select(); foreach ($data as $item) { preg_match('/ext=({.*?})/', $item['url'], $match); if (!$match) { continue; } $ext = $match[1]; preg_match('/\/t\/(\d+)/', $item['url'], $match_short_referral_id); preg_match('/referral_id=(\d+)/', $item['url'], $match_referral_id); $referral_id = 0; if ($match_short_referral_id) { $referral_id = $match_short_referral_id[1]; } if ($match_referral_id) { $referral_id = $match_referral_id[1]; } if ($ext) { $cacheExt = 'RefExt:' . md5($ext); if ($referral_id) { $sum += Redis::instance()->set($cacheExt, $referral_id); } } } } echo "ok,处理数量" . $sum; } }