增加微信模型支持

This commit is contained in:
邹景立 2021-09-15 23:30:48 +08:00
parent d30dc421b5
commit f4c4329a45
18 changed files with 228 additions and 77 deletions

View File

@ -16,6 +16,7 @@
namespace app\wechat\command; namespace app\wechat\command;
use app\wechat\model\WechatAuto;
use app\wechat\service\MediaService; use app\wechat\service\MediaService;
use app\wechat\service\WechatService; use app\wechat\service\WechatService;
use think\admin\Command; use think\admin\Command;
@ -63,7 +64,7 @@ class Auto extends Command
// 查询微信消息对象 // 查询微信消息对象
$map = ['code' => $code, 'status' => 1]; $map = ['code' => $code, 'status' => 1];
$data = $this->app->db->name('WechatAuto')->where($map)->find(); $data = WechatAuto::mk()->where($map)->find();
if (empty($data)) $this->setQueueError("Message Data Query failed"); if (empty($data)) $this->setQueueError("Message Data Query failed");
// 发送微信客服消息 // 发送微信客服消息

View File

@ -16,6 +16,8 @@
namespace app\wechat\command; namespace app\wechat\command;
use app\wechat\model\WechatFans;
use app\wechat\model\WechatFansTags;
use app\wechat\service\FansService; use app\wechat\service\FansService;
use app\wechat\service\WechatService; use app\wechat\service\WechatService;
use think\admin\Command; use think\admin\Command;
@ -98,7 +100,6 @@ class Fans extends Command
* @return string * @return string
* @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException * @throws \WeChat\Exceptions\LocalCacheException
* @throws \think\db\exception\DbException
*/ */
public function _black(string $next = '', int $done = 0): string public function _black(string $next = '', int $done = 0): string
{ {
@ -108,7 +109,7 @@ class Fans extends Command
foreach (array_chunk($result['data']['openid'], 100) as $chunk) { foreach (array_chunk($result['data']['openid'], 100) as $chunk) {
$done += count($chunk); $done += count($chunk);
$map = [['is_black', '=', 0], ['openid', 'in', $chunk]]; $map = [['is_black', '=', 0], ['openid', 'in', $chunk]];
$this->app->db->name('WechatFans')->where($map)->update(['is_black' => 1]); WechatFans::mk()->where($map)->update(['is_black' => 1]);
} }
$next = $result['total'] > $done ? $result['next_openid'] : null; $next = $result['total'] > $done ? $result['next_openid'] : null;
} }
@ -142,12 +143,11 @@ class Fans extends Command
$tag['appid'] = $appid; $tag['appid'] = $appid;
$this->queue->message($count, ++$done, "-> {$tag['name']}"); $this->queue->message($count, ++$done, "-> {$tag['name']}");
} }
$this->app->db->name('WechatFansTags')->where(['appid' => $appid])->delete(); WechatFansTags::mk()->where(['appid' => $appid])->delete();
$this->app->db->name('WechatFansTags')->insertAll($list['tags']); WechatFansTags::mk()->insertAll($list['tags']);
} }
$this->output->comment($done > 0 ? '微信用户标签数据获取完成' : '未获取到微信用户标签数据'); $this->output->comment($done > 0 ? '微信用户标签数据获取完成' : '未获取到微信用户标签数据');
$this->output->newLine(); $this->output->newLine();
return ", 获取到 {$done} 个标签"; return ", 获取到 {$done} 个标签";
} }
} }

View File

