1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wanggb
- * Date: 2019/1/2
- * Time: 14:13
- */
- namespace app\admin\command;
- use app\common\library\Redis;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\Request;
- class RefreshRefExtCache extends Command
- {
- protected function configure()
- {
- $this->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;
- }
- }
|