diff --git a/app/data/controller/Config.php b/app/data/controller/Config.php
index e0b11b9ff..8f4b20151 100644
--- a/app/data/controller/Config.php
+++ b/app/data/controller/Config.php
@@ -2,7 +2,6 @@
namespace app\data\controller;
-use app\data\service\MessageService;
use think\admin\Controller;
/**
@@ -26,23 +25,6 @@ class Config extends Controller
$this->__sysconf('wxapp');
}
- /**
- * 短信接口配置
- * @auth true
- * @menu true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function message()
- {
- if ($this->request->isGet()) {
- $this->title = '短信接口配置';
- $this->result = MessageService::instance()->balance();
- }
- $this->__sysconf('message');
- }
-
/**
* 关于我们描述
* @auth true
diff --git a/app/data/controller/NewsItem.php b/app/data/controller/NewsItem.php
index 520ee785f..e417875c7 100644
--- a/app/data/controller/NewsItem.php
+++ b/app/data/controller/NewsItem.php
@@ -97,8 +97,9 @@ class NewsItem extends Controller
$data['code'] = CodeExtend::uniqidNumber(14, 'A');
}
if ($this->request->isGet()) {
- $query = $this->app->db->name('DataNewsMark')->where(['deleted' => 0, 'status' => 1]);
- $this->mark = $query->order('sort desc,id desc')->select()->toArray();
+ $map = ['deleted' => 0, 'status' => 1];
+ $query = $this->app->db->name('DataNewsMark')->where($map);
+ $this->marks = $query->order('sort desc,id desc')->select()->toArray();
$data['mark'] = str2arr($data['mark'] ?? '');
} else {
$data['mark'] = arr2str($data['mark'] ?? []);
diff --git a/app/data/controller/NewsMark.php b/app/data/controller/NewsMark.php
index 617696890..aa2f174fb 100644
--- a/app/data/controller/NewsMark.php
+++ b/app/data/controller/NewsMark.php
@@ -20,7 +20,6 @@ class NewsMark extends Controller
/**
* 文章标签管理
* @auth true
- * @menu true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
diff --git a/app/data/controller/Payment.php b/app/data/controller/Payment.php
index e4992e797..38455fd0a 100644
--- a/app/data/controller/Payment.php
+++ b/app/data/controller/Payment.php
@@ -80,18 +80,15 @@ class Payment extends Controller
if ($this->request->isGet()) {
$this->payments = [];
foreach ($this->types as $k => $vo) {
- [$allow, $group] = [[], ucfirst(strstr($k, '_', true))];
+ $allow = [];
foreach ($vo['bind'] as $api) if (isset(UserService::TYPES[$api])) {
$allow[$api] = UserService::TYPES[$api]['name'];
}
- $vo['allow'] = join('、', $allow);
- $this->payments[$group][$k] = $vo;
+ $this->payments[$k] = array_merge($vo, ['allow' => join('、', $allow)]);
}
$data['content'] = json_decode($data['content'] ?? '[]', true) ?: [];
} else {
- if (empty($data['type'])) {
- $this->error('请选择支付通道并配置支付参数!');
- }
+ if (empty($data['type'])) $this->error('请选择支付通道并配置支付参数!');
$data['content'] = json_encode($this->request->post() ?: [], JSON_UNESCAPED_UNICODE);
}
}
diff --git a/app/data/controller/ShopGoodsMark.php b/app/data/controller/ShopGoodsMark.php
index 8c7428686..176458331 100644
--- a/app/data/controller/ShopGoodsMark.php
+++ b/app/data/controller/ShopGoodsMark.php
@@ -20,7 +20,6 @@ class ShopGoodsMark extends Controller
/**
* 商品标签管理
* @auth true
- * @menu true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
@@ -28,7 +27,9 @@ class ShopGoodsMark extends Controller
public function index()
{
$this->title = '商品标签管理';
- $this->_query($this->table)->order('sort desc,id desc')->page();
+ $query = $this->_query($this->table);
+ $query->like('name')->dateBetween('create_at');
+ $query->equal('status')->order('sort desc,id desc')->page();
}
/**
diff --git a/app/data/controller/UserMessage.php b/app/data/controller/UserMessage.php
index 8cd41368a..a5e43ee03 100644
--- a/app/data/controller/UserMessage.php
+++ b/app/data/controller/UserMessage.php
@@ -2,6 +2,7 @@
namespace app\data\controller;
+use app\data\service\MessageService;
use think\admin\Controller;
/**
@@ -33,6 +34,27 @@ class UserMessage extends Controller
$query->dateBetween('create_at')->order('id desc')->page();
}
+ /**
+ * 短信接口配置
+ * @auth true
+ * @menu true
+ * @throws \think\db\exception\DataNotFoundException
+ * @throws \think\db\exception\DbException
+ * @throws \think\db\exception\ModelNotFoundException
+ */
+ public function config()
+ {
+ if ($this->request->isGet()) {
+ $this->title = '短信接口配置';
+ $this->result = MessageService::instance()->balance();
+ $this->fetch();
+ } else {
+ $data = $this->request->post();
+ foreach ($data as $k => $v) sysconf($k, $v);
+ $this->success('配置保存成功!');
+ }
+ }
+
/**
* 删除短信记录
* @auth true
diff --git a/app/data/controller/api/Wechat.php b/app/data/controller/api/Wechat.php
index 4b65fe499..65ad7125b 100644
--- a/app/data/controller/api/Wechat.php
+++ b/app/data/controller/api/Wechat.php
@@ -13,7 +13,8 @@ use think\Response;
* @package app\data\controller\api
* @example 域名请修改为自己的地址,放到网页代码合适位置
*
- *
+ *
+ *
* 授权模式支持两种模块,参数 mode=0 时为静默授权,mode=1 时为完整授权
* 注意:回跳地址默认从 Header 中的 http_referer 获取,也可以传 source 参数
*/
@@ -32,45 +33,22 @@ class Wechat extends Controller
*/
private $field;
- /**
- * 粉丝OPNEID
- * @var string
- */
- private $openid;
-
- /**
- * 网页授权配置
- * @var array
- */
- private $config;
-
- /**
- * 微信粉丝数据
- * @var array
- */
- private $fansInfo;
-
- /**
- * 前端用户数据
- * @var array
- */
- private $userInfo;
-
/**
* 控制器初始化
+ * @return $this
*/
- protected function initialize()
+ protected function initialize(): Wechat
{
if (empty(UserService::TYPES[$this->type]['auth'])) {
$this->error("接口类型[{$this->type}]没有定义规则");
} else {
$this->field = UserService::TYPES[$this->type]['auth'];
}
+ return $this;
}
/**
- * 加载对应JSSDK数据
- * @return \think\Response
+ * 获取 JSSDK 签名
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
* @throws \think\Exception
@@ -78,79 +56,39 @@ class Wechat extends Controller
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
- public function jssdk(): Response
+ public function jssdk()
{
- $wechat = WechatService::instance();
- $source = $this->request->server('http_referer', $this->request->get('source', ''));
+ $url = input('source') ?: $this->request->server('http_referer');
+ $this->success('获取签名参数', WechatService::instance()->getWebJssdkSign($url));
+ }
+
+ /**
+ * 加载网页授权数据
+ * @return \think\Response
+ * @throws \think\Exception
+ * @throws \think\db\exception\DataNotFoundException
+ * @throws \think\db\exception\DbException
+ * @throws \think\db\exception\ModelNotFoundException
+ */
+ public function oauth(): Response
+ {
+ [$script, $wechat] = [[], WechatService::instance()];
+ $source = input('source') ?: $this->request->server('http_referer');
$result = $wechat->getWebOauthInfo($source ?: $this->request->url(true), input('mode', 1), false);
if (empty($result['openid'])) {
- $content = 'alert("Wechat WebOauth failed.")';
+ $script[] = 'alert("Wechat WebOauth failed.")';
} else {
- $this->openid = $result['openid'];
- $this->fansInfo = $result['fansinfo'] ?? [];
- $this->config = $wechat->getWebJssdkSign($source);
- // 用户注册并登录生成接口令牌
- $data = $this->fansInfo;
+ $data = $result['fansinfo'] ?? [];
$data['openid2'] = $data['openid'];
$data['base_sex'] = ['未知', '男', '女'][$data['sex']] ?? '未知';
if (isset($data['headimgurl'])) $data['headimg'] = $data['headimgurl'];
- $map = isset($data['unionid']) ? ['unionid' => $data['unionid']] : [$this->field => $this->openid];
- $this->userInfo = UserService::instance()->set($map, array_merge($map, $data), $this->type, true);
- $content = $this->_buildContent();
+ $map = isset($data['unionid']) ? ['unionid' => $data['unionid']] : [$this->field => $result['openid']];
+ $result['userinfo'] = UserService::instance()->set($map, array_merge($map, $data), $this->type, true);
+ $script[] = "window.WeChatOpenid='{$result['openid']}'";
+ $script[] = 'window.WeChatFansInfo=' . json_encode($result['fansinfo'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
+ $script[] = 'window.WeChatUserInfo=' . json_encode($result['userinfo'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
- return Response::create($content)->contentType('application/x-javascript');
+ $script[] = '';
+ return Response::create(join(";\n", $script))->contentType('application/x-javascript');
}
-
-
- /**
- * 页面授权 jssdk 测试
- * @return string
- */
- public function jssdkTest(): string
- {
- $src = sysuri('data/api.wechat/jssdk', [], false, true) . '?mode=1';
- return <<
-
-
-
-
-