123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- /**
- * Created by PhpStorm.
- * User: lytian
- * Date: 2019/7/25
- * Time: 21:46
- */
- namespace app\admin\command;
- use app\common\library\Redis;
- use app\common\library\WeChatObject;
- use app\common\model\AdminConfig;
- use app\main\constants\CacheConstants;
- use app\main\service\AdminService;
- use app\main\service\OfficialAccountsService;
- use app\main\service\OpenPlatformService;
- use app\main\service\UserService;
- use EasyWeChat\Kernel\Messages\Text;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Option;
- use think\console\Output;
- use think\Exception;
- use think\Request;
- class FixUserFollow extends Command
- {
- protected function configure()
- {
- $this->setName('fixUserFollow')
- ->setDescription('修复用户的关注状态');
- }
- protected function execute(Input $input, Output $output)
- {
- Request::instance()->module('admin'); //cli模式下无法获取到当前的项目模块,手动指定一下
- $filename = APP_PATH."1111.txt";
- $handle = fopen ($filename, "r");
- $adminIds = [];
- $i = 1;
- while (!feof($handle)) {
- $buffer = fgets($handle, 4096);
- $content = trim($buffer);
- if (empty($content)) {
- break;
- }
- try {
- $arr = explode(' ', $content);
- $appid = $arr[0];
- $openid = $arr[1];
- //查询admin_id
- if (!isset($adminIds[$appid])) {
- $adminInfo = AdminService::instance()
- ->getAdminConfigModel()
- ->where('appid', $appid)
- ->find();
- $adminIds[$appid] = $adminInfo['admin_id'];
- }
- $admin_id = $adminIds[$appid];
- $userId = OfficialAccountsService::instance()
- ->getOpenidModel()
- ->getUserId($admin_id, $openid);
- if ($userId) {
- if (
- UserService::instance()
- ->getUserModel()
- ->setConnect($userId)
- ->update(
- ['is_subscribe' => 1, 'subscribe_time' => time()],
- ['id' => $userId])
- ) {
- $userKey = CacheConstants::getUserCacheKey($userId);
- Redis::instance()->del($userKey);
- //发送客服消息
- $adminConfig = new AdminConfig();
- $adminInfo = $adminConfig->getAdminInfoAll($admin_id);
- $wechat = new WeChatObject($adminInfo);
- $officialAccount = $wechat->getOfficialAccount();
- $host = AdminService::instance()->getAdminReferralDomain($admin_id)->data;
- $msg = '<a href="https://'.$appid.'.'.$host["menu_ophost_host"].'/index/user/recent">最近阅读链接</a>';
- $result = $officialAccount
- ->customer_service
- ->message(new Text($msg))
- ->to($openid)
- ->send();
- echo "第{$i}行--appid:{$appid} --openid:{$openid} --处理结果".json_encode($result, JSON_UNESCAPED_UNICODE);
- $adminConfig->getConnection()->free();
- $adminConfig->getConnection()->close();
- unset($adminConfig);
- }
- }
- }catch (Exception $e) {
- echo "第{$i}行--appid:{$appid} --openid:{$openid} --处理结果:".$e->getMessage();
- }
- $i++;
- }
- fclose ($handle);
- $output->writeln("\n处理完毕!");
- }
- }
|