新增
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
return [
|
||||
'middleware' => [
|
||||
app\api\http\middleware\InitMiddleware::class, // 初始化
|
||||
app\api\http\middleware\LoginMiddleware::class, // 登录验证
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\lists\AccountLogLists;
|
||||
|
||||
/**
|
||||
* 账户流水
|
||||
* Class AccountLogController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class AccountLogController extends BaseApiController
|
||||
{
|
||||
/**
|
||||
* @notes 账户流水
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 14:34
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new AccountLogLists());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\lists\article\ArticleCollectLists;
|
||||
use app\api\lists\article\ArticleLists;
|
||||
use app\api\logic\ArticleLogic;
|
||||
|
||||
/**
|
||||
* 文章管理
|
||||
* Class ArticleController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class ArticleController extends BaseApiController
|
||||
{
|
||||
|
||||
public array $notNeedLogin = ['lists', 'cate', 'detail'];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 文章列表
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 15:30
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ArticleLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 文章分类列表
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 15:30
|
||||
*/
|
||||
public function cate()
|
||||
{
|
||||
return $this->data(ArticleLogic::cate());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 收藏列表
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 16:31
|
||||
*/
|
||||
public function collect()
|
||||
{
|
||||
return $this->dataLists(new ArticleCollectLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 文章详情
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 17:09
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$id = $this->request->get('id/d');
|
||||
$result = ArticleLogic::detail($id, $this->userId);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 加入收藏
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 17:01
|
||||
*/
|
||||
public function addCollect()
|
||||
{
|
||||
$articleId = $this->request->post('id/d');
|
||||
ArticleLogic::addCollect($articleId, $this->userId);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 取消收藏
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 17:01
|
||||
*/
|
||||
public function cancelCollect()
|
||||
{
|
||||
$articleId = $this->request->post('id/d');
|
||||
ArticleLogic::cancelCollect($articleId, $this->userId);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseLikeAdminController;
|
||||
|
||||
class BaseApiController extends BaseLikeAdminController
|
||||
{
|
||||
protected int $userId = 0;
|
||||
protected array $userInfo = [];
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
if (isset($this->request->userInfo) && $this->request->userInfo) {
|
||||
$this->userInfo = $this->request->userInfo;
|
||||
$this->userId = $this->request->userInfo['user_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\IndexLogic;
|
||||
use think\response\Json;
|
||||
|
||||
|
||||
/**
|
||||
* index
|
||||
* Class IndexController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class IndexController extends BaseApiController
|
||||
{
|
||||
|
||||
|
||||
public array $notNeedLogin = ['index', 'config', 'policy', 'decorate'];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:15
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$result = IndexLogic::getIndexData();
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 全局配置
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:41
|
||||
*/
|
||||
public function config()
|
||||
{
|
||||
$result = IndexLogic::getConfigData();
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 政策协议
|
||||
* @return Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 20:00
|
||||
*/
|
||||
public function policy()
|
||||
{
|
||||
$type = $this->request->get('type/s', '');
|
||||
$result = IndexLogic::getPolicyByType($type);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 装修信息
|
||||
* @return Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 18:37
|
||||
*/
|
||||
public function decorate()
|
||||
{
|
||||
$id = $this->request->get('id/d');
|
||||
$result = IndexLogic::getDecorate($id);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\validate\{LoginAccountValidate, RegisterValidate, WebScanLoginValidate, WechatLoginValidate};
|
||||
use app\api\logic\LoginLogic;
|
||||
|
||||
/**
|
||||
* 登录注册
|
||||
* Class LoginController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class LoginController extends BaseApiController
|
||||
{
|
||||
|
||||
public array $notNeedLogin = ['register', 'account', 'logout', 'codeUrl', 'oaLogin', 'mnpLogin', 'getScanCode', 'scanLogin'];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 注册账号
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/7 15:38
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$params = (new RegisterValidate())->post()->goCheck('register');
|
||||
$result = LoginLogic::register($params);
|
||||
if (true === $result) {
|
||||
return $this->success('注册成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 账号密码/手机号密码/手机号验证码登录
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:42
|
||||
*/
|
||||
public function account()
|
||||
{
|
||||
$params = (new LoginAccountValidate())->post()->goCheck();
|
||||
$result = LoginLogic::login($params);
|
||||
if (false === $result) {
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 退出登录
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:42
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
LoginLogic::logout($this->userInfo);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取微信请求code的链接
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 18:27
|
||||
*/
|
||||
public function codeUrl()
|
||||
{
|
||||
$url = $this->request->get('url');
|
||||
$result = ['url' => LoginLogic::codeUrl($url)];
|
||||
return $this->success('获取成功', $result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 公众号登录
|
||||
* @return \think\response\Json
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:48
|
||||
*/
|
||||
public function oaLogin()
|
||||
{
|
||||
$params = (new WechatLoginValidate())->post()->goCheck('oa');
|
||||
$res = LoginLogic::oaLogin($params);
|
||||
if (false === $res) {
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
return $this->success('', $res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序-登录接口
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:48
|
||||
*/
|
||||
public function mnpLogin()
|
||||
{
|
||||
$params = (new WechatLoginValidate())->post()->goCheck('mnpLogin');
|
||||
$res = LoginLogic::mnpLogin($params);
|
||||
if (false === $res) {
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
return $this->success('', $res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序绑定微信
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:48
|
||||
*/
|
||||
public function mnpAuthBind()
|
||||
{
|
||||
$params = (new WechatLoginValidate())->post()->goCheck("wechatAuth");
|
||||
$params['user_id'] = $this->userId;
|
||||
$result = LoginLogic::mnpAuthLogin($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
return $this->success('绑定成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 公众号绑定微信
|
||||
* @return \think\response\Json
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:48
|
||||
*/
|
||||
public function oaAuthBind()
|
||||
{
|
||||
$params = (new WechatLoginValidate())->post()->goCheck("wechatAuth");
|
||||
$params['user_id'] = $this->userId;
|
||||
$result = LoginLogic::oaAuthLogin($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
return $this->success('绑定成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取扫码地址
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/10/20 18:25
|
||||
*/
|
||||
public function getScanCode()
|
||||
{
|
||||
$redirectUri = $this->request->get('url/s');
|
||||
$result = LoginLogic::getScanCode($redirectUri);
|
||||
if (false === $result) {
|
||||
return $this->fail(LoginLogic::getError() ?? '未知错误');
|
||||
}
|
||||
return $this->success('', $result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 网站扫码登录
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/10/21 10:28
|
||||
*/
|
||||
public function scanLogin()
|
||||
{
|
||||
$params = (new WebScanLoginValidate())->post()->goCheck();
|
||||
$result = LoginLogic::scanLogin($params);
|
||||
if (false === $result) {
|
||||
return $this->fail(LoginLogic::getError() ?? '登录失败');
|
||||
}
|
||||
return $this->success('', $result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新用户头像昵称
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2023/2/22 11:15
|
||||
*/
|
||||
public function updateUser()
|
||||
{
|
||||
$params = (new WechatLoginValidate())->post()->goCheck("updateUser");
|
||||
LoginLogic::updateUser($params, $this->userId);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\validate\PayValidate;
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\logic\PaymentLogic;
|
||||
use app\common\service\pay\AliPayService;
|
||||
use app\common\service\pay\WeChatPayService;
|
||||
|
||||
/**
|
||||
* 支付
|
||||
* Class PayController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class PayController extends BaseApiController
|
||||
{
|
||||
|
||||
public array $notNeedLogin = ['notifyMnp', 'notifyOa', 'aliNotify'];
|
||||
|
||||
/**
|
||||
* @notes 支付方式
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 17:54
|
||||
*/
|
||||
public function payWay()
|
||||
{
|
||||
$params = (new PayValidate())->goCheck('payway');
|
||||
$result = PaymentLogic::getPayWay($this->userId, $this->userInfo['terminal'], $params);
|
||||
if ($result === false) {
|
||||
return $this->fail(PaymentLogic::getError());
|
||||
}
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 预支付
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2023/2/28 14:21
|
||||
*/
|
||||
public function prepay()
|
||||
{
|
||||
$params = (new PayValidate())->post()->goCheck();
|
||||
//订单信息
|
||||
$order = PaymentLogic::getPayOrderInfo($params);
|
||||
if (false === $order) {
|
||||
return $this->fail(PaymentLogic::getError(), $params);
|
||||
}
|
||||
//支付流程
|
||||
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
|
||||
$result = PaymentLogic::pay($params['pay_way'], $params['from'], $order, $this->userInfo['terminal'], $redirectUrl);
|
||||
if (false === $result) {
|
||||
return $this->fail(PaymentLogic::getError(), $params);
|
||||
}
|
||||
return $this->success('', $result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取支付状态
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2023/3/1 16:23
|
||||
*/
|
||||
public function payStatus()
|
||||
{
|
||||
$params = (new PayValidate())->goCheck('status', ['user_id' => $this->userId]);
|
||||
$result = PaymentLogic::getPayStatus($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(PaymentLogic::getError());
|
||||
}
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序支付回调
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
* @throws \ReflectionException
|
||||
* @throws \Throwable
|
||||
* @author 段誉
|
||||
* @date 2023/2/28 14:21
|
||||
*/
|
||||
public function notifyMnp()
|
||||
{
|
||||
return (new WeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 公众号支付回调
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
* @throws \ReflectionException
|
||||
* @throws \Throwable
|
||||
* @author 段誉
|
||||
* @date 2023/2/28 14:21
|
||||
*/
|
||||
public function notifyOa()
|
||||
{
|
||||
return (new WeChatPayService(UserTerminalEnum::WECHAT_OA))->notify();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 支付宝回调
|
||||
* @author mjf
|
||||
* @date 2024/3/18 16:50
|
||||
*/
|
||||
public function aliNotify()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = (new AliPayService())->notify($params);
|
||||
if (true === $result) {
|
||||
echo 'success';
|
||||
} else {
|
||||
echo 'fail';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\PcLogic;
|
||||
use think\response\Json;
|
||||
|
||||
|
||||
/**
|
||||
* PC
|
||||
* Class PcController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class PcController extends BaseApiController
|
||||
{
|
||||
|
||||
public array $notNeedLogin = ['index', 'config', 'infoCenter', 'articleDetail'];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:15
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$result = PcLogic::getIndexData();
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 全局配置
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:41
|
||||
*/
|
||||
public function config()
|
||||
{
|
||||
$result = PcLogic::getConfigData();
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 资讯中心
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/19 16:55
|
||||
*/
|
||||
public function infoCenter()
|
||||
{
|
||||
$result = PcLogic::getInfoCenter();
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取文章详情
|
||||
* @return Json
|
||||
* @author 段誉
|
||||
* @date 2022/10/20 15:18
|
||||
*/
|
||||
public function articleDetail()
|
||||
{
|
||||
$id = $this->request->get('id/d', 0);
|
||||
$source = $this->request->get('source/s', 'default');
|
||||
$result = PcLogic::getArticleDetail($this->userId, $id, $source);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\lists\recharge\RechargeLists;
|
||||
use app\api\logic\RechargeLogic;
|
||||
use app\api\validate\RechargeValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 充值控制器
|
||||
* Class RechargeController
|
||||
* @package app\shopapi\controller
|
||||
*/
|
||||
class RechargeController extends BaseApiController
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取充值列表
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 18:55
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new RechargeLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 充值
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 18:56
|
||||
*/
|
||||
public function recharge()
|
||||
{
|
||||
$params = (new RechargeValidate())->post()->goCheck('recharge', [
|
||||
'user_id' => $this->userId,
|
||||
'terminal' => $this->userInfo['terminal'],
|
||||
]);
|
||||
$result = RechargeLogic::recharge($params);
|
||||
if (false === $result) {
|
||||
return $this->fail(RechargeLogic::getError());
|
||||
}
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 充值配置
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 16:56
|
||||
*/
|
||||
public function config()
|
||||
{
|
||||
return $this->data(RechargeLogic::config($this->userId));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\SearchLogic;
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
* Class HotSearchController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SearchController extends BaseApiController
|
||||
{
|
||||
|
||||
public array $notNeedLogin = ['hotLists'];
|
||||
|
||||
/**
|
||||
* @notes 热门搜素
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/22 10:14
|
||||
*/
|
||||
public function hotLists()
|
||||
{
|
||||
return $this->data(SearchLogic::hotLists());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\SmsLogic;
|
||||
use app\api\validate\SendSmsValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 短信
|
||||
* Class SmsController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SmsController extends BaseApiController
|
||||
{
|
||||
|
||||
public array $notNeedLogin = ['sendCode'];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 发送短信验证码
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 16:17
|
||||
*/
|
||||
public function sendCode()
|
||||
{
|
||||
$params = (new SendSmsValidate())->post()->goCheck();
|
||||
$result = SmsLogic::sendCode($params);
|
||||
if (true === $result) {
|
||||
return $this->success('发送成功');
|
||||
}
|
||||
return $this->fail(SmsLogic::getError());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\enum\FileEnum;
|
||||
use app\common\service\UploadService;
|
||||
use Exception;
|
||||
use think\response\Json;
|
||||
|
||||
|
||||
/** 上传文件
|
||||
* Class UploadController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class UploadController extends BaseApiController
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 上传图片
|
||||
* @return Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 18:11
|
||||
*/
|
||||
public function image()
|
||||
{
|
||||
try {
|
||||
$result = UploadService::image(0, $this->userId,FileEnum::SOURCE_USER);
|
||||
return $this->success('上传成功', $result);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\UserLogic;
|
||||
use app\api\validate\PasswordValidate;
|
||||
use app\api\validate\SetUserInfoValidate;
|
||||
use app\api\validate\UserValidate;
|
||||
|
||||
/**
|
||||
* 用户控制器
|
||||
* Class UserController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class UserController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = ['resetPassword'];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取个人中心
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:19
|
||||
*/
|
||||
public function center()
|
||||
{
|
||||
$data = UserLogic::center($this->userInfo);
|
||||
return $this->success('', $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取个人信息
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:46
|
||||
*/
|
||||
public function info()
|
||||
{
|
||||
$result = UserLogic::info($this->userId);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 重置密码
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:06
|
||||
*/
|
||||
public function resetPassword()
|
||||
{
|
||||
$params = (new PasswordValidate())->post()->goCheck('resetPassword');
|
||||
$result = UserLogic::resetPassword($params);
|
||||
if (true === $result) {
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 修改密码
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:16
|
||||
*/
|
||||
public function changePassword()
|
||||
{
|
||||
$params = (new PasswordValidate())->post()->goCheck('changePassword');
|
||||
$result = UserLogic::changePassword($params, $this->userId);
|
||||
if (true === $result) {
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取小程序手机号
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 16:46
|
||||
*/
|
||||
public function getMobileByMnp()
|
||||
{
|
||||
$params = (new UserValidate())->post()->goCheck('getMobileByMnp');
|
||||
$params['user_id'] = $this->userId;
|
||||
$result = UserLogic::getMobileByMnp($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
return $this->success('绑定成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑用户信息
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 17:01
|
||||
*/
|
||||
public function setInfo()
|
||||
{
|
||||
$params = (new SetUserInfoValidate())->post()->goCheck(null, ['id' => $this->userId]);
|
||||
$result = UserLogic::setInfo($this->userId, $params);
|
||||
if (false === $result) {
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 绑定/变更 手机号
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 17:29
|
||||
*/
|
||||
public function bindMobile()
|
||||
{
|
||||
$params = (new UserValidate())->post()->goCheck('bindMobile');
|
||||
$params['user_id'] = $this->userId;
|
||||
$result = UserLogic::bindMobile($params);
|
||||
if($result) {
|
||||
return $this->success('绑定成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\logic\WechatLogic;
|
||||
use app\api\validate\WechatValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 微信
|
||||
* Class WechatController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class WechatController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = ['jsConfig'];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 微信JSSDK授权接口
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2023/3/1 11:39
|
||||
*/
|
||||
public function jsConfig()
|
||||
{
|
||||
$params = (new WechatValidate())->goCheck('jsConfig');
|
||||
$result = WechatLogic::jsConfig($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(WechatLogic::getError(), [], 0, 0);
|
||||
}
|
||||
return $this->data($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\http\middleware;
|
||||
|
||||
|
||||
use app\common\exception\ControllerExtendException;
|
||||
use app\api\controller\BaseApiController;
|
||||
use think\exception\ClassNotFoundException;
|
||||
use think\exception\HttpException;
|
||||
|
||||
|
||||
class InitMiddleware
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 初始化
|
||||
* @param $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
* @throws ControllerExtendException
|
||||
* @author 段誉
|
||||
* @date 2022/9/6 18:17
|
||||
*/
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
//获取控制器
|
||||
try {
|
||||
$controller = str_replace('.', '\\', $request->controller());
|
||||
$controller = '\\app\\api\\controller\\' . $controller . 'Controller';
|
||||
$controllerClass = invoke($controller);
|
||||
if (($controllerClass instanceof BaseApiController) === false) {
|
||||
throw new ControllerExtendException($controller, '404');
|
||||
}
|
||||
} catch (ClassNotFoundException $e) {
|
||||
throw new HttpException(404, 'controller not exists:' . $e->getClass());
|
||||
}
|
||||
//创建控制器对象
|
||||
$request->controllerObject = invoke($controller);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\http\middleware;
|
||||
|
||||
|
||||
use app\common\cache\UserTokenCache;
|
||||
use app\common\service\JsonService;
|
||||
use app\api\service\UserTokenService;
|
||||
use think\facade\Config;
|
||||
|
||||
class LoginMiddleware
|
||||
{
|
||||
/**
|
||||
* @notes 登录验证
|
||||
* @param $request
|
||||
* @param \Closure $next
|
||||
* @return mixed|\think\response\Json
|
||||
* @author 令狐冲
|
||||
* @date 2021/7/1 17:33
|
||||
*/
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
$token = $request->header('token');
|
||||
//判断接口是否免登录
|
||||
$isNotNeedLogin = $request->controllerObject->isNotNeedLogin();
|
||||
|
||||
//不直接判断$isNotNeedLogin结果,使不需要登录的接口通过,为了兼容某些接口可以登录或不登录访问
|
||||
if (empty($token) && !$isNotNeedLogin) {
|
||||
//没有token并且该地址需要登录才能访问, 指定show为0,前端不弹出此报错
|
||||
return JsonService::fail('请求参数缺token', [], 0, 0);
|
||||
}
|
||||
|
||||
$userInfo = (new UserTokenCache())->getUserInfo($token);
|
||||
|
||||
if (empty($userInfo) && !$isNotNeedLogin) {
|
||||
//token过期无效并且该地址需要登录才能访问
|
||||
return JsonService::fail('登录超时,请重新登录', [], -1, 0);
|
||||
}
|
||||
|
||||
//token临近过期,自动续期
|
||||
if ($userInfo) {
|
||||
//获取临近过期自动续期时长
|
||||
$beExpireDuration = Config::get('project.user_token.be_expire_duration');
|
||||
//token续期
|
||||
if (time() > ($userInfo['expire_time'] - $beExpireDuration)) {
|
||||
$result = UserTokenService::overtimeToken($token);
|
||||
//续期失败(数据表被删除导致)
|
||||
if (empty($result)) {
|
||||
return JsonService::fail('登录过期', [], -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//给request赋值,用于控制器
|
||||
$request->userInfo = $userInfo;
|
||||
$request->userId = $userInfo['user_id'] ?? 0;
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\lists;
|
||||
|
||||
use app\common\enum\user\AccountLogEnum;
|
||||
use app\common\model\user\UserAccountLog;
|
||||
|
||||
|
||||
/**
|
||||
* 账户流水列表
|
||||
* Class AccountLogLists
|
||||
* @package app\shopapi\lists
|
||||
*/
|
||||
class AccountLogLists extends BaseApiDataLists
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 搜索条件
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 14:43
|
||||
*/
|
||||
public function queryWhere()
|
||||
{
|
||||
// 指定用户
|
||||
$where[] = ['user_id', '=', $this->userId];
|
||||
|
||||
// 用户月明细
|
||||
if (isset($this->params['type']) && $this->params['type'] == 'um') {
|
||||
$where[] = ['change_type', 'in', AccountLogEnum::getUserMoneyChangeType()];
|
||||
}
|
||||
|
||||
// 变动类型
|
||||
if (!empty($this->params['action'])) {
|
||||
$where[] = ['action', '=', $this->params['action']];
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 14:43
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$field = 'change_type,change_amount,action,create_time,remark';
|
||||
$lists = UserAccountLog::field($field)
|
||||
->where($this->queryWhere())
|
||||
->order('id', 'desc')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['type_desc'] = AccountLogEnum::getChangeTypeDesc($item['change_type']);
|
||||
$symbol = $item['action'] == AccountLogEnum::DEC ? '-' : '+';
|
||||
$item['change_amount_desc'] = $symbol . $item['change_amount'];
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 14:44
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return UserAccountLog::where($this->queryWhere())->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\lists;
|
||||
|
||||
use app\common\lists\BaseDataLists;
|
||||
|
||||
abstract class BaseApiDataLists extends BaseDataLists
|
||||
{
|
||||
protected array $userInfo = [];
|
||||
protected int $userId = 0;
|
||||
|
||||
public string $export;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (isset($this->request->userInfo) && $this->request->userInfo) {
|
||||
$this->userInfo = $this->request->userInfo;
|
||||
$this->userId = $this->request->userId;
|
||||
}
|
||||
$this->export = $this->request->get('export', '');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\lists\article;
|
||||
|
||||
use app\api\lists\BaseApiDataLists;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\model\article\Article;
|
||||
|
||||
/**
|
||||
* 文章收藏列表
|
||||
* Class ArticleCollectLists
|
||||
* @package app\api\lists\article
|
||||
*/
|
||||
class ArticleCollectLists extends BaseApiDataLists
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取收藏列表
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 16:29
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$field = "c.id,c.article_id,a.title,a.image,a.desc,a.is_show,
|
||||
a.click_virtual, a.click_actual,a.create_time, c.create_time as collect_time";
|
||||
|
||||
$lists = (new Article())->alias('a')
|
||||
->join('article_collect c', 'c.article_id = a.id')
|
||||
->field($field)
|
||||
->where([
|
||||
'c.user_id' => $this->userId,
|
||||
'c.status' => YesNoEnum::YES,
|
||||
'a.is_show' => YesNoEnum::YES,
|
||||
])
|
||||
->order(['sort' => 'desc', 'c.id' => 'desc'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->append(['click'])
|
||||
->hidden(['click_virtual', 'click_actual'])
|
||||
->select()->toArray();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['collect_time'] = date('Y-m-d H:i', $item['collect_time']);
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取收藏数量
|
||||
* @return int
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 16:29
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return (new Article())->alias('a')
|
||||
->join('article_collect c', 'c.article_id = a.id')
|
||||
->where([
|
||||
'c.user_id' => $this->userId,
|
||||
'c.status' => YesNoEnum::YES,
|
||||
'a.is_show' => YesNoEnum::YES,
|
||||
])
|
||||
->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\lists\article;
|
||||
|
||||
use app\api\lists\BaseApiDataLists;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\article\ArticleCollect;
|
||||
|
||||
|
||||
/**
|
||||
* 文章列表
|
||||
* Class ArticleLists
|
||||
* @package app\api\lists\article
|
||||
*/
|
||||
class ArticleLists extends BaseApiDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 搜索条件
|
||||
* @return \string[][]
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:54
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['cid']
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 自定查询条件
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/10/25 16:53
|
||||
*/
|
||||
public function queryWhere()
|
||||
{
|
||||
$where[] = ['is_show', '=', 1];
|
||||
if (!empty($this->params['keyword'])) {
|
||||
$where[] = ['title', 'like', '%' . $this->params['keyword'] . '%'];
|
||||
}
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取文章列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:55
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$orderRaw = 'sort desc, id desc';
|
||||
$sortType = $this->params['sort'] ?? 'default';
|
||||
// 最新排序
|
||||
if ($sortType == 'new') {
|
||||
$orderRaw = 'id desc';
|
||||
}
|
||||
// 最热排序
|
||||
if ($sortType == 'hot') {
|
||||
$orderRaw = 'click_actual + click_virtual desc, id desc';
|
||||
}
|
||||
|
||||
$field = 'id,cid,title,desc,image,click_virtual,click_actual,create_time';
|
||||
$result = Article::field($field)
|
||||
->where($this->queryWhere())
|
||||
->where($this->searchWhere)
|
||||
->orderRaw($orderRaw)
|
||||
->append(['click'])
|
||||
->hidden(['click_virtual', 'click_actual'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->select()->toArray();
|
||||
|
||||
$articleIds = array_column($result, 'id');
|
||||
|
||||
$collectIds = ArticleCollect::where(['user_id' => $this->userId, 'status' => YesNoEnum::YES])
|
||||
->whereIn('article_id', $articleIds)
|
||||
->column('article_id');
|
||||
|
||||
foreach ($result as &$item) {
|
||||
$item['collect'] = in_array($item['id'], $collectIds);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取文章数量
|
||||
* @return int
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:55
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Article::where($this->searchWhere)
|
||||
->where($this->queryWhere())
|
||||
->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\lists\recharge;
|
||||
|
||||
use app\api\lists\BaseApiDataLists;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\recharge\RechargeOrder;
|
||||
|
||||
|
||||
/**
|
||||
* 充值记录列表
|
||||
* Class RechargeLists
|
||||
* @package app\api\lists\recharge
|
||||
*/
|
||||
class RechargeLists extends BaseApiDataLists
|
||||
{
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 18:43
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$lists = RechargeOrder::field('order_amount,create_time')
|
||||
->where([
|
||||
'user_id' => $this->userId,
|
||||
'pay_status' => PayEnum::ISPAID
|
||||
])
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach($lists as &$item) {
|
||||
$item['tips'] = '充值' . format_amount($item['order_amount']) . '元';
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 18:43
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return RechargeOrder::where([
|
||||
'user_id' => $this->userId,
|
||||
'pay_status' => PayEnum::ISPAID
|
||||
])
|
||||
->count();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\article\ArticleCate;
|
||||
use app\common\model\article\ArticleCollect;
|
||||
|
||||
|
||||
/**
|
||||
* 文章逻辑
|
||||
* Class ArticleLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class ArticleLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 文章详情
|
||||
* @param $articleId
|
||||
* @param $userId
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 17:09
|
||||
*/
|
||||
public static function detail($articleId, $userId)
|
||||
{
|
||||
// 文章详情
|
||||
$article = Article::getArticleDetailArr($articleId);
|
||||
// 关注状态
|
||||
$article['collect'] = ArticleCollect::isCollectArticle($userId, $articleId);
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 加入收藏
|
||||
* @param $userId
|
||||
* @param $articleId
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 16:52
|
||||
*/
|
||||
public static function addCollect($articleId, $userId)
|
||||
{
|
||||
$where = ['user_id' => $userId, 'article_id' => $articleId];
|
||||
$collect = ArticleCollect::where($where)->findOrEmpty();
|
||||
if ($collect->isEmpty()) {
|
||||
ArticleCollect::create([
|
||||
'user_id' => $userId,
|
||||
'article_id' => $articleId,
|
||||
'status' => YesNoEnum::YES
|
||||
]);
|
||||
} else {
|
||||
ArticleCollect::update([
|
||||
'id' => $collect['id'],
|
||||
'status' => YesNoEnum::YES
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 取消收藏
|
||||
* @param $articleId
|
||||
* @param $userId
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 16:59
|
||||
*/
|
||||
public static function cancelCollect($articleId, $userId)
|
||||
{
|
||||
ArticleCollect::update(['status' => YesNoEnum::NO], [
|
||||
'user_id' => $userId,
|
||||
'article_id' => $articleId,
|
||||
'status' => YesNoEnum::YES
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 文章分类
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/23 14:11
|
||||
*/
|
||||
public static function cate()
|
||||
{
|
||||
return ArticleCate::field('id,name')
|
||||
->where('is_show', '=', 1)
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
use app\common\model\decorate\DecorateTabbar;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
|
||||
/**
|
||||
* index
|
||||
* Class IndexLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class IndexLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:15
|
||||
*/
|
||||
public static function getIndexData()
|
||||
{
|
||||
// 装修配置
|
||||
$decoratePage = DecoratePage::findOrEmpty(1);
|
||||
|
||||
// 首页文章
|
||||
$field = [
|
||||
'id', 'title', 'desc', 'abstract', 'image',
|
||||
'author', 'click_actual', 'click_virtual', 'create_time'
|
||||
];
|
||||
|
||||
$article = Article::field($field)
|
||||
->where(['is_show' => 1])
|
||||
->order(['id' => 'desc'])
|
||||
->limit(20)->append(['click'])
|
||||
->hidden(['click_actual', 'click_virtual'])
|
||||
->select()->toArray();
|
||||
|
||||
return [
|
||||
'page' => $decoratePage,
|
||||
'article' => $article
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取政策协议
|
||||
* @param string $type
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 20:00
|
||||
*/
|
||||
public static function getPolicyByType(string $type)
|
||||
{
|
||||
return [
|
||||
'title' => ConfigService::get('agreement', $type . '_title', ''),
|
||||
'content' => ConfigService::get('agreement', $type . '_content', ''),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 装修信息
|
||||
* @param $id
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 18:37
|
||||
*/
|
||||
public static function getDecorate($id)
|
||||
{
|
||||
return DecoratePage::field(['type', 'name', 'data', 'meta'])
|
||||
->findOrEmpty($id)->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取配置
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:38
|
||||
*/
|
||||
public static function getConfigData()
|
||||
{
|
||||
// 底部导航
|
||||
$tabbar = DecorateTabbar::getTabbarLists();
|
||||
// 导航颜色
|
||||
$style = ConfigService::get('tabbar', 'style', config('project.decorate.tabbar_style'));
|
||||
// 登录配置
|
||||
$loginConfig = [
|
||||
// 登录方式
|
||||
'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
|
||||
// 注册强制绑定手机
|
||||
'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
|
||||
// 政策协议
|
||||
'login_agreement' => ConfigService::get('login', 'login_agreement', config('project.login.login_agreement')),
|
||||
// 第三方登录 开关
|
||||
'third_auth' => ConfigService::get('login', 'third_auth', config('project.login.third_auth')),
|
||||
// 微信授权登录
|
||||
'wechat_auth' => ConfigService::get('login', 'wechat_auth', config('project.login.wechat_auth')),
|
||||
// qq授权登录
|
||||
'qq_auth' => ConfigService::get('login', 'qq_auth', config('project.login.qq_auth')),
|
||||
];
|
||||
// 网址信息
|
||||
$website = [
|
||||
'h5_favicon' => FileService::getFileUrl(ConfigService::get('website', 'h5_favicon')),
|
||||
'shop_name' => ConfigService::get('website', 'shop_name'),
|
||||
'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
|
||||
];
|
||||
// H5配置
|
||||
$webPage = [
|
||||
// 渠道状态 0-关闭 1-开启
|
||||
'status' => ConfigService::get('web_page', 'status', 1),
|
||||
// 关闭后渠道后访问页面 0-空页面 1-自定义链接
|
||||
'page_status' => ConfigService::get('web_page', 'page_status', 0),
|
||||
// 自定义链接
|
||||
'page_url' => ConfigService::get('web_page', 'page_url', ''),
|
||||
'url' => request()->domain() . '/mobile'
|
||||
];
|
||||
|
||||
// 备案信息
|
||||
$copyright = ConfigService::get('copyright', 'config', []);
|
||||
|
||||
return [
|
||||
'domain' => FileService::getFileUrl(),
|
||||
'style' => $style,
|
||||
'tabbar' => $tabbar,
|
||||
'login' => $loginConfig,
|
||||
'website' => $website,
|
||||
'webPage' => $webPage,
|
||||
'version'=> config('project.version'),
|
||||
'copyright' => $copyright,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,433 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\cache\WebScanLoginCache;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\api\service\{UserTokenService, WechatUserService};
|
||||
use app\common\enum\{LoginEnum, user\UserTerminalEnum, YesNoEnum};
|
||||
use app\common\service\{
|
||||
ConfigService,
|
||||
FileService,
|
||||
wechat\WeChatConfigService,
|
||||
wechat\WeChatMnpService,
|
||||
wechat\WeChatOaService,
|
||||
wechat\WeChatRequestService
|
||||
};
|
||||
use app\common\model\user\{User, UserAuth};
|
||||
use think\facade\{Db, Config};
|
||||
|
||||
/**
|
||||
* 登录逻辑
|
||||
* Class LoginLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class LoginLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 账号密码注册
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/7 15:37
|
||||
*/
|
||||
public static function register(array $params)
|
||||
{
|
||||
try {
|
||||
$userSn = User::createUserSn();
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$avatar = ConfigService::get('default_image', 'user_avatar');
|
||||
|
||||
User::create([
|
||||
'sn' => $userSn,
|
||||
'avatar' => $avatar,
|
||||
'nickname' => '用户' . $userSn,
|
||||
'account' => $params['account'],
|
||||
'password' => $password,
|
||||
'channel' => $params['channel'],
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 账号/手机号登录,手机号验证码
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/6 19:26
|
||||
*/
|
||||
public static function login($params)
|
||||
{
|
||||
try {
|
||||
// 账号/手机号 密码登录
|
||||
$where = ['account|mobile' => $params['account']];
|
||||
if ($params['scene'] == LoginEnum::MOBILE_CAPTCHA) {
|
||||
//手机验证码登录
|
||||
$where = ['mobile' => $params['account']];
|
||||
}
|
||||
|
||||
$user = User::where($where)->findOrEmpty();
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
//更新登录信息
|
||||
$user->login_time = time();
|
||||
$user->login_ip = request()->ip();
|
||||
$user->save();
|
||||
|
||||
//设置token
|
||||
$userInfo = UserTokenService::setToken($user->id, $params['terminal']);
|
||||
|
||||
//返回登录信息
|
||||
$avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
|
||||
$avatar = FileService::getFileUrl($avatar);
|
||||
|
||||
return [
|
||||
'nickname' => $userInfo['nickname'],
|
||||
'sn' => $userInfo['sn'],
|
||||
'mobile' => $userInfo['mobile'],
|
||||
'avatar' => $avatar,
|
||||
'token' => $userInfo['token'],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 退出登录
|
||||
* @param $userInfo
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 17:56
|
||||
*/
|
||||
public static function logout($userInfo)
|
||||
{
|
||||
//token不存在,不注销
|
||||
if (!isset($userInfo['token'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//设置token过期
|
||||
return UserTokenService::expireToken($userInfo['token']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取微信请求code的链接
|
||||
* @param string $url
|
||||
* @return string
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function codeUrl(string $url)
|
||||
{
|
||||
return (new WeChatOaService())->getCodeUrl($url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 公众号登录
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function oaLogin(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
//通过code获取微信 openid
|
||||
$response = (new WeChatOaService())->getOaResByCode($params['code']);
|
||||
$userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_OA);
|
||||
$userInfo = $userServer->getResopnseByUserInfo()->authUserLogin()->getUserInfo();
|
||||
|
||||
// 更新登录信息
|
||||
self::updateLoginInfo($userInfo['id']);
|
||||
|
||||
Db::commit();
|
||||
return $userInfo;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序-静默登录
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function silentLogin(array $params)
|
||||
{
|
||||
try {
|
||||
//通过code获取微信 openid
|
||||
$response = (new WeChatMnpService())->getMnpResByCode($params['code']);
|
||||
$userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_MMP);
|
||||
$userInfo = $userServer->getResopnseByUserInfo('silent')->getUserInfo();
|
||||
|
||||
if (!empty($userInfo)) {
|
||||
// 更新登录信息
|
||||
self::updateLoginInfo($userInfo['id']);
|
||||
}
|
||||
|
||||
return $userInfo;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序-授权登录
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function mnpLogin(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
//通过code获取微信 openid
|
||||
$response = (new WeChatMnpService())->getMnpResByCode($params['code']);
|
||||
$userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_MMP);
|
||||
$userInfo = $userServer->getResopnseByUserInfo()->authUserLogin()->getUserInfo();
|
||||
|
||||
// 更新登录信息
|
||||
self::updateLoginInfo($userInfo['id']);
|
||||
|
||||
Db::commit();
|
||||
return $userInfo;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新登录信息
|
||||
* @param $userId
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:46
|
||||
*/
|
||||
public static function updateLoginInfo($userId)
|
||||
{
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$user->login_time = $time;
|
||||
$user->login_ip = request()->ip();
|
||||
$user->update_time = $time;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序端绑定微信
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:46
|
||||
*/
|
||||
public static function mnpAuthLogin(array $params)
|
||||
{
|
||||
try {
|
||||
//通过code获取微信openid
|
||||
$response = (new WeChatMnpService())->getMnpResByCode($params['code']);
|
||||
$response['user_id'] = $params['user_id'];
|
||||
$response['terminal'] = UserTerminalEnum::WECHAT_MMP;
|
||||
|
||||
return self::createAuth($response);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 公众号端绑定微信
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:43
|
||||
*/
|
||||
public static function oaAuthLogin(array $params)
|
||||
{
|
||||
try {
|
||||
//通过code获取微信openid
|
||||
$response = (new WeChatOaService())->getOaResByCode($params['code']);
|
||||
$response['user_id'] = $params['user_id'];
|
||||
$response['terminal'] = UserTerminalEnum::WECHAT_OA;
|
||||
|
||||
return self::createAuth($response);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 生成授权记录
|
||||
* @param $response
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:43
|
||||
*/
|
||||
public static function createAuth($response)
|
||||
{
|
||||
//先检查openid是否有记录
|
||||
$isAuth = UserAuth::where('openid', '=', $response['openid'])->findOrEmpty();
|
||||
if (!$isAuth->isEmpty()) {
|
||||
throw new \Exception('该微信已被绑定');
|
||||
}
|
||||
|
||||
if (isset($response['unionid']) && !empty($response['unionid'])) {
|
||||
//在用unionid找记录,防止生成两个账号,同个unionid的问题
|
||||
$userAuth = UserAuth::where(['unionid' => $response['unionid']])
|
||||
->findOrEmpty();
|
||||
if (!$userAuth->isEmpty() && $userAuth->user_id != $response['user_id']) {
|
||||
throw new \Exception('该微信已被绑定');
|
||||
}
|
||||
}
|
||||
|
||||
//如果没有授权,直接生成一条微信授权记录
|
||||
UserAuth::create([
|
||||
'user_id' => $response['user_id'],
|
||||
'openid' => $response['openid'],
|
||||
'unionid' => $response['unionid'] ?? '',
|
||||
'terminal' => $response['terminal'],
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取扫码登录地址
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/10/20 18:23
|
||||
*/
|
||||
public static function getScanCode($redirectUri)
|
||||
{
|
||||
try {
|
||||
$config = WeChatConfigService::getOpConfig();
|
||||
$appId = $config['app_id'];
|
||||
$redirectUri = UrlEncode($redirectUri);
|
||||
|
||||
// 设置有效时间标记状态, 超时扫码不可登录
|
||||
$state = MD5(time().rand(10000, 99999));
|
||||
(new WebScanLoginCache())->setScanLoginState($state);
|
||||
|
||||
// 扫码地址
|
||||
$url = WeChatRequestService::getScanCodeUrl($appId, $redirectUri, $state);
|
||||
return ['url' => $url];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 网站扫码登录
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/10/21 10:28
|
||||
*/
|
||||
public static function scanLogin($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 通过code 获取 access_token,openid,unionid等信息
|
||||
$userAuth = WeChatRequestService::getUserAuthByCode($params['code']);
|
||||
|
||||
if (empty($userAuth['openid']) || empty($userAuth['access_token'])) {
|
||||
throw new \Exception('获取用户授权信息失败');
|
||||
}
|
||||
|
||||
// 获取微信用户信息
|
||||
$response = WeChatRequestService::getUserInfoByAuth($userAuth['access_token'], $userAuth['openid']);
|
||||
|
||||
// 生成用户或更新用户信息
|
||||
$userServer = new WechatUserService($response, UserTerminalEnum::PC);
|
||||
$userInfo = $userServer->getResopnseByUserInfo()->authUserLogin()->getUserInfo();
|
||||
|
||||
// 更新登录信息
|
||||
self::updateLoginInfo($userInfo['id']);
|
||||
|
||||
Db::commit();
|
||||
return $userInfo;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新用户信息
|
||||
* @param $params
|
||||
* @param $userId
|
||||
* @return User
|
||||
* @author 段誉
|
||||
* @date 2023/2/22 11:19
|
||||
*/
|
||||
public static function updateUser($params, $userId)
|
||||
{
|
||||
return User::where(['id' => $userId])->update([
|
||||
'nickname' => $params['nickname'],
|
||||
'avatar' => FileService::setFileUrl($params['avatar']),
|
||||
'is_new_user' => YesNoEnum::NO
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\article\ArticleCate;
|
||||
use app\common\model\article\ArticleCollect;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
|
||||
/**
|
||||
* index
|
||||
* Class IndexLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class PcLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:15
|
||||
*/
|
||||
public static function getIndexData()
|
||||
{
|
||||
// 装修配置
|
||||
$decoratePage = DecoratePage::findOrEmpty(4);
|
||||
// 最新资讯
|
||||
$newArticle = self::getLimitArticle('new', 7);
|
||||
// 全部资讯
|
||||
$allArticle = self::getLimitArticle('all', 5);
|
||||
// 热门资讯
|
||||
$hotArticle = self::getLimitArticle('hot', 8);
|
||||
|
||||
return [
|
||||
'page' => $decoratePage,
|
||||
'all' => $allArticle,
|
||||
'new' => $newArticle,
|
||||
'hot' => $hotArticle
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取文章
|
||||
* @param string $sortType
|
||||
* @param int $limit
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/10/19 9:53
|
||||
*/
|
||||
public static function getLimitArticle(string $sortType, int $limit = 0, int $cate = 0, int $excludeId = 0)
|
||||
{
|
||||
// 查询字段
|
||||
$field = [
|
||||
'id', 'cid', 'title', 'desc', 'abstract', 'image',
|
||||
'author', 'click_actual', 'click_virtual', 'create_time'
|
||||
];
|
||||
|
||||
// 排序条件
|
||||
$orderRaw = 'sort desc, id desc';
|
||||
if ($sortType == 'new') {
|
||||
$orderRaw = 'id desc';
|
||||
}
|
||||
if ($sortType == 'hot') {
|
||||
$orderRaw = 'click_actual + click_virtual desc, id desc';
|
||||
}
|
||||
|
||||
// 查询条件
|
||||
$where[] = ['is_show', '=', YesNoEnum::YES];
|
||||
if (!empty($cate)) {
|
||||
$where[] = ['cid', '=', $cate];
|
||||
}
|
||||
if (!empty($excludeId)) {
|
||||
$where[] = ['id', '<>', $excludeId];
|
||||
}
|
||||
|
||||
$article = Article::field($field)
|
||||
->where($where)
|
||||
->append(['click'])
|
||||
->orderRaw($orderRaw)
|
||||
->hidden(['click_actual', 'click_virtual']);
|
||||
|
||||
if ($limit) {
|
||||
$article->limit($limit);
|
||||
}
|
||||
|
||||
return $article->select()->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取配置
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:38
|
||||
*/
|
||||
public static function getConfigData()
|
||||
{
|
||||
// 登录配置
|
||||
$loginConfig = [
|
||||
// 登录方式
|
||||
'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
|
||||
// 注册强制绑定手机
|
||||
'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
|
||||
// 政策协议
|
||||
'login_agreement' => ConfigService::get('login', 'login_agreement', config('project.login.login_agreement')),
|
||||
// 第三方登录 开关
|
||||
'third_auth' => ConfigService::get('login', 'third_auth', config('project.login.third_auth')),
|
||||
// 微信授权登录
|
||||
'wechat_auth' => ConfigService::get('login', 'wechat_auth', config('project.login.wechat_auth')),
|
||||
// qq授权登录
|
||||
'qq_auth' => ConfigService::get('login', 'qq_auth', config('project.login.qq_auth')),
|
||||
];
|
||||
|
||||
// 网站信息
|
||||
$website = [
|
||||
'shop_name' => ConfigService::get('website', 'shop_name'),
|
||||
'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
|
||||
'pc_logo' => FileService::getFileUrl(ConfigService::get('website', 'pc_logo')),
|
||||
'pc_title' => ConfigService::get('website', 'pc_title'),
|
||||
'pc_ico' => FileService::getFileUrl(ConfigService::get('website', 'pc_ico')),
|
||||
'pc_desc' => ConfigService::get('website', 'pc_desc'),
|
||||
'pc_keywords' => ConfigService::get('website', 'pc_keywords'),
|
||||
];
|
||||
|
||||
// 站点统计
|
||||
$siteStatistics = [
|
||||
'clarity_code' => ConfigService::get('siteStatistics', 'clarity_code'),
|
||||
];
|
||||
|
||||
// 备案信息
|
||||
$copyright = ConfigService::get('copyright', 'config', []);
|
||||
|
||||
// 公众号二维码
|
||||
$oaQrCode = ConfigService::get('oa_setting', 'qr_code', '');
|
||||
$oaQrCode = empty($oaQrCode) ? $oaQrCode : FileService::getFileUrl($oaQrCode);
|
||||
// 小程序二维码
|
||||
$mnpQrCode = ConfigService::get('mnp_setting', 'qr_code', '');
|
||||
$mnpQrCode = empty($mnpQrCode) ? $mnpQrCode : FileService::getFileUrl($mnpQrCode);
|
||||
|
||||
return [
|
||||
'domain' => FileService::getFileUrl(),
|
||||
'login' => $loginConfig,
|
||||
'website' => $website,
|
||||
'siteStatistics' => $siteStatistics,
|
||||
'version' => config('project.version'),
|
||||
'copyright' => $copyright,
|
||||
'admin_url' => request()->domain() . '/admin',
|
||||
'qrcode' => [
|
||||
'oa' => $oaQrCode,
|
||||
'mnp' => $mnpQrCode,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 资讯中心
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/19 16:55
|
||||
*/
|
||||
public static function getInfoCenter()
|
||||
{
|
||||
$data = ArticleCate::field(['id', 'name'])
|
||||
->with(['article' => function ($query) {
|
||||
$query->hidden(['content', 'click_virtual', 'click_actual'])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->append(['click'])
|
||||
->limit(10);
|
||||
}])
|
||||
->where(['is_show' => YesNoEnum::YES])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取文章详情
|
||||
* @param $userId
|
||||
* @param $articleId
|
||||
* @param string $source
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/10/20 15:18
|
||||
*/
|
||||
public static function getArticleDetail($userId, $articleId, $source = 'default')
|
||||
{
|
||||
// 文章详情
|
||||
$detail = Article::getArticleDetailArr($articleId);
|
||||
|
||||
// 根据来源列表查找对应列表
|
||||
$nowIndex = 0;
|
||||
$lists = self::getLimitArticle($source, 0, $detail['cid']);
|
||||
foreach ($lists as $key => $item) {
|
||||
if ($item['id'] == $articleId) {
|
||||
$nowIndex = $key;
|
||||
}
|
||||
}
|
||||
// 上一篇
|
||||
$detail['last'] = $lists[$nowIndex - 1] ?? [];
|
||||
// 下一篇
|
||||
$detail['next'] = $lists[$nowIndex + 1] ?? [];
|
||||
|
||||
// 最新资讯
|
||||
$detail['new'] = self::getLimitArticle('new', 8, $detail['cid'], $detail['id']);
|
||||
// 关注状态
|
||||
$detail['collect'] = ArticleCollect::isCollectArticle($userId, $articleId);
|
||||
// 分类名
|
||||
$detail['cate_name'] = ArticleCate::where('id', $detail['cid'])->value('name');
|
||||
|
||||
return $detail;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\recharge\RechargeOrder;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
|
||||
/**
|
||||
* 充值逻辑层
|
||||
* Class RechargeLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class RechargeLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 充值
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 10:43
|
||||
*/
|
||||
public static function recharge(array $params)
|
||||
{
|
||||
try {
|
||||
$data = [
|
||||
'sn' => generate_sn(RechargeOrder::class, 'sn'),
|
||||
'order_terminal' => $params['terminal'],
|
||||
'user_id' => $params['user_id'],
|
||||
'pay_status' => PayEnum::UNPAID,
|
||||
'order_amount' => $params['money'],
|
||||
];
|
||||
$order = RechargeOrder::create($data);
|
||||
|
||||
return [
|
||||
'order_id' => (int)$order['id'],
|
||||
'from' => 'recharge'
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 充值配置
|
||||
* @param $userId
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 16:56
|
||||
*/
|
||||
public static function config($userId)
|
||||
{
|
||||
$userMoney = User::where(['id' => $userId])->value('user_money');
|
||||
$minAmount = ConfigService::get('recharge', 'min_amount', 0);
|
||||
$status = ConfigService::get('recharge', 'status', 0);
|
||||
|
||||
return [
|
||||
'status' => $status,
|
||||
'min_amount' => $minAmount,
|
||||
'user_money' => $userMoney,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\HotSearch;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
/**
|
||||
* 搜索逻辑
|
||||
* Class SearchLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class SearchLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 热搜列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/23 14:34
|
||||
*/
|
||||
public static function hotLists()
|
||||
{
|
||||
$data = HotSearch::field(['name', 'sort'])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()->toArray();
|
||||
|
||||
return [
|
||||
// 功能状态 0-关闭 1-开启
|
||||
'status' => ConfigService::get('hot_search', 'status', 0),
|
||||
// 热门搜索数据
|
||||
'data' => $data,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
|
||||
|
||||
/**
|
||||
* 短信逻辑
|
||||
* Class SmsLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class SmsLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 发送验证码
|
||||
* @param $params
|
||||
* @return false|mixed
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 16:17
|
||||
*/
|
||||
public static function sendCode($params)
|
||||
{
|
||||
try {
|
||||
$scene = NoticeEnum::getSceneByTag($params['scene']);
|
||||
if (empty($scene)) {
|
||||
throw new \Exception('场景值异常');
|
||||
}
|
||||
|
||||
$result = event('Notice', [
|
||||
'scene_id' => $scene,
|
||||
'params' => [
|
||||
'mobile' => $params['mobile'],
|
||||
'code' => mt_rand(1000, 9999),
|
||||
]
|
||||
]);
|
||||
|
||||
return $result[0];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\{enum\notice\NoticeEnum,
|
||||
enum\user\UserTerminalEnum,
|
||||
enum\YesNoEnum,
|
||||
logic\BaseLogic,
|
||||
model\user\User,
|
||||
model\user\UserAuth,
|
||||
service\FileService,
|
||||
service\sms\SmsDriver,
|
||||
service\wechat\WeChatMnpService};
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 会员逻辑层
|
||||
* Class UserLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class UserLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 个人中心
|
||||
* @param array $userInfo
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:04
|
||||
*/
|
||||
public static function center(array $userInfo): array
|
||||
{
|
||||
$user = User::where(['id' => $userInfo['user_id']])
|
||||
->field('id,sn,sex,account,nickname,real_name,avatar,mobile,create_time,is_new_user,user_money,password')
|
||||
->findOrEmpty();
|
||||
|
||||
if (in_array($userInfo['terminal'], [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA])) {
|
||||
$auth = UserAuth::where(['user_id' => $userInfo['user_id'], 'terminal' => $userInfo['terminal']])->find();
|
||||
$user['is_auth'] = $auth ? YesNoEnum::YES : YesNoEnum::NO;
|
||||
}
|
||||
|
||||
$user['has_password'] = !empty($user['password']);
|
||||
$user->hidden(['password']);
|
||||
return $user->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 个人信息
|
||||
* @param $userId
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:45
|
||||
*/
|
||||
public static function info(int $userId)
|
||||
{
|
||||
$user = User::where(['id' => $userId])
|
||||
->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,create_time,user_money')
|
||||
->findOrEmpty();
|
||||
$user['has_password'] = !empty($user['password']);
|
||||
$user['has_auth'] = self::hasWechatAuth($userId);
|
||||
$user['version'] = config('project.version');
|
||||
$user->hidden(['password']);
|
||||
return $user->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置用户信息
|
||||
* @param int $userId
|
||||
* @param array $params
|
||||
* @return User|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 16:53
|
||||
*/
|
||||
public static function setInfo(int $userId, array $params)
|
||||
{
|
||||
try {
|
||||
if ($params['field'] == "avatar") {
|
||||
$params['value'] = FileService::setFileUrl($params['value']);
|
||||
}
|
||||
|
||||
return User::update([
|
||||
'id' => $userId,
|
||||
$params['field'] => $params['value']]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 是否有微信授权信息
|
||||
* @param $userId
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:36
|
||||
*/
|
||||
public static function hasWechatAuth(int $userId)
|
||||
{
|
||||
//是否有微信授权登录
|
||||
$terminal = [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA,UserTerminalEnum::PC];
|
||||
$auth = UserAuth::where(['user_id' => $userId])
|
||||
->whereIn('terminal', $terminal)
|
||||
->findOrEmpty();
|
||||
return !$auth->isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 重置登录密码
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:06
|
||||
*/
|
||||
public static function resetPassword(array $params)
|
||||
{
|
||||
try {
|
||||
// 校验验证码
|
||||
$smsDriver = new SmsDriver();
|
||||
if (!$smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA)) {
|
||||
throw new \Exception('验证码错误');
|
||||
}
|
||||
|
||||
// 重置密码
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
|
||||
// 更新
|
||||
User::where('mobile', $params['mobile'])->update([
|
||||
'password' => $password
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 修稿密码
|
||||
* @param $params
|
||||
* @param $userId
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:13
|
||||
*/
|
||||
public static function changePassword(array $params, int $userId)
|
||||
{
|
||||
try {
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
// 密码盐
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
|
||||
if (!empty($user['password'])) {
|
||||
if (empty($params['old_password'])) {
|
||||
throw new \Exception('请填写旧密码');
|
||||
}
|
||||
$oldPassword = create_password($params['old_password'], $passwordSalt);
|
||||
if ($oldPassword != $user['password']) {
|
||||
throw new \Exception('原密码不正确');
|
||||
}
|
||||
}
|
||||
|
||||
// 保存密码
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$user->password = $password;
|
||||
$user->save();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取小程序手机号
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
||||
* @author 段誉
|
||||
* @date 2023/2/27 11:49
|
||||
*/
|
||||
public static function getMobileByMnp(array $params)
|
||||
{
|
||||
try {
|
||||
$response = (new WeChatMnpService())->getUserPhoneNumber($params['code']);
|
||||
$phoneNumber = $response['phone_info']['purePhoneNumber'] ?? '';
|
||||
if (empty($phoneNumber)) {
|
||||
throw new \Exception('获取手机号码失败');
|
||||
}
|
||||
|
||||
$user = User::where([
|
||||
['mobile', '=', $phoneNumber],
|
||||
['id', '<>', $params['user_id']]
|
||||
])->findOrEmpty();
|
||||
|
||||
if (!$user->isEmpty()) {
|
||||
throw new \Exception('手机号已被其他账号绑定');
|
||||
}
|
||||
|
||||
// 绑定手机号
|
||||
User::update([
|
||||
'id' => $params['user_id'],
|
||||
'mobile' => $phoneNumber
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 绑定手机号
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 17:28
|
||||
*/
|
||||
public static function bindMobile(array $params)
|
||||
{
|
||||
try {
|
||||
// 变更手机号场景
|
||||
$sceneId = NoticeEnum::CHANGE_MOBILE_CAPTCHA;
|
||||
$where = [
|
||||
['id', '=', $params['user_id']],
|
||||
['mobile', '=', $params['mobile']]
|
||||
];
|
||||
|
||||
// 绑定手机号场景
|
||||
if ($params['type'] == 'bind') {
|
||||
$sceneId = NoticeEnum::BIND_MOBILE_CAPTCHA;
|
||||
$where = [
|
||||
['mobile', '=', $params['mobile']]
|
||||
];
|
||||
}
|
||||
|
||||
// 校验短信
|
||||
$checkSmsCode = (new SmsDriver())->verify($params['mobile'], $params['code'], $sceneId);
|
||||
if (!$checkSmsCode) {
|
||||
throw new \Exception('验证码错误');
|
||||
}
|
||||
|
||||
$user = User::where($where)->findOrEmpty();
|
||||
if (!$user->isEmpty()) {
|
||||
throw new \Exception('该手机号已被使用');
|
||||
}
|
||||
|
||||
User::update([
|
||||
'id' => $params['user_id'],
|
||||
'mobile' => $params['mobile'],
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\wechat\WeChatOaService;
|
||||
use EasyWeChat\Kernel\Exceptions\Exception;
|
||||
|
||||
/**
|
||||
* 微信
|
||||
* Class WechatLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class WechatLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 微信JSSDK授权接口
|
||||
* @param $params
|
||||
* @return false|mixed[]
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
||||
* @author 段誉
|
||||
* @date 2023/3/1 11:49
|
||||
*/
|
||||
public static function jsConfig($params)
|
||||
{
|
||||
try {
|
||||
$url = urldecode($params['url']);
|
||||
return (new WeChatOaService())->getJsConfig($url, [
|
||||
'onMenuShareTimeline',
|
||||
'onMenuShareAppMessage',
|
||||
'onMenuShareQQ',
|
||||
'onMenuShareWeibo',
|
||||
'onMenuShareQZone',
|
||||
'openLocation',
|
||||
'getLocation',
|
||||
'chooseWXPay',
|
||||
'updateAppMessageShareData',
|
||||
'updateTimelineShareData',
|
||||
'openAddress',
|
||||
'scanQRCode'
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
self::setError('获取jssdk失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\api\service;
|
||||
|
||||
use app\common\cache\UserTokenCache;
|
||||
use app\common\model\user\UserSession;
|
||||
use think\facade\Config;
|
||||
|
||||
class UserTokenService
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 设置或更新用户token
|
||||
* @param $userId
|
||||
* @param $terminal
|
||||
* @return array|false|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:10
|
||||
*/
|
||||
public static function setToken($userId, $terminal)
|
||||
{
|
||||
$time = time();
|
||||
$userSession = UserSession::where([['user_id', '=', $userId], ['terminal', '=', $terminal]])->find();
|
||||
|
||||
//获取token延长过期的时间
|
||||
$expireTime = $time + Config::get('project.user_token.expire_duration');
|
||||
$userTokenCache = new UserTokenCache();
|
||||
|
||||
//token处理
|
||||
if ($userSession) {
|
||||
//清空缓存
|
||||
$userTokenCache->deleteUserInfo($userSession->token);
|
||||
//重新获取token
|
||||
$userSession->token = create_token($userId);
|
||||
$userSession->expire_time = $expireTime;
|
||||
$userSession->update_time = $time;
|
||||
$userSession->save();
|
||||
} else {
|
||||
//找不到在该终端的token记录,创建token记录
|
||||
$userSession = UserSession::create([
|
||||
'user_id' => $userId,
|
||||
'terminal' => $terminal,
|
||||
'token' => create_token($userId),
|
||||
'expire_time' => $expireTime
|
||||
]);
|
||||
}
|
||||
|
||||
return $userTokenCache->setUserInfo($userSession->token);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 延长token过期时间
|
||||
* @param $token
|
||||
* @return array|false|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:10
|
||||
*/
|
||||
public static function overtimeToken($token)
|
||||
{
|
||||
$time = time();
|
||||
$userSession = UserSession::where('token', '=', $token)->find();
|
||||
if ($userSession->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//延长token过期时间
|
||||
$userSession->expire_time = $time + Config::get('project.user_token.expire_duration');
|
||||
$userSession->update_time = $time;
|
||||
$userSession->save();
|
||||
|
||||
return (new UserTokenCache())->setUserInfo($userSession->token);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置token为过期
|
||||
* @param $token
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:10
|
||||
*/
|
||||
public static function expireToken($token)
|
||||
{
|
||||
$userSession = UserSession::where('token', '=', $token)
|
||||
->find();
|
||||
if (empty($userSession)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$userSession->expire_time = $time;
|
||||
$userSession->update_time = $time;
|
||||
$userSession->save();
|
||||
|
||||
return (new UserTokenCache())->deleteUserInfo($token);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\service;
|
||||
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\model\user\{User, UserAuth};
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\service\{ConfigService, storage\Driver as StorageDriver};
|
||||
use think\Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 用户功能类(主要微信登录后创建和更新用户)
|
||||
* Class WechatUserService
|
||||
* @package app\api\service
|
||||
*/
|
||||
class WechatUserService
|
||||
{
|
||||
|
||||
protected int $terminal = UserTerminalEnum::WECHAT_MMP;
|
||||
protected array $response = [];
|
||||
protected ?string $code = null;
|
||||
protected ?string $openid = null;
|
||||
protected ?string $unionid = null;
|
||||
protected ?string $nickname = null;
|
||||
protected ?string $headimgurl = null;
|
||||
protected User $user;
|
||||
|
||||
|
||||
public function __construct(array $response, int $terminal)
|
||||
{
|
||||
$this->terminal = $terminal;
|
||||
$this->setParams($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置微信返回的用户信息
|
||||
* @param $response
|
||||
* @author cjhao
|
||||
* @date 2021/8/2 11:49
|
||||
*/
|
||||
private function setParams($response): void
|
||||
{
|
||||
$this->response = $response;
|
||||
$this->openid = $response['openid'];
|
||||
$this->unionid = $response['unionid'] ?? '';
|
||||
$this->nickname = $response['nickname'] ?? '';
|
||||
$this->headimgurl = $response['headimgurl'] ?? '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 根据opendid或unionid获取系统用户信息
|
||||
* @return $this
|
||||
* @author 段誉
|
||||
* @date 2022/9/23 16:09
|
||||
*/
|
||||
public function getResopnseByUserInfo(): self
|
||||
{
|
||||
$openid = $this->openid;
|
||||
$unionid = $this->unionid;
|
||||
|
||||
$user = User::alias('u')
|
||||
->field('u.id,u.sn,u.mobile,u.nickname,u.avatar,u.mobile,u.is_disable,u.is_new_user')
|
||||
->join('user_auth au', 'au.user_id = u.id')
|
||||
->where(function ($query) use ($openid, $unionid) {
|
||||
$query->whereOr(['au.openid' => $openid]);
|
||||
if (isset($unionid) && $unionid) {
|
||||
$query->whereOr(['au.unionid' => $unionid]);
|
||||
}
|
||||
})
|
||||
->findOrEmpty();
|
||||
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取用户信息
|
||||
* @param bool $isCheck 是否验证账号是否可用
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @author cjhao
|
||||
* @date 2021/8/3 11:42
|
||||
*/
|
||||
public function getUserInfo($isCheck = true): array
|
||||
{
|
||||
if (!$this->user->isEmpty() && $isCheck) {
|
||||
$this->checkAccount();
|
||||
}
|
||||
if (!$this->user->isEmpty()) {
|
||||
$this->getToken();
|
||||
}
|
||||
return $this->user->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验账号
|
||||
* @throws Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:14
|
||||
*/
|
||||
private function checkAccount()
|
||||
{
|
||||
if ($this->user->is_disable) {
|
||||
throw new Exception('您的账号异常,请联系客服。');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 创建用户
|
||||
* @throws Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:06
|
||||
*/
|
||||
private function createUser(): void
|
||||
{
|
||||
//设置头像
|
||||
if (empty($this->headimgurl)) {
|
||||
// 默认头像
|
||||
$defaultAvatar = config('project.default_image.user_avatar');
|
||||
$avatar = ConfigService::get('default_image', 'user_avatar', $defaultAvatar);
|
||||
} else {
|
||||
// 微信获取到的头像信息
|
||||
$avatar = $this->getAvatarByWechat();
|
||||
}
|
||||
|
||||
$userSn = User::createUserSn();
|
||||
$this->user->sn = $userSn;
|
||||
$this->user->account = 'u' . $userSn;
|
||||
$this->user->nickname = "用户" . $userSn;
|
||||
$this->user->avatar = $avatar;
|
||||
$this->user->channel = $this->terminal;
|
||||
$this->user->is_new_user = YesNoEnum::YES;
|
||||
|
||||
if ($this->terminal != UserTerminalEnum::WECHAT_MMP && !empty($this->nickname)) {
|
||||
$this->user->nickname = $this->nickname;
|
||||
}
|
||||
|
||||
$this->user->save();
|
||||
|
||||
UserAuth::create([
|
||||
'user_id' => $this->user->id,
|
||||
'openid' => $this->openid,
|
||||
'unionid' => $this->unionid,
|
||||
'terminal' => $this->terminal,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新用户信息
|
||||
* @throws Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:06
|
||||
* @remark 该端没授权信息,重新写入一条该端的授权信息
|
||||
*/
|
||||
private function updateUser(): void
|
||||
{
|
||||
// 无头像需要更新头像
|
||||
if (empty($this->user->avatar)) {
|
||||
$this->user->avatar = $this->getAvatarByWechat();
|
||||
$this->user->save();
|
||||
}
|
||||
|
||||
$userAuth = UserAuth::where(['user_id' => $this->user->id, 'openid' => $this->openid])
|
||||
->findOrEmpty();
|
||||
|
||||
// 无该端授权信息,新增一条
|
||||
if ($userAuth->isEmpty()) {
|
||||
$userAuth->user_id = $this->user->id;
|
||||
$userAuth->openid = $this->openid;
|
||||
$userAuth->unionid = $this->unionid;
|
||||
$userAuth->terminal = $this->terminal;
|
||||
$userAuth->save();
|
||||
} else {
|
||||
if (empty($userAuth['unionid']) && !empty($this->unionid)) {
|
||||
$userAuth->unionid = $this->unionid;
|
||||
$userAuth->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取token
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2021/8/2 16:45
|
||||
*/
|
||||
private function getToken(): void
|
||||
{
|
||||
$user = UserTokenService::setToken($this->user->id, $this->terminal);
|
||||
$this->user->token = $user['token'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 用户授权登录,
|
||||
* 如果用户不存在,创建用户;用户存在,更新用户信息,并检查该端信息是否需要写入
|
||||
* @return WechatUserService
|
||||
* @throws Exception
|
||||
* @author cjhao
|
||||
* @date 2021/8/2 16:35
|
||||
*/
|
||||
public function authUserLogin(): self
|
||||
{
|
||||
if ($this->user->isEmpty()) {
|
||||
$this->createUser();
|
||||
} else {
|
||||
$this->updateUser();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 处理从微信获取到的头像信息
|
||||
* @return string
|
||||
* @throws Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 9:50
|
||||
*/
|
||||
public function getAvatarByWechat(): string
|
||||
{
|
||||
// 存储引擎
|
||||
$config = [
|
||||
'default' => ConfigService::get('storage', 'default', 'local'),
|
||||
'engine' => ConfigService::get('storage')
|
||||
];
|
||||
|
||||
$fileName = md5($this->openid . time()) . '.jpeg';
|
||||
|
||||
if ($config['default'] == 'local') {
|
||||
// 本地存储
|
||||
$avatar = download_file($this->headimgurl, 'uploads/user/avatar/', $fileName);
|
||||
} else {
|
||||
// 第三方存储
|
||||
$avatar = 'uploads/user/avatar/' . $fileName;
|
||||
$StorageDriver = new StorageDriver($config);
|
||||
if (!$StorageDriver->fetch($this->headimgurl, $avatar)) {
|
||||
throw new Exception('头像保存失败:' . $StorageDriver->getError());
|
||||
}
|
||||
}
|
||||
return $avatar;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use app\common\cache\UserAccountSafeCache;
|
||||
use app\common\enum\LoginEnum;
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\sms\SmsDriver;
|
||||
use app\common\validate\BaseValidate;
|
||||
use app\common\model\user\User;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 账号密码登录校验
|
||||
* Class LoginValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class LoginAccountValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'terminal' => 'require|in:' . UserTerminalEnum::WECHAT_MMP . ',' . UserTerminalEnum::WECHAT_OA . ','
|
||||
. UserTerminalEnum::H5 . ',' . UserTerminalEnum::PC . ',' . UserTerminalEnum::IOS .
|
||||
',' . UserTerminalEnum::ANDROID,
|
||||
'scene' => 'require|in:' . LoginEnum::ACCOUNT_PASSWORD . ',' . LoginEnum::MOBILE_CAPTCHA . '|checkConfig',
|
||||
'account' => 'require',
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'terminal.require' => '终端参数缺失',
|
||||
'terminal.in' => '终端参数状态值不正确',
|
||||
'scene.require' => '场景不能为空',
|
||||
'scene.in' => '场景值错误',
|
||||
'account.require' => '请输入账号',
|
||||
'password.require' => '请输入密码',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 登录场景相关校验
|
||||
* @param $scene
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 14:37
|
||||
*/
|
||||
public function checkConfig($scene, $rule, $data)
|
||||
{
|
||||
$config = ConfigService::get('login', 'login_way');
|
||||
if (!in_array($scene, $config)) {
|
||||
return '不支持的登录方式';
|
||||
}
|
||||
|
||||
// 账号密码登录
|
||||
if (LoginEnum::ACCOUNT_PASSWORD == $scene) {
|
||||
if (!isset($data['password'])) {
|
||||
return '请输入密码';
|
||||
}
|
||||
return $this->checkPassword($data['password'], [], $data);
|
||||
}
|
||||
|
||||
// 手机验证码登录
|
||||
if (LoginEnum::MOBILE_CAPTCHA == $scene) {
|
||||
if (!isset($data['code'])) {
|
||||
return '请输入手机验证码';
|
||||
}
|
||||
return $this->checkCode($data['code'], [], $data);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 登录密码校验
|
||||
* @param $password
|
||||
* @param $other
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 14:39
|
||||
*/
|
||||
public function checkPassword($password, $other, $data)
|
||||
{
|
||||
//账号安全机制,连续输错后锁定,防止账号密码暴力破解
|
||||
$userAccountSafeCache = new UserAccountSafeCache();
|
||||
if (!$userAccountSafeCache->isSafe()) {
|
||||
return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试';
|
||||
}
|
||||
|
||||
$where = [];
|
||||
if ($data['scene'] == LoginEnum::ACCOUNT_PASSWORD) {
|
||||
// 手机号密码登录
|
||||
$where = ['account|mobile' => $data['account']];
|
||||
}
|
||||
|
||||
$userInfo = User::where($where)
|
||||
->field(['password,is_disable'])
|
||||
->findOrEmpty();
|
||||
|
||||
if ($userInfo->isEmpty()) {
|
||||
return '用户不存在';
|
||||
}
|
||||
|
||||
if ($userInfo['is_disable'] === YesNoEnum::YES) {
|
||||
return '用户已禁用';
|
||||
}
|
||||
|
||||
if (empty($userInfo['password'])) {
|
||||
$userAccountSafeCache->record();
|
||||
return '用户不存在';
|
||||
}
|
||||
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
if ($userInfo['password'] !== create_password($password, $passwordSalt)) {
|
||||
$userAccountSafeCache->record();
|
||||
return '密码错误';
|
||||
}
|
||||
|
||||
$userAccountSafeCache->relieve();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验验证码
|
||||
* @param $code
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author Tab
|
||||
* @date 2021/8/25 15:43
|
||||
*/
|
||||
public function checkCode($code, $rule, $data)
|
||||
{
|
||||
$smsDriver = new SmsDriver();
|
||||
$result = $smsDriver->verify($data['account'], $code, NoticeEnum::LOGIN_CAPTCHA);
|
||||
if ($result) {
|
||||
return true;
|
||||
}
|
||||
return '验证码错误';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\validate;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 密码校验
|
||||
* Class PasswordValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class PasswordValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'mobile' => 'require|mobile',
|
||||
'code' => 'require',
|
||||
'password' => 'require|length:6,20|alphaNum',
|
||||
'password_confirm' => 'require|confirm',
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'mobile.require' => '请输入手机号',
|
||||
'mobile.mobile' => '请输入正确手机号',
|
||||
'code.require' => '请填写验证码',
|
||||
'password.require' => '请输入密码',
|
||||
'password.length' => '密码须在6-25位之间',
|
||||
'password.alphaNum' => '密码须为字母数字组合',
|
||||
'password_confirm.require' => '请确认密码',
|
||||
'password_confirm.confirm' => '两次输入的密码不一致'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 重置登录密码
|
||||
* @return PasswordValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:11
|
||||
*/
|
||||
public function sceneResetPassword()
|
||||
{
|
||||
return $this->only(['mobile', 'code', 'password', 'password_confirm']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 修改密码场景
|
||||
* @return PasswordValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:14
|
||||
*/
|
||||
public function sceneChangePassword()
|
||||
{
|
||||
return $this->only(['password', 'password_confirm']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 支付验证
|
||||
* Class PayValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class PayValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'from' => 'require',
|
||||
'pay_way' => 'require|in:' . PayEnum::BALANCE_PAY . ',' . PayEnum::WECHAT_PAY . ',' . PayEnum::ALI_PAY,
|
||||
'order_id' => 'require'
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'from.require' => '参数缺失',
|
||||
'pay_way.require' => '支付方式参数缺失',
|
||||
'pay_way.in' => '支付方式参数错误',
|
||||
'order_id.require' => '订单参数缺失'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 支付方式场景
|
||||
* @return PayValidate
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 17:43
|
||||
*/
|
||||
public function scenePayway()
|
||||
{
|
||||
return $this->only(['from', 'order_id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 支付状态
|
||||
* @return PayValidate
|
||||
* @author 段誉
|
||||
* @date 2023/3/1 16:17
|
||||
*/
|
||||
public function sceneStatus()
|
||||
{
|
||||
return $this->only(['from', 'order_id']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 用户验证器
|
||||
* Class UserValidate
|
||||
* @package app\shopapi\validate
|
||||
*/
|
||||
class RechargeValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'money' => 'require|gt:0|checkMoney',
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'money.require' => '请填写充值金额',
|
||||
'money.gt' => '请填写大于0的充值金额',
|
||||
];
|
||||
|
||||
|
||||
public function sceneRecharge()
|
||||
{
|
||||
return $this->only(['money']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验金额
|
||||
* @param $money
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 10:42
|
||||
*/
|
||||
protected function checkMoney($money, $rule, $data)
|
||||
{
|
||||
$status = ConfigService::get('recharge', 'status', 0);
|
||||
if (!$status) {
|
||||
return '充值功能已关闭';
|
||||
}
|
||||
|
||||
$minAmount = ConfigService::get('recharge', 'min_amount', 0);
|
||||
|
||||
if ($money < $minAmount) {
|
||||
return '最低充值金额' . $minAmount . "元";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\validate;
|
||||
|
||||
|
||||
use app\common\model\user\User;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 注册验证器
|
||||
* Class RegisterValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class RegisterValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $regex = [
|
||||
'register' => '^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]+$',
|
||||
'password' => '/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-z]|[A-Z]|[0-9]){6,20}$/'
|
||||
];
|
||||
|
||||
protected $rule = [
|
||||
'channel' => 'require',
|
||||
'account' => 'require|length:3,12|unique:' . User::class . '|regex:register',
|
||||
'password' => 'require|length:6,20|regex:password',
|
||||
'password_confirm' => 'require|confirm'
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'channel.require' => '注册来源参数缺失',
|
||||
'account.require' => '请输入账号',
|
||||
'account.regex' => '账号须为字母数字组合',
|
||||
'account.length' => '账号须为3-12位之间',
|
||||
'account.unique' => '账号已存在',
|
||||
'password.require' => '请输入密码',
|
||||
'password.length' => '密码须在6-25位之间',
|
||||
'password.regex' => '密码须为数字,字母或符号组合',
|
||||
'password_confirm.require' => '请确认密码',
|
||||
'password_confirm.confirm' => '两次输入的密码不一致'
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 短信验证
|
||||
* Class SmsValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class SendSmsValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'mobile' => 'require|mobile',
|
||||
'scene' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'mobile.require' => '请输入手机号',
|
||||
'mobile.mobile' => '请输入正确手机号',
|
||||
'scene.require' => '请输入场景值',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
|
||||
use app\common\model\user\User;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 设置用户信息验证
|
||||
* Class SetUserInfoValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class SetUserInfoValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'field' => 'require|checkField',
|
||||
'value' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'field.require' => '参数缺失',
|
||||
'value.require' => '值不存在',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验字段内容
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 17:01
|
||||
*/
|
||||
protected function checkField($value, $rule, $data)
|
||||
{
|
||||
$allowField = [
|
||||
'nickname', 'account', 'sex', 'avatar', 'real_name',
|
||||
];
|
||||
|
||||
if (!in_array($value, $allowField)) {
|
||||
return '参数错误';
|
||||
}
|
||||
|
||||
if ($value == 'account') {
|
||||
$user = User::where([
|
||||
['account', '=', $data['value']],
|
||||
['id', '<>', $data['id']]
|
||||
])->findOrEmpty();
|
||||
if (!$user->isEmpty()) {
|
||||
return '账号已被使用!';
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 用户验证器
|
||||
* Class UserValidate
|
||||
* @package app\shopapi\validate
|
||||
*/
|
||||
class UserValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'code' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'code.require' => '参数缺失',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取小程序手机号场景
|
||||
* @return UserValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 16:44
|
||||
*/
|
||||
public function sceneGetMobileByMnp()
|
||||
{
|
||||
return $this->only(['code']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 绑定/变更 手机号
|
||||
* @return UserValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 17:37
|
||||
*/
|
||||
public function sceneBindMobile()
|
||||
{
|
||||
return $this->only(['mobile', 'code']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use app\common\cache\WebScanLoginCache;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 网站扫码登录验证
|
||||
* Class WebScanLoginValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class WebScanLoginValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'code' => 'require',
|
||||
'state' => 'require|checkState',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'code.require' => '参数缺失',
|
||||
'state.require' => '昵称缺少',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验登录状态标记
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/10/21 9:47
|
||||
*/
|
||||
protected function checkState($value, $rule, $data)
|
||||
{
|
||||
$check = (new WebScanLoginCache())->getScanLoginState($value);
|
||||
|
||||
if (empty($check)) {
|
||||
return '二维码已失效或不存在,请重新扫码';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 微信登录验证
|
||||
* Class WechatLoginValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class WechatLoginValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'code' => 'require',
|
||||
'nickname' => 'require',
|
||||
'headimgurl' => 'require',
|
||||
'openid' => 'require',
|
||||
'access_token' => 'require',
|
||||
'terminal' => 'require',
|
||||
'avatar' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'code.require' => 'code缺少',
|
||||
'nickname.require' => '昵称缺少',
|
||||
'headimgurl.require' => '头像缺少',
|
||||
'openid.require' => 'opendid缺少',
|
||||
'access_token.require' => 'access_token缺少',
|
||||
'terminal.require' => '终端参数缺少',
|
||||
'avatar.require' => '头像缺少',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 公众号登录场景
|
||||
* @return WechatLoginValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:57
|
||||
*/
|
||||
public function sceneOa()
|
||||
{
|
||||
return $this->only(['code']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序-授权登录场景
|
||||
* @return WechatLoginValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 11:15
|
||||
*/
|
||||
public function sceneMnpLogin()
|
||||
{
|
||||
return $this->only(['code']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes
|
||||
* @return WechatLoginValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 11:15
|
||||
*/
|
||||
public function sceneWechatAuth()
|
||||
{
|
||||
return $this->only(['code']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新用户信息场景
|
||||
* @return WechatLoginValidate
|
||||
* @author 段誉
|
||||
* @date 2023/2/22 11:14
|
||||
*/
|
||||
public function sceneUpdateUser()
|
||||
{
|
||||
return $this->only(['nickname', 'avatar']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 微信验证器
|
||||
* Class WechatValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class WechatValidate extends BaseValidate
|
||||
{
|
||||
public $rule = [
|
||||
'url' => 'require'
|
||||
];
|
||||
|
||||
public $message = [
|
||||
'url.require' => '请提供url'
|
||||
];
|
||||
|
||||
public function sceneJsConfig()
|
||||
{
|
||||
return $this->only(['url']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user