租房掌柜微信小程序Api以及小程序前端模板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 lines
3.3 KiB

<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\service\queue;
use app\admin\queue\JobsQueue;
use app\service\service\WechatService;
use app\wechat\service\FansService;
use think\Db;
/**
* Class Jobs
* @package app\wechat
*/
class WechatQueue extends JobsQueue
{
/**
* 当前任务URI
*/
const URI = self::class;
/**
* 当前操作APPID
* @var string
*/
protected $appid;
/**
* 执行任务
* @return boolean
*/
public function execute()
{
try {
$this->appid = $this->data['appid'];
$wechat = WechatService::WeChatUser($this->appid);
$next = ''; // 获取远程粉丝
$this->output->writeln('Start synchronizing fans from the Wechat server');
while (is_array($result = $wechat->getUserList($next)) && !empty($result['data']['openid'])) {
foreach (array_chunk($result['data']['openid'], 100) as $chunk)
if (is_array($list = $wechat->getBatchUserInfo($chunk)) && !empty($list['user_info_list']))
foreach ($list['user_info_list'] as $user) FansService::set($user, $this->appid);
if (in_array($result['next_openid'], $result['data']['openid'])) break;
$next = $result['next_openid'];
}
$next = ''; // 同步粉丝黑名单
$this->output->writeln('Start synchronizing black from the Wechat server');
while (is_array($result = $wechat->getBlackList($next)) && !empty($result['data']['openid'])) {
foreach (array_chunk($result['data']['openid'], 100) as $chunk) {
$where = [['is_black', 'eq', '0'], ['openid', 'in', $chunk]];
Db::name('WechatFans')->where($where)->update(['is_black' => '1']);
}
if (in_array($result['next_openid'], $result['data']['openid'])) break;
$next = $result['next_openid'];
}
// 同步粉丝标签列表
$this->output->writeln('Start synchronizing tags from the Wechat server');
if (is_array($list = WechatService::WeChatTags($this->appid)->getTags()) && !empty($list['tags'])) {
foreach ($list['tags'] as &$tag) $tag['appid'] = $this->appid;
Db::name('WechatFansTags')->where('1=1')->delete();
Db::name('WechatFansTags')->insertAll($list['tags']);
}
return true;
} catch (\Exception $e) {
$this->statusDesc = $e->getMessage();
return false;
}
}
}