@ -16,6 +16,7 @@
namespace app\wechat\controller; namespace app\wechat\controller;
use app\wechat\model\WechatAuto;
use think\admin\Controller; use think\admin\Controller;
use think\admin\extend\CodeExtend; use think\admin\extend\CodeExtend;
@ -26,12 +27,6 @@ use think\admin\extend\CodeExtend;
*/ */
class Auto extends Controller class Auto extends Controller
{ {
/**
* 绑定数据表
* @var string
*/
private $table = 'WechatAuto';
/** /**
* 消息类型 * 消息类型
* @var array * @var array
@ -53,7 +48,7 @@ class Auto extends Controller
public function index() public function index()
{ {
$this->title = '关注自动回复'; $this->title = '关注自动回复';
$query = $this->_query($this->table)->like('code,type'); $query = WechatAuto::mQuery()->like('code,type');
$query->equal('status')->dateBetween('create_at')->order('time asc')->page(); $query->equal('status')->dateBetween('create_at')->order('time asc')->page();
} }
@ -78,7 +73,7 @@ class Auto extends Controller
public function add() public function add()
{ {
$this->title = '添加自动回复'; $this->title = '添加自动回复';
$this->_form($this->table, 'form'); WechatAuto::mForm('form');
} }
/** /**
@ -91,7 +86,7 @@ class Auto extends Controller
public function edit() public function edit()
{ {
$this->title = '编辑自动回复'; $this->title = '编辑自动回复';
$this->_form($this->table, 'form'); WechatAuto::mForm('form');
} }
/** /**
@ -129,7 +124,7 @@ class Auto extends Controller
*/ */
public function state() public function state()
{ {
$this->_save($this->table, $this->_vali([ WechatAuto::mSave($this->_vali([
'status.in:0,1' => '状态值范围异常!', 'status.in:0,1' => '状态值范围异常!',
'status.require' => '状态值不能为空!', 'status.require' => '状态值不能为空!',
])); ]));
@ -142,6 +137,6 @@ class Auto extends Controller
*/ */
public function remove() public function remove()
{ {
$this->_delete($this->table); WechatAuto::mDelete();
} }
} }

View File

@ -16,6 +16,7 @@
namespace app\wechat\controller; namespace app\wechat\controller;
use app\wechat\model\WechatFans;
use app\wechat\service\WechatService; use app\wechat\service\WechatService;
use think\admin\Controller; use think\admin\Controller;
use think\admin\helper\QueryHelper; use think\admin\helper\QueryHelper;
@ -28,12 +29,6 @@ use think\exception\HttpResponseException;
*/ */
class Fans extends Controller class Fans extends Controller
{ {
/**
* 绑定数据表
* @var string
*/
private $table = 'WechatFans';
/** /**
* 微信用户管理 * 微信用户管理
* @auth true * @auth true
@ -44,7 +39,7 @@ class Fans extends Controller
*/ */
public function index() public function index()
{ {
$this->_query($this->table)->layTable(function () { WechatFans::mQuery()->layTable(function () {
$this->title = '微信用户管理'; $this->title = '微信用户管理';
}, function (QueryHelper $query) { }, function (QueryHelper $query) {
$query->where(['appid' => WechatService::instance()->getAppid()]); $query->where(['appid' => WechatService::instance()->getAppid()]);
@ -77,18 +72,18 @@ class Fans extends Controller
*/ */
public function black() public function black()
{ {
$data = $this->_vali([
'black.require' => '操作类型不能为空!',
'openid.require' => '操作用户不能为空!',
]);
try { try {
$data = $this->_vali([
'black.require' => '操作类型不能为空!',
'openid.require' => '操作用户不能为空!',
]);
foreach (array_chunk(str2arr($data['openid']), 20) as $openids) { foreach (array_chunk(str2arr($data['openid']), 20) as $openids) {
if ($data['black']) { if ($data['black']) {
WechatService::WeChatUser()->batchBlackList($openids); WechatService::WeChatUser()->batchBlackList($openids);
$this->app->db->name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => 1]); WechatFans::mk()->whereIn('openid', $openids)->update(['is_black' => 1]);
} else { } else {
WechatService::WeChatUser()->batchUnblackList($openids); WechatService::WeChatUser()->batchUnblackList($openids);
$this->app->db->name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => 0]); WechatFans::mk()->whereIn('openid', $openids)->update(['is_black' => 0]);
} }
} }
if (empty($data['black'])) { if (empty($data['black'])) {
@ -97,7 +92,7 @@ class Fans extends Controller
$this->success('拉入黑名单成功!'); $this->success('拉入黑名单成功!');
} }
} catch (HttpResponseException $exception) { } catch (HttpResponseException $exception) {
throw $exception; throw $exception;
} catch (\Exception $exception) { } catch (\Exception $exception) {
$this->error("黑名单操作失败,请稍候再试!<br>{$exception->getMessage()}"); $this->error("黑名单操作失败,请稍候再试!<br>{$exception->getMessage()}");
} }
@ -110,7 +105,7 @@ class Fans extends Controller
*/ */
public function remove() public function remove()
{ {
$this->_delete($this->table); WechatFans::mDelete();
} }
/** /**
@ -120,8 +115,8 @@ class Fans extends Controller
public function truncate() public function truncate()
{ {
try { try {
$this->_query('WechatFans')->empty(); WechatFans::mQuery()->empty();
$this->_query('WechatFansTags')->empty(); WechatFans::mQuery()->empty();
$this->success('清空用户数据成功!'); $this->success('清空用户数据成功!');
} catch (HttpResponseException $exception) { } catch (HttpResponseException $exception) {
throw $exception; throw $exception;

View File

@ -16,6 +16,7 @@
namespace app\wechat\controller; namespace app\wechat\controller;
use app\wechat\model\WechatKeys;
use app\wechat\service\WechatService; use app\wechat\service\WechatService;
use think\admin\Controller; use think\admin\Controller;
use think\exception\HttpResponseException; use think\exception\HttpResponseException;
@ -27,12 +28,6 @@ use think\exception\HttpResponseException;
*/ */
class Keys extends Controller class Keys extends Controller
{ {
/**
* 绑定数据表
* @var string
*/
private $table = 'WechatKeys';
/** /**
* 消息类型 * 消息类型
* @var array * @var array
@ -64,7 +59,7 @@ class Keys extends Controller
} }
// 数据列表分页处理 // 数据列表分页处理
$this->title = '回复规则管理'; $this->title = '回复规则管理';
$query = $this->_query($this->table)->whereNotIn('keys', ['subscribe', 'default']); $query = WechatKeys::mQuery()->whereNotIn('keys', ['subscribe', 'default']);
$query->equal('status')->like('keys,type')->dateBetween('create_at')->order('sort desc,id desc')->page(); $query->equal('status')->like('keys,type')->dateBetween('create_at')->order('sort desc,id desc')->page();
} }
@ -91,7 +86,7 @@ class Keys extends Controller
{ {
$this->_applyFormToken(); $this->_applyFormToken();
$this->title = '添加回复规则'; $this->title = '添加回复规则';
$this->_form($this->table, 'form'); WechatKeys::mForm('form');
} }
/** /**
@ -105,7 +100,7 @@ class Keys extends Controller
{ {
$this->_applyFormToken(); $this->_applyFormToken();
$this->title = '编辑回复规则'; $this->title = '编辑回复规则';
$this->_form($this->table, 'form'); WechatKeys::mForm('form');
} }
/** /**
@ -116,7 +111,7 @@ class Keys extends Controller
public function state() public function state()
{ {
$this->_applyFormToken(); $this->_applyFormToken();
$this->_save($this->table, $this->_vali([ WechatKeys::mSave($this->_vali([
'status.in:0,1' => '状态值范围异常!', 'status.in:0,1' => '状态值范围异常!',
'status.require' => '状态值不能为空!', 'status.require' => '状态值不能为空!',
])); ]));
@ -130,7 +125,7 @@ class Keys extends Controller
public function remove() public function remove()
{ {
$this->_applyFormToken(); $this->_applyFormToken();
$this->_delete($this->table); WechatKeys::mDelete();
} }
/** /**
@ -145,7 +140,7 @@ class Keys extends Controller
{ {
$this->_applyFormToken(); $this->_applyFormToken();
$this->title = '编辑订阅回复规则'; $this->title = '编辑订阅回复规则';
$this->_form($this->table, 'form', 'keys', [], ['keys' => 'subscribe']); WechatKeys::mForm('form', 'keys', [], ['keys' => 'subscribe']);
} }
/** /**
@ -160,7 +155,7 @@ class Keys extends Controller
{ {
$this->_applyFormToken(); $this->_applyFormToken();
$this->title = '编辑默认回复规则'; $this->title = '编辑默认回复规则';
$this->_form($this->table, 'form', 'keys', [], ['keys' => 'default']); WechatKeys::mForm('form', 'keys', [], ['keys' => 'default']);
} }
/** /**
@ -171,7 +166,7 @@ class Keys extends Controller
{ {
if ($this->request->isPost()) { if ($this->request->isPost()) {
$map = [['keys', '=', $data['keys']], ['id', '<>', $data['id'] ?? 0]]; $map = [['keys', '=', $data['keys']], ['id', '<>', $data['id'] ?? 0]];
if ($this->app->db->name($this->table)->where($map)->count() > 0) { if (WechatKeys::mk()->where($map)->count() > 0) {
$this->error('该关键字已经存在!'); $this->error('该关键字已经存在!');
} }
} elseif ($this->request->isGet()) { } elseif ($this->request->isGet()) {

View File

@ -165,5 +165,4 @@ class Menu extends Controller
return []; return [];
} }
} }
} }

View File

@ -16,6 +16,8 @@
namespace app\wechat\controller; namespace app\wechat\controller;
use app\wechat\model\WechatNews;
use app\wechat\model\WechatNewsArticle;
use app\wechat\service\MediaService; use app\wechat\service\MediaService;
use think\admin\Controller; use think\admin\Controller;
use think\admin\service\AdminService; use think\admin\service\AdminService;
@ -27,13 +29,6 @@ use think\admin\service\AdminService;
*/ */
class News extends Controller class News extends Controller
{ {
/**
* 设置默认操作表
* @var string
*/
private $table = 'WechatNews';
/** /**
* 微信图文管理 * 微信图文管理
* @auth true * @auth true
@ -45,7 +40,7 @@ class News extends Controller
public function index() public function index()
{ {
$this->title = '微信图文列表'; $this->title = '微信图文列表';
$this->_query($this->table)->where(['is_deleted' => 0])->order('id desc')->page(); WechatNews::mQuery()->where(['is_deleted' => 0])->order('id desc')->page();
} }
/** /**
@ -89,7 +84,7 @@ class News extends Controller
'create_by' => AdminService::instance()->getUserId(), 'create_by' => AdminService::instance()->getUserId(),
'article_id' => $this->_buildArticle($this->request->post('data', [])), 'article_id' => $this->_buildArticle($this->request->post('data', [])),
]; ];
if ($this->app->db->name($this->table)->insert($update) !== false) { if (WechatNews::mk()->insert($update) !== false) {
$this->success('图文添加成功!', 'javascript:history.back()'); $this->success('图文添加成功!', 'javascript:history.back()');
} else { } else {
$this->error('图文添加失败,请稍候再试!'); $this->error('图文添加失败,请稍候再试!');
@ -118,7 +113,7 @@ class News extends Controller
} else { } else {
$ids = $this->_buildArticle($this->request->post('data', [])); $ids = $this->_buildArticle($this->request->post('data', []));
[$map, $data] = [['id' => $this->id], ['article_id' => $ids]]; [$map, $data] = [['id' => $this->id], ['article_id' => $ids]];
if ($this->app->db->name($this->table)->where($map)->update($data) !== false) { if (WechatNews::mk()->where($map)->update($data) !== false) {
$this->success('更新成功!', 'javascript:history.back()'); $this->success('更新成功!', 'javascript:history.back()');
} else { } else {
$this->error('更新失败,请稍候再试!'); $this->error('更新失败,请稍候再试!');
@ -133,32 +128,30 @@ class News extends Controller
*/ */
public function remove() public function remove()
{ {
$this->_delete($this->table); WechatNews::mDelete();
} }
/** /**
* 图文更新操作 * 图文更新操作
* @param array $data * @param array $data
* @param array $ids
* @return string * @return string
* @throws \think\db\exception\DbException
*/ */
private function _buildArticle(array $data, array $ids = []): string private function _buildArticle(array $data): string
{ {
$ids = [];
foreach ($data as $vo) { foreach ($data as $vo) {
if (empty($vo['digest'])) { if (empty($vo['digest'])) {
$vo['digest'] = mb_substr(strip_tags(str_replace(["\s", ' '], '', $vo['content'])), 0, 120); $vo['digest'] = mb_substr(strip_tags(str_replace(["\s", ' '], '', $vo['content'])), 0, 120);
} }
$vo['create_at'] = date('Y-m-d H:i:s'); $vo['create_at'] = date('Y-m-d H:i:s');
if (empty($vo['id'])) { if (empty($vo['id'])) {
$result = $id = $this->app->db->name('WechatNewsArticle')->insertGetId($vo); $result = $id = WechatNewsArticle::mk()->insertGetId($vo);
} else { } else {
$id = intval($vo['id']); $id = intval($vo['id']);
$result = $this->app->db->name('WechatNewsArticle')->where('id', $id)->update($vo); $result = WechatNewsArticle::mk()->where('id', $id)->update($vo);
} }
if ($result !== false) array_push($ids, $id); if ($result !== false) array_push($ids, $id);
} }
return join(',', $ids); return join(',', $ids);
} }
} }

View File

@ -16,6 +16,7 @@
namespace app\wechat\controller\api; namespace app\wechat\controller\api;
use app\wechat\model\WechatNewsArticle;
use app\wechat\service\MediaService; use app\wechat\service\MediaService;
use think\admin\Controller; use think\admin\Controller;
@ -51,10 +52,10 @@ class View extends Controller
public function item($id = 0) public function item($id = 0)
{ {
$map = ['id' => $id ?: input('id', 0)]; $map = ['id' => $id ?: input('id', 0)];
$this->app->db->name('WechatNewsArticle')->where($map)->update([ WechatNewsArticle::mk()->where($map)->update([
'read_num' => $this->app->db->raw('read_num+1'), 'read_num' => $this->app->db->raw('read_num+1'),
]); ]);
$this->info = $this->app->db->name('WechatNewsArticle')->where($map)->find(); $this->info = WechatNewsArticle::mk()->where($map)->find();
$this->fetch(); $this->fetch();
} }

View File

@ -0,0 +1,28 @@
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免费声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\wechat\model;
use think\admin\Model;
/**
* 微信自动回复模型
* Class WechatAuto
* @package app\wechat\model
*/
class WechatAuto extends Model
{
}

View File

@ -0,0 +1,28 @@
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免费声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\wechat\model;
use think\admin\Model;
/**
* 微信粉丝用户模型
* Class WechatFans
* @package app\wechat\model
*/
class WechatFans extends Model
{
}

View File

@ -0,0 +1,28 @@
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免费声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\wechat\model;
use think\admin\Model;
/**
* 微信粉丝标签模型
* Class WechatFansTags
* @package app\wechat\model
*/
class WechatFansTags extends Model
{
}

View File

@ -0,0 +1,28 @@
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免费声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\wechat\model;
use think\admin\Model;
/**
* 微信回复关键词模型
* Class WechatKeys
* @package app\wechat\model
*/
class WechatKeys extends Model
{
}

View File

@ -0,0 +1,28 @@
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免费声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\wechat\model;
use think\admin\Model;
/**
* 微信图文主模型
* Class WechatNews
* @package app\wechat\model
*/
class WechatNews extends Model
{
}

View File

@ -0,0 +1,28 @@
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免费声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\wechat\model;
use think\admin\Model;
/**
* 微信图文详细模型
* Class WechatNewsArticle
* @package app\wechat\model
*/
class WechatNewsArticle extends Model
{
}

View File

@ -16,6 +16,7 @@
namespace app\wechat\service; namespace app\wechat\service;
use app\wechat\model\WechatAuto;
use think\admin\Service; use think\admin\Service;
use think\admin\service\QueueService; use think\admin\service\QueueService;
@ -36,7 +37,7 @@ class AutoService extends Service
*/ */
public function register(string $openid) public function register(string $openid)
{ {
foreach ($this->app->db->name('WechatAuto')->where(['status' => 1])->order('time asc')->cursor() as $vo) { foreach (WechatAuto::mk()->where(['status' => 1])->order('time asc')->cursor() as $vo) {
[$name, $time] = ["推送客服消息 {$vo['code']}#{$openid}", $this->parseTimeString($vo['time'])]; [$name, $time] = ["推送客服消息 {$vo['code']}#{$openid}", $this->parseTimeString($vo['time'])];
QueueService::instance()->register($name, "xadmin:fansmsg {$openid} {$vo['code']}", $time, []); QueueService::instance()->register($name, "xadmin:fansmsg {$openid} {$vo['code']}", $time, []);
} }

View File

@ -16,6 +16,7 @@
namespace app\wechat\service; namespace app\wechat\service;
use app\wechat\model\WechatFans;
use think\admin\Service; use think\admin\Service;
/** /**
@ -46,7 +47,7 @@ class FansService extends Service
if ($appid !== '') $user['appid'] = $appid; if ($appid !== '') $user['appid'] = $appid;
unset($user['privilege'], $user['groupid']); unset($user['privilege'], $user['groupid']);
$this->app->event->trigger('WechatFansUpdate', $user); $this->app->event->trigger('WechatFansUpdate', $user);
return !!data_save('WechatFans', $user, 'openid'); return !!data_save(WechatFans::class, $user, 'openid');
} }
/** /**
@ -59,7 +60,7 @@ class FansService extends Service
*/ */
public function get(string $openid): array public function get(string $openid): array
{ {
return $this->app->db->name('WechatFans')->where(['openid' => $openid])->find() ?: []; $user = WechatFans::mk()->where(['openid' => $openid])->find();
return empty($user) ? [] : $user->toArray();
} }
} }

View File

@ -16,6 +16,8 @@
namespace app\wechat\service; namespace app\wechat\service;
use app\wechat\model\WechatNews;
use app\wechat\model\WechatNewsArticle;
use think\admin\Service; use think\admin\Service;
use think\admin\Storage; use think\admin\Storage;
use WeChat\Contracts\MyCurlFile; use WeChat\Contracts\MyCurlFile;
@ -40,14 +42,14 @@ class MediaService extends Service
{ {
// 文章主体数据 // 文章主体数据
$where = ['id' => $id, 'is_deleted' => 0]; $where = ['id' => $id, 'is_deleted' => 0];
$data = $this->app->db->name('WechatNews')->where($where)->where($map)->find(); $data = WechatNews::mk()->where($where)->where($map)->find();
if (empty($data)) return []; if (empty($data)) return [];
// 文章内容编号 // 文章内容编号
$data['articles'] = []; $data['articles'] = [];
$data['articleids'] = str2arr($data['article_id']); $data['articleids'] = str2arr($data['article_id']);
if (empty($data['articleids'])) return $data; if (empty($data['articleids'])) return $data;
// 文章内容集合 // 文章内容集合
$query = $this->app->db->name('WechatNewsArticle'); $query = WechatNewsArticle::mk();
$query->whereIn('id', $data['articleids'])->orderField('id', $data['articleids']); $query->whereIn('id', $data['articleids'])->orderField('id', $data['articleids']);
$data['articles'] = $query->withoutField('create_by,create_at')->select()->toArray(); $data['articles'] = $query->withoutField('create_by,create_at')->select()->toArray();
return $data; return $data;

View File

@ -213,7 +213,7 @@ class WechatService extends Service
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function getWebOauthInfo(string $source, $isfull = 0, $redirect = true): array public function getWebOauthInfo(string $source, int $isfull = 0, bool $redirect = true): array
{ {
$appid = $this->getAppid(); $appid = $this->getAppid();
$openid = $this->app->session->get("{$appid}_openid"); $openid = $this->app->session->get("{$appid}_openid");