Compare commits
No commits in common. 'main' and 'master' have entirely different histories.
@ -0,0 +1,8 @@
|
||||
/.idea
|
||||
/.vscode
|
||||
/runtime
|
||||
/public/uploads
|
||||
/public/ueditor
|
||||
/public/temp
|
||||
/config/database.php
|
||||
/.env
|
@ -0,0 +1,42 @@
|
||||
sudo: false
|
||||
|
||||
language: php
|
||||
|
||||
branches:
|
||||
only:
|
||||
- stable
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
before_install:
|
||||
- composer self-update
|
||||
|
||||
install:
|
||||
- composer install --no-dev --no-interaction --ignore-platform-reqs
|
||||
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip .
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-image:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0"
|
||||
- composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0"
|
||||
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip .
|
||||
|
||||
script:
|
||||
- php think unit
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw=
|
||||
file:
|
||||
- ThinkPHP_Core.zip
|
||||
- ThinkPHP_Full.zip
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
@ -0,0 +1,2 @@
|
||||
本项目审核阶段,
|
||||
1.登录手机号固定17343089220 验证码1234 登入 方便审核人员审核
|
@ -0,0 +1 @@
|
||||
deny from all
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\Service;
|
||||
|
||||
/**
|
||||
* 应用服务类
|
||||
*/
|
||||
class AppService extends Service
|
||||
{
|
||||
public function register()
|
||||
{
|
||||
// 服务注册
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
// 服务启动
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class BaseController
|
||||
{
|
||||
/**
|
||||
* Request实例
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 是否批量验证
|
||||
* @var bool
|
||||
*/
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 控制器中间件
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
* @access protected
|
||||
* @param array $data 数据
|
||||
* @param string|array $validate 验证器名或者验证规则数组
|
||||
* @param array $message 提示信息
|
||||
* @param bool $batch 是否批量验证
|
||||
* @return array|string|true
|
||||
* @throws ValidateException
|
||||
*/
|
||||
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
|
||||
{
|
||||
if (is_array($validate)) {
|
||||
$v = new Validate();
|
||||
$v->rule($validate);
|
||||
} else {
|
||||
if (strpos($validate, '.')) {
|
||||
// 支持场景
|
||||
[$validate, $scene] = explode('.', $validate);
|
||||
}
|
||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||
$v = new $class();
|
||||
if (!empty($scene)) {
|
||||
$v->scene($scene);
|
||||
}
|
||||
}
|
||||
|
||||
$v->message($message);
|
||||
|
||||
// 是否批量验证
|
||||
if ($batch || $this->batchValidate) {
|
||||
$v->batch(true);
|
||||
}
|
||||
|
||||
return $v->failException(true)->check($data);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class BaseLogic extends Model
|
||||
{
|
||||
|
||||
protected $mid;
|
||||
protected $userAgent; //客户端 weixin--微信公众号 mp_weixin--微信小程序 mp_qq--QQ小程序 app--APP
|
||||
protected $userId; //用户ID
|
||||
protected $openid; //用户平台ID
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @date 2020-07-27
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
if (isset($data['uid'])) {
|
||||
$this->mid = $data['uid'];
|
||||
} else {
|
||||
if (defined('UID')) {
|
||||
$this->mid = UID;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['user_agent'])) {
|
||||
$this->userAgent = $data['user_agent'];
|
||||
} else {
|
||||
if (defined('USER_AGENT')) {
|
||||
$this->userAgent = USER_AGENT;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['user_id'])) {
|
||||
$this->userId = $data['user_id'];
|
||||
} else {
|
||||
if (defined('USER_ID')) {
|
||||
$this->userId = USER_ID;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['openid'])) {
|
||||
$this->openid = $data['openid'];
|
||||
} else {
|
||||
if (defined('OPENID')) {
|
||||
$this->openid = OPENID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class BaseService extends Model
|
||||
{
|
||||
|
||||
protected $mid;
|
||||
protected $userAgent; //客户端 weixin--微信公众号 mp_weixin--微信小程序 mp_qq--QQ小程序 app--APP
|
||||
protected $userId; //用户ID
|
||||
protected $openid; //用户平台ID
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @date 2022-07-27
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
if (isset($data['uid'])) {
|
||||
$this->mid = $data['uid'];
|
||||
} else {
|
||||
if (defined('UID')) {
|
||||
$this->mid = UID;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['user_agent'])) {
|
||||
$this->userAgent = $data['user_agent'];
|
||||
} else {
|
||||
if (defined('USER_AGENT')) {
|
||||
$this->userAgent = USER_AGENT;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['user_id'])) {
|
||||
$this->userId = $data['user_id'];
|
||||
} else {
|
||||
if (defined('USER_ID')) {
|
||||
$this->userId = USER_ID;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['openid'])) {
|
||||
$this->openid = $data['openid'];
|
||||
} else {
|
||||
if (defined('OPENID')) {
|
||||
$this->openid = OPENID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\Handle;
|
||||
use think\exception\HttpException;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Response;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 应用异常处理类
|
||||
*/
|
||||
class ExceptionHandle extends Handle
|
||||
{
|
||||
/**
|
||||
* 不需要记录信息(日志)的异常类列表
|
||||
* @var array
|
||||
*/
|
||||
protected $ignoreReport = [
|
||||
HttpException::class,
|
||||
HttpResponseException::class,
|
||||
ModelNotFoundException::class,
|
||||
DataNotFoundException::class,
|
||||
ValidateException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 记录异常信息(包括日志或者其它方式记录)
|
||||
*
|
||||
* @access public
|
||||
* @param Throwable $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Throwable $exception): void
|
||||
{
|
||||
// 使用内置的方式记录异常日志
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @access public
|
||||
* @param \think\Request $request
|
||||
* @param Throwable $e
|
||||
* @return Response
|
||||
*/
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 添加自定义异常处理机制
|
||||
if ($e instanceof ValidateException) { //验证器异常抛出
|
||||
return response(sendArray([], 2100, $e->getError()),200,[],'json');
|
||||
}
|
||||
|
||||
// 其他错误交给系统处理
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace app;
|
||||
|
||||
// 应用请求对象类
|
||||
class Request extends \think\Request
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
namespace app\account\controller\admin;
|
||||
|
||||
use app\account\model\Nickname;
|
||||
use app\auth\model\AuthGroup;
|
||||
use app\auth\model\AuthGroupRule;
|
||||
use app\auth\model\AuthRule;
|
||||
use app\system\logic\Login;
|
||||
use app\system\model\SystemLoginer;
|
||||
use think\facade\View;
|
||||
|
||||
class Account extends Base
|
||||
{
|
||||
/**
|
||||
* 子账号列表
|
||||
* @return string
|
||||
*/
|
||||
public function account()
|
||||
{
|
||||
$search = input('get.');
|
||||
autoSearch(['time', 'keyword'], $search);
|
||||
$system_login_er_model = new SystemLoginer();
|
||||
$where = [
|
||||
['status', '>=', 0],
|
||||
['rank', '>=', 1],
|
||||
];
|
||||
if ($search['time']) {
|
||||
$time = explode('-', $search['time']);
|
||||
$where[] = ['create_time', 'between time', [$time[0], $time[1]]];
|
||||
}
|
||||
if ($search['keyword']) {
|
||||
$where[] = ['username', 'like', '%' . $search['keyword'] . '%'];
|
||||
}
|
||||
$dataList = $system_login_er_model
|
||||
->with(['loginGroup'])->where($where)->order('id desc')
|
||||
->paginate([
|
||||
'list_rows' => 20,
|
||||
'page' => array_key_exists("page", $search) ? (string)$search['page'] : "1",
|
||||
'query' => $search
|
||||
], false);
|
||||
View::assign('search', $search);
|
||||
View::assign('dataList', $dataList);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 子账号添加 2017-10-15
|
||||
*/
|
||||
public function accountAdd()
|
||||
{
|
||||
$system_loginer_model = new SystemLoginer();
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
|
||||
if ($data['password'] != $data['repassword']) {
|
||||
return sendErrorMessage(1,'添加失败,密码和重复密码不一致!');
|
||||
}
|
||||
|
||||
$is_username = $system_loginer_model->getOneData([['username', '=', $data['username']], ['id', 'not in', (string)$data['id']]]);
|
||||
if (!empty($is_username)) {
|
||||
return sendErrorMessage(1,'用户名重复,请更换用户名');
|
||||
}
|
||||
$data['password_real'] = $data['password'];
|
||||
if (!$data['id']) {
|
||||
$Login = new Login();
|
||||
$loginerid = $Login->register($data['username'], $data['password']);
|
||||
if ($loginerid > 0) { //注册成功
|
||||
$my = $system_loginer_model->getOneData([['id','=', LID]]);
|
||||
$userData = [
|
||||
'id' => $loginerid,
|
||||
'uid' => UID,
|
||||
'pid' => LID,
|
||||
'rank' => $my['rank'] + 1,
|
||||
'register_time' => time(),
|
||||
'register_ip' => getClientIp(1),
|
||||
'role_id' => $data['role_id'],
|
||||
'status' => 1
|
||||
];
|
||||
if (!empty($data['end_time'])) {
|
||||
$userData['end_time'] = strtotime($data['end_time']);
|
||||
}
|
||||
$res = $system_loginer_model->dataUpdate($userData);
|
||||
if (!$res) {
|
||||
return sendErrorMessage();
|
||||
}
|
||||
return sendSuccessMessage();
|
||||
} else {
|
||||
return sendErrorMessage(1,'用户名重复,请更换用户名');
|
||||
}
|
||||
} else {
|
||||
if (!empty($data['password'])) {
|
||||
$arr = ['password' => $data['password']];
|
||||
$Login = new Login();
|
||||
$res1 = $Login->updateUserInfo($data['id'], false, $arr);
|
||||
}
|
||||
unset($data['password']);
|
||||
if (!empty($data['end_time'])) {
|
||||
$data['end_time'] = strtotime($data['end_time']);
|
||||
} else {
|
||||
unset($data['end_time']);
|
||||
}
|
||||
$res = $system_loginer_model->dataUpdate($data);
|
||||
if (!$res) {
|
||||
return sendErrorMessage();
|
||||
}
|
||||
return sendSuccessMessage();
|
||||
}
|
||||
} else {
|
||||
$id = input('param.id', 0);
|
||||
$data = $system_loginer_model->getOneData(['id' => $id]);
|
||||
$auth_group_model = new AuthGroup();
|
||||
$groupList = $auth_group_model->getAllData(['status' => 1]);
|
||||
|
||||
if (!empty($data['end_time'])) {
|
||||
$data['end_time'] = date('Y-m-d H:i:s', $data['end_time']);
|
||||
}
|
||||
|
||||
View::assign('data', $data);
|
||||
View::assign('groupList', $groupList);
|
||||
return View::fetch('accountadd');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 子账号修改
|
||||
*/
|
||||
public function accountUpdate()
|
||||
{
|
||||
return $this->accountadd();
|
||||
}
|
||||
|
||||
/**
|
||||
* 子账号修改状态
|
||||
* @return array|string
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function accountStatus()
|
||||
{
|
||||
$data = input('post.');
|
||||
$system_loginer_model = new SystemLoginer();
|
||||
//修改子账号ID
|
||||
$res = $system_loginer_model->where('id', $data['id'])->update(['status' => $data['afterchange']]);
|
||||
if ($res === false) {
|
||||
return sendErrorMessage(1);
|
||||
}
|
||||
return sendSuccessMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*
|
||||
*/
|
||||
public function role()
|
||||
{
|
||||
$search = input('get.');
|
||||
autoSearch(['time', 'keyword'], $search);
|
||||
View::assign('search', $search);
|
||||
$where = [
|
||||
'status' => 1,
|
||||
];
|
||||
$auth_group_model = new AuthGroup();
|
||||
// dump(111);exit();
|
||||
$page = array_key_exists("page", $search) ? (string)$search['page'] : "1";
|
||||
$dataList = $auth_group_model
|
||||
->where($where)->order('id asc')
|
||||
->paginate(['list_rows' => 50, 'page' => $page], false)->each(function ($item, $key) {
|
||||
return $item;
|
||||
});
|
||||
View::assign('dataList', $dataList);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色添加
|
||||
*/
|
||||
public function roleAdd()
|
||||
{
|
||||
$auth_group_model = new AuthGroup();
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
$data['uid'] = UID;
|
||||
//事务处理
|
||||
$res = $auth_group_model->dataUpdate($data);
|
||||
if (!$res) {
|
||||
return sendErrorMessage(1);
|
||||
}
|
||||
return sendSuccessMessage();
|
||||
} else {
|
||||
$id = input('param.id', 0);
|
||||
$data = $auth_group_model->getOneData(['id' => $id]);
|
||||
View::assign('data', $data);
|
||||
return View::fetch('roleadd');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色修改 2017-10-15
|
||||
*/
|
||||
public function roleUpdate()
|
||||
{
|
||||
return $this->roleadd();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
* @auth Alan
|
||||
* @time 2019-03-11
|
||||
* @return array|string
|
||||
*/
|
||||
public function roleDelete()
|
||||
{
|
||||
$id = input('post.id/d', 0);
|
||||
//删除角色同时删除角色关联权限
|
||||
$res = AuthGroup::destroy($id);
|
||||
if ($res === false) {
|
||||
return sendErrorMessage(1);
|
||||
}
|
||||
$loginer_model = new SystemLoginer();
|
||||
$auth_group_rule_model = new AuthGroupRule();
|
||||
|
||||
$loginer_count = $loginer_model->where(['role_id'=>$id])->count();
|
||||
if($loginer_count)
|
||||
{
|
||||
return sendErrorMessage(1,'该角色已赋予账号,不可删除');
|
||||
}
|
||||
$res = $auth_group_rule_model->where(['role_id' => $id])->delete();
|
||||
if ($res === false) {
|
||||
return sendErrorMessage(1);
|
||||
}
|
||||
|
||||
return sendSuccessMessage();
|
||||
}
|
||||
|
||||
/*
|
||||
* 角色授权
|
||||
*/
|
||||
|
||||
public function roleSetAuth()
|
||||
{
|
||||
$auth_group_model = new AuthGroup();
|
||||
$auth_group_rule_model = new AuthGroupRule();
|
||||
$auth_rule_model = new AuthRule();
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
$rule_list = [];
|
||||
if (!empty($data['authrule'])) {
|
||||
$rule_list = $data['authrule'];
|
||||
}
|
||||
//事务处理
|
||||
$res = $auth_group_rule_model->saveData($data['id'], $rule_list);
|
||||
if (!$res) {
|
||||
return sendErrorMessage(1);
|
||||
}
|
||||
return sendSuccessMessage();
|
||||
} else {
|
||||
$id = input('param.id');
|
||||
$data = $auth_group_model->getOneData(['id' => $id]);
|
||||
View::assign('data', $data);
|
||||
$auth = $auth_rule_model->getLevelData();
|
||||
View::assign('auth', $auth);
|
||||
$ids = $auth_group_rule_model->getIds($id);
|
||||
View::assign('rule_ids', $ids);
|
||||
return View::fetch('rolesetauth');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace app\account\controller\admin;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
use think\facade\View;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\account\logic;
|
||||
|
||||
use app\BaseLogic;
|
||||
|
||||
class Base extends BaseLogic
|
||||
{
|
||||
|
||||
protected $mid;
|
||||
protected $userAgent;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @date 2020-07-27
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
|
||||
if (isset($data['uid'])) {
|
||||
$mid = $data['uid'];
|
||||
} else {
|
||||
if (defined('UID')) {
|
||||
$mid = UID;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['user_agent'])) {
|
||||
$this->userAgent = $data['user_agent'];
|
||||
} else {
|
||||
if (defined('USER_AGENT')) {
|
||||
$this->userAgent = USER_AGENT;
|
||||
}
|
||||
}
|
||||
|
||||
$this->mid = isset($mid) ? $mid : 2;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace app\account\model;
|
||||
|
||||
use app\BaseModel;
|
||||
|
||||
class Base extends BaseModel
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @date 2020-07-27
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
use think\facade\Route;
|
||||
|
||||
//Route::rule(':controller_type_name/:controller_name/:function_name', ':controller_type_name.:controller_name/:function_name');
|
||||
//Route::rule('admin/:controller_name/:function_name', 'admin.:controller_name/:function_name')
|
||||
// ->pattern(['controller_name' => ''])
|
||||
// ->middleware(\app\middleware\CheckAdmin::class, 'user');
|
||||
Route::rule(':controller_name/:function_name', 'admin.:controller_name/:function_name')
|
||||
->middleware(\app\middleware\CheckAdmin::class);
|
||||
|
||||
|
||||
|
@ -0,0 +1,656 @@
|
||||
<?php
|
||||
|
||||
namespace app\auth\controller\admin;
|
||||
|
||||
use app\auth\model\AuthGroupRule;
|
||||
use app\auth\model\AuthRule;
|
||||
use app\auth\model\AuthRuleParam;
|
||||
use think\facade\View;
|
||||
|
||||
class Auth extends Base
|
||||
{
|
||||
|
||||
/***
|
||||
* 权限列表
|
||||
* @return string
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
//获取数据总数
|
||||
$auth_rule_model = new AuthRule();
|
||||
//获取数据信息
|
||||
$dataList = $auth_rule_model->getListAll();
|
||||
View::assign('dataList', $dataList);
|
||||
|
||||
//获取参数列表信息
|
||||
$auth_rule_param_model = new AuthRuleParam();
|
||||
$param = $auth_rule_param_model->getListByRule();
|
||||
View::assign('param', $param);
|
||||
return View::fetch('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限组添加
|
||||
* @return string
|
||||
*/
|
||||
public function authGroupAdd()
|
||||
{
|
||||
$auth_rule_model = new AuthRule();
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
|
||||
$data['uid'] = 2;
|
||||
//权限值进行小写操作
|
||||
$data['rule_val'] = strtolower($data['rule_val']);
|
||||
$data['group_name'] = $data['rule_val'];
|
||||
//判断是否存在
|
||||
if ($data['id'] != "") {
|
||||
$count = $auth_rule_model->where([
|
||||
['id', '<>', $data['id']],
|
||||
['rule_val', '=', $data['rule_val']],
|
||||
['type', '=', 1]
|
||||
])->count();
|
||||
if ($count > 0) {
|
||||
sendErrorMessage('1','该权限组已经存在,修改失败!');
|
||||
}
|
||||
} else {
|
||||
$count = $auth_rule_model->where([
|
||||
['rule_val' ,'=',$data['rule_val']],
|
||||
['type','=', 1],
|
||||
])->count();
|
||||
if ($count > 0) {
|
||||
sendErrorMessage('1','该权限组已经存在,添加失败!');
|
||||
}
|
||||
}
|
||||
$res = $auth_rule_model->dataUpdate($data);
|
||||
if (!$res) {
|
||||
sendErrorMessage();
|
||||
}
|
||||
$this->createMenu();
|
||||
return sendSuccessMessage();
|
||||
} else {
|
||||
$id = input('param.id', 0);
|
||||
$data = $auth_rule_model->getOneData(['id' => $id]);
|
||||
View::assign('data', $data);
|
||||
return View::fetch('authgroupadd');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 权限组修改
|
||||
* @return string
|
||||
*/
|
||||
public function authGroupUpdate()
|
||||
{
|
||||
return $this->authGroupAdd();
|
||||
}
|
||||
|
||||
public function authGroupDelete()
|
||||
{
|
||||
$id = input('param.id', 0);
|
||||
//查询该权限授权次数
|
||||
|
||||
$auth_group_rule_model = new AuthGroupRule();
|
||||
$count = $auth_group_rule_model->where(['rule_id' => $id])->count('role_id');
|
||||
if ($count > 0) {
|
||||
return sendErrorMessage(1,'该权限组已被授权给角色,无法删除!');
|
||||
}
|
||||
|
||||
$auth_rule_mode = new AuthRule();
|
||||
//取该权限组的所有的权限
|
||||
$group_name = $auth_rule_mode->where(['id' => $id, 'uid' => UID])->value('group_name');
|
||||
$idList = $auth_rule_mode->where(['group_name' => $group_name, 'uid' => UID])->column('id');
|
||||
$res = $auth_rule_mode->destroy($idList);
|
||||
if ($res === false) {
|
||||
return sendErrorMessage();
|
||||
}
|
||||
|
||||
$this->createMenu();
|
||||
|
||||
return sendSuccessMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限添加
|
||||
* @return string
|
||||
*/
|
||||
public function authAdd()
|
||||
{
|
||||
$auth_rule_model = new AuthRule();
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
$data['uid'] = UID;
|
||||
//权限值进行小写操作
|
||||
$data['rule_val'] = strtolower($data['rule_val']);
|
||||
//获取所有的一级分类id
|
||||
$idData = $auth_rule_model->where(['pid' => $data['group_id']])->column('id');
|
||||
$group_module = $auth_rule_model->where(['id'=>$data['group_id']])->value('module');
|
||||
array_push($idData, $data['group_id']);
|
||||
//判断是否存在
|
||||
if ($data['id'] != "") {
|
||||
$count = $auth_rule_model->getNumber([['id', '<>', $data['id']], ['rule_val', '=', $data['rule_val']], ['pid', 'in', $idData], ['uid', '=', UID]]);
|
||||
if ($count > 0) {
|
||||
return sendErrorMessage(1,'该权限已经存在,修改失败!');
|
||||
}
|
||||
} else {
|
||||
$count = $auth_rule_model->getNumber([['rule_val', '=', $data['rule_val']], ['pid', 'in', $idData], ['uid', '=', UID]]);
|
||||
if ($count > 0) {
|
||||
return sendErrorMessage(1,'该权限已经存在,添加失败!');
|
||||
}
|
||||
}
|
||||
$data['module'] = $group_module;
|
||||
$data['rule_url'] = strtolower($group_module."/" . $data['group_val'] . "/" . $data['rule_val']);
|
||||
$data['group_name'] = $data['group_val'];
|
||||
if ($data['type'] == 2) {
|
||||
$data['pid'] = $data['group_id'];
|
||||
}
|
||||
$res = $auth_rule_model->dataUpdate($data);
|
||||
if (!$res) {
|
||||
return sendErrorMessage();
|
||||
}
|
||||
|
||||
$this->createMenu();
|
||||
|
||||
return sendSuccessMessage();
|
||||
} else {
|
||||
$id = input('param.id', 0);
|
||||
$groupid = input('param.groupid', 0);
|
||||
//获取组信息
|
||||
$group = $auth_rule_model->getOneData(['id' => $groupid]);
|
||||
View::assign('group', $group);
|
||||
//获取权限信息
|
||||
$data = $auth_rule_model->getOneData(['id' => $id]);
|
||||
View::assign('data', $data);
|
||||
//获取该权限组下已经权限列表
|
||||
$pidlist = $auth_rule_model->getAllData(['pid' => $groupid], 'id,title,rule_val');
|
||||
View::assign('pidlist', $pidlist);
|
||||
return View::fetch('authadd');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限修改
|
||||
* @return string
|
||||
*/
|
||||
public function authUpdate()
|
||||
{
|
||||
return $this->AuthAdd();
|
||||
}
|
||||
/*
|
||||
* 权限删除
|
||||
*/
|
||||
|
||||
public function authDelete()
|
||||
{
|
||||
$id = input('param.id', 0);
|
||||
//查询该权限授权次数
|
||||
$auth_group_rule_model = new AuthGroupRule();
|
||||
$count = $auth_group_rule_model->where(['rule_id' => $id])->count('role_id');
|
||||
if ($count > 0) {
|
||||
return sendErrorMessage(1,'该权限已被授权给角色,无法删除!');
|
||||
}
|
||||
$auth_rule_mode = new AuthRule();
|
||||
$type = $auth_rule_mode->where(['id' => $id])->value('type');
|
||||
if ($type == 2) {
|
||||
$idlist = $auth_rule_mode->where(['pid' => $id])->column('id');
|
||||
array_push($idlist, $id);
|
||||
$res = $auth_rule_mode->destroy($idlist);
|
||||
} else {
|
||||
$res = $auth_rule_mode->destroy($id);
|
||||
}
|
||||
|
||||
if ($res === false) {
|
||||
return sendErrorMessage();
|
||||
}
|
||||
|
||||
$this->createMenu();
|
||||
|
||||
return sendSuccessMessage();
|
||||
}
|
||||
|
||||
//批量添加权限
|
||||
public function authBatchAdd()
|
||||
{
|
||||
$auth_rule_model = new AuthRule();
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
$auth = $data['rule'];
|
||||
$one_auth_val = [];
|
||||
foreach ($auth as $value) {
|
||||
$one_auth_val[] = $value['rule_val'];
|
||||
//判断是否库中已存在
|
||||
$count = $auth_rule_model->getNumber(['type' => 2, 'pid' => $data['group_id'], 'rule_val' => $value['rule_val']]);
|
||||
if ($count > 0) {
|
||||
return sendErrorMessage(1,'一级权限:' . $value['title'] . "已添加过,不可重复添加!");
|
||||
}
|
||||
$two_auth_val = [];
|
||||
if (!empty($value['twolevel'])) {
|
||||
foreach ($value['twolevel'] as $val) {
|
||||
$two_auth_val[] = $val['rule_val'];
|
||||
}
|
||||
}
|
||||
//判断是否有重复值 (每个一级权限下的二级权限)
|
||||
$unique_arr = array_unique($two_auth_val);
|
||||
if (count($two_auth_val) != count($unique_arr)) {
|
||||
// 获取重复数据的数组
|
||||
// $repeat_arr = array_diff_assoc($two_auth_val, $unique_arr);
|
||||
// $arr= implode(',', $repeat_arr);
|
||||
return sendErrorMessage(1,'一级权限:' . $value['title'] . "下的二级权限值有重复,不可添加!");
|
||||
}
|
||||
}
|
||||
//判断一级权限是否有重复
|
||||
$unique_one = array_unique($one_auth_val);
|
||||
if (count($one_auth_val) != count($unique_one)) {
|
||||
// 获取重复数据的数组
|
||||
$repeat_arr = array_diff_assoc($one_auth_val, $unique_one);
|
||||
$arr = implode(',', $repeat_arr);
|
||||
return sendErrorMessage(1,'一级权限' . $arr . "重复,不可添加!");
|
||||
}
|
||||
$group_module = $auth_rule_model->getOneData(['id'=>$data['group_id']],'module');
|
||||
//拼接数组,事务提交信息
|
||||
$auth_rule_model->startTrans();
|
||||
foreach ($auth as $value) {
|
||||
$temp = [
|
||||
'uid' => UID,
|
||||
'type' => 2,
|
||||
'module' => $group_module,
|
||||
'title' => $value['title'],
|
||||
'rule_val' => $value['rule_val'],
|
||||
'sort' => $value['sort'],
|
||||
'is_total_visible' => $value['is_total_visible'],
|
||||
'is_sub_visible' => $value['is_sub_visible'],
|
||||
'pid' => $data['group_id'],
|
||||
'group_name' => $data['group_val'],
|
||||
'rule_url' => strtolower($group_module."/" . $data['group_val'] . "/" . $value['rule_val'])
|
||||
];
|
||||
$res = $auth_rule_model->dataUpdate($temp);
|
||||
if ($res == false) {
|
||||
$auth_rule_model->rollback();
|
||||
return sendErrorMessage(1,'权限(一级)添加失败');
|
||||
}
|
||||
if (!empty($value['twolevel'])) {
|
||||
foreach ($value['twolevel'] as $val) {
|
||||
$tep = [
|
||||
'uid' => UID,
|
||||
'type' => 3,
|
||||
'module' => $group_module,
|
||||
'title' => $val['title'],
|
||||
'rule_val' => $val['rule_val'],
|
||||
'sort' => $val['sort'],
|
||||
'pid' => $res,
|
||||
'group_name' => $data['group_val'],
|
||||
'rule_url' => strtolower($group_module."/" . $data['group_val'] . "/" . $val['rule_val'])
|
||||
];
|
||||
$res1 = $auth_rule_model->dataUpdate($tep);
|
||||
if ($res1 == false) {
|
||||
$auth_rule_model->rollback();
|
||||
return sendErrorMessage(1,'权限(二级)添加失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$auth_rule_model->commit();
|
||||
|
||||
$this->createMenu();
|
||||
|
||||
|
||||
return sendSuccessMessage();
|
||||
} else {
|
||||
$id = input('param.id', 0);
|
||||
$groupid = input('param.groupid', 0);
|
||||
//获取组信息
|
||||
$group = $auth_rule_model->getOneData(['id' => $groupid]);
|
||||
View::assign('group', $group);
|
||||
return View::fetch('authbatchadd');
|
||||
}
|
||||
}
|
||||
|
||||
//批量修改权限
|
||||
public function authBatchUpdate()
|
||||
{
|
||||
$auth_rule_model = new AuthRule();
|
||||
$auth_group_rule_model = new AuthGroupRule();
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
$auth = $data['rule'];
|
||||
$one_auth_val = [];
|
||||
$auth_all_id = [];
|
||||
foreach ($auth as $value) {
|
||||
$one_auth_val[] = $value['rule_val'];
|
||||
if ($value['id'] > 0) {
|
||||
$auth_all_id[] = $value['id'];
|
||||
}
|
||||
$two_auth_val = [];
|
||||
if (!empty($value['twolevel'])) {
|
||||
foreach ($value['twolevel'] as $val) {
|
||||
if ($val['id'] > 0) {
|
||||
$auth_all_id[] = $val['id'];
|
||||
}
|
||||
$two_auth_val[] = $val['rule_val'];
|
||||
}
|
||||
}
|
||||
//判断是否有重复值 (每个一级权限下的二级权限)
|
||||
$unique_arr = array_unique($two_auth_val);
|
||||
if (count($two_auth_val) != count($unique_arr)) {
|
||||
// 获取重复数据的数组
|
||||
// $repeat_arr = array_diff_assoc($two_auth_val, $unique_arr);
|
||||
// $arr= implode(',', $repeat_arr);
|
||||
return sendErrorMessage(1,'一级权限:' . $value['title'] . "下的二级权限值有重复,不可添加!");
|
||||
}
|
||||
}
|
||||
//判断一级权限是否有重复
|
||||
$unique_one = array_unique($one_auth_val);
|
||||
if (count($one_auth_val) != count($unique_one)) {
|
||||
// 获取重复数据的数组
|
||||
$repeat_arr = array_diff_assoc($one_auth_val, $unique_one);
|
||||
$arr = implode(',', $repeat_arr);
|
||||
return sendErrorMessage(1,'一级权限' . $arr . "重复,不可添加!");
|
||||
}
|
||||
// var_dump($auth_all_id);
|
||||
//获取删除数组
|
||||
$delete_id_all = $auth_rule_model->where([['id', 'NOT IN', $auth_all_id], ['type', 'IN', [2, 3]], ['group_name', '=', $data['group_val']]])->column('id');
|
||||
// var_dump($delete_id_all);
|
||||
// exit();
|
||||
//查询该权限授权次数
|
||||
if (!empty($delete_id_all)) {
|
||||
$set_count = $auth_group_rule_model->getCountByRuleMany($delete_id_all);
|
||||
if ($set_count > 0) {
|
||||
return sendErrorMessage(1,"删除权限已被授权给角色,无法删除!");
|
||||
}
|
||||
}
|
||||
//拼接数组,事务提交信息
|
||||
$auth_rule_model->startTrans();
|
||||
//删除权限
|
||||
if (!empty($delete_id_all)) {
|
||||
$delete_re = $auth_rule_model->destroy($delete_id_all);
|
||||
if ($delete_re == false) {
|
||||
$auth_rule_model->rollback();
|
||||
return sendErrorMessage(1,'权限修改失败!');
|
||||
}
|
||||
}
|
||||
$group_module = $auth_rule_model->getOneData(['id'=>$data['group_id']],'module');
|
||||
|
||||
foreach ($auth as $value) {
|
||||
if ($value['id'] > 0) {
|
||||
$temp = [
|
||||
'id' => $value['id'],
|
||||
'uid' => UID,
|
||||
'type' => 2,
|
||||
'module' => $group_module,
|
||||
'title' => $value['title'],
|
||||
'rule_val' => $value['rule_val'],
|
||||
'sort' => $value['sort'],
|
||||
'is_total_visible' => $value['is_total_visible'],
|
||||
'is_sub_visible' => $value['is_sub_visible'],
|
||||
'pid' => $data['group_id'],
|
||||
'group_name' => $data['group_val'],
|
||||
'rule_url' => strtolower($group_module."/" . $data['group_val'] . "/" . $value['rule_val']),
|
||||
'update_time' => time()
|
||||
];
|
||||
$res = $auth_rule_model->dataUpdate($temp);
|
||||
if ($res == false) {
|
||||
$auth_rule_model->rollback();
|
||||
return sendErrorMessage(1,'权限(一级)修改失败');
|
||||
}
|
||||
if (!empty($value['twolevel'])) {
|
||||
foreach ($value['twolevel'] as $val) {
|
||||
if ($val['id'] > 0) {
|
||||
$tep = [
|
||||
'id' => $val['id'],
|
||||
'uid' => UID,
|
||||
'type' => 3,
|
||||
'module' => $group_module,
|
||||
'title' => $val['title'],
|
||||
'rule_val' => $val['rule_val'],
|
||||
'sort' => $val['sort'],
|
||||
'pid' => $res,
|
||||
'group_name' => $data['group_val'],
|
||||
'rule_url' => strtolower($group_module."/" . $data['group_val'] . "/" . $val['rule_val']),
|
||||
'update_time' => time()
|
||||
];
|
||||
$res1 = $auth_rule_model->dataUpdate($tep);
|
||||
if ($res1 == false) {
|
||||
$auth_rule_model->rollback();
|
||||
return sendErrorMessage(1,'权限(二级)修改失败');
|
||||
}
|
||||
} else {
|
||||
$tep = [
|
||||
'uid' => UID,
|
||||
'type' => 3,
|
||||
'module' => $group_module,
|
||||
'title' => $val['title'],
|
||||
'rule_val' => $val['rule_val'],
|
||||
'sort' => $val['sort'],
|
||||
'pid' => $res,
|
||||
'group_name' => $data['group_val'],
|
||||
'rule_url' => strtolower($group_module."/" . $data['group_val'] . "/" . $val['rule_val'])
|
||||
];
|
||||
$res1 = $auth_rule_model->dataUpdate($tep);
|
||||
if ($res1 == false) {
|
||||
$auth_rule_model->rollback();
|
||||
return sendErrorMessage(1,'权限(二级)添加失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$temp = [
|
||||
'uid' => UID,
|
||||
'type' => 2,
|
||||
'module' => $group_module,
|
||||
'title' => $value['title'],
|
||||
'rule_val' => $value['rule_val'],
|
||||
'sort' => $value['sort'],
|
||||
'is_total_visible' => $value['is_total_visible'],
|
||||
'is_sub_visible' => $value['is_sub_visible'],
|
||||
'pid' => $data['group_id'],
|
||||
'group_name' => $data['group_val'],
|
||||
'rule_url' => strtolower($group_module."/" . $data['group_val'] . "/" . $value['rule_val'])
|
||||
];
|
||||
$res = $auth_rule_model->dataUpdate($temp);
|
||||
if ($res == false) {
|
||||
$auth_rule_model->rollback();
|
||||
return sendErrorMessage(1,'权限(一级)添加失败');
|
||||
}
|
||||
if (!empty($value['twolevel'])) {
|
||||
foreach ($value['twolevel'] as $val) {
|
||||
$tep = [
|
||||
'uid' => UID,
|
||||
'type' => 3,
|
||||
'module' => $group_module,
|
||||
'title' => $val['title'],
|
||||
'rule_val' => $val['rule_val'],
|
||||
'sort' => $val['sort'],
|
||||
'pid' => $res,
|
||||
'group_name' => $data['group_val'],
|
||||
'rule_url' => strtolower($group_module."/" . $data['group_val'] . "/" . $val['rule_val'])
|
||||
];
|
||||
$res1 = $auth_rule_model->dataUpdate($tep);
|
||||
if ($res1 == false) {
|
||||
$auth_rule_model->rollback();
|
||||
return sendErrorMessage(1,'权限(二级)添加失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$auth_rule_model->commit();
|
||||
|
||||
|
||||
$this->createMenu();
|
||||
|
||||
|
||||
return sendSuccessMessage();
|
||||
} else {
|
||||
$id = input('param.id', 0);
|
||||
$groupid = input('param.groupid', 0);
|
||||
//获取组信息
|
||||
$group = $auth_rule_model->getOneData(['id' => $groupid]);
|
||||
View::assign('group', $group);
|
||||
//获取改组所有的权限信息
|
||||
$one_level = $auth_rule_model->getAllData(['pid' => $groupid, 'type' => 2], "id,title,rule_val,sort,is_total_visible,is_sub_visible", "sort desc");
|
||||
if (!empty($one_level)) {
|
||||
foreach ($one_level as $key => $value) {
|
||||
$two_level = $auth_rule_model->getAllData(['type' => 3, 'pid' => $value['id']], "id,title,rule_val,sort,is_total_visible,is_sub_visible", "sort desc");
|
||||
if (!empty($two_level)) {
|
||||
$value['twolevel'] = $two_level->toArray();
|
||||
} else {
|
||||
$value['twolevel'] = [];
|
||||
}
|
||||
$one_level[$key] = $value;
|
||||
}
|
||||
}
|
||||
View::assign('auth', $one_level);
|
||||
return View::fetch('authbatchupdate');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限参数
|
||||
* @return string
|
||||
*/
|
||||
public function authParam()
|
||||
{
|
||||
$id = input('param.id', 0);
|
||||
$auth_rule_param_model = new AuthRuleParam();
|
||||
$dataList = $auth_rule_param_model->getAllData(['rule_id' => $id], '', 'sort desc, id asc');
|
||||
View::assign('dataList', $dataList);
|
||||
//获取权限相关信息
|
||||
$auth_rule_model = new AuthRule();
|
||||
$rule = $auth_rule_model->getOneData(['id' => $id]);
|
||||
View::assign('rule', $rule);
|
||||
return View::fetch('authparam');
|
||||
}
|
||||
|
||||
/*
|
||||
* 权限参数添加
|
||||
*/
|
||||
|
||||
public function authParamAdd()
|
||||
{
|
||||
$auth_rule_param_model = new AuthRuleParam();
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
$data['uid'] = UID;
|
||||
//权限值进行小写操作
|
||||
$data['param_val'] = strtolower($data['param_val']);
|
||||
//判断是否存在
|
||||
if ($data['id'] != "") {
|
||||
$count = $auth_rule_param_model->getNumber([['id', '<>', $data['id']], ['param_val', '=', $data['param_val']], ['rule_id', '=', $data['rule_id']], ['uid', '=', UID]]);
|
||||
if ($count > 0) {
|
||||
return sendErrorMessage(1,'该参数已经存在,修改失败!');
|
||||
}
|
||||
} else {
|
||||
$count = $auth_rule_param_model->getNumber(['param_val' => $data['param_val'], 'rule_id' => $data['rule_id'], 'uid' => UID]);
|
||||
if ($count > 0) {
|
||||
return sendErrorMessage(1,'该参数已经存在,添加失败!');
|
||||
}
|
||||
}
|
||||
$res = $auth_rule_param_model->dataUpdate($data);
|
||||
if (!$res) {
|
||||
return sendErrorMessage();
|
||||
}
|
||||
|
||||
$this->createMenu();
|
||||
|
||||
|
||||
return sendSuccessMessage();
|
||||
} else {
|
||||
$id = input('param.id', 0);
|
||||
$rule_id = input('param.rule_id');
|
||||
//获取权限信息
|
||||
$auth_rule_model = new AuthRule();
|
||||
$rule = $auth_rule_model->getOneData(['id' => $rule_id]);
|
||||
View::assign('rule_id', $rule_id);
|
||||
View::assign('rule', $rule);
|
||||
//获取参数信息
|
||||
$data = $auth_rule_param_model->getOneData(['id' => $id]);
|
||||
View::assign('data', $data);
|
||||
return View::fetch('authparamadd');
|
||||
}
|
||||
}
|
||||
|
||||
public function authParamDelete()
|
||||
{
|
||||
$id = input('param.id', 0);
|
||||
$auth_rule_param_model = new AuthRuleParam();
|
||||
$res = $auth_rule_param_model->destroy( $id);
|
||||
$this->createMenu();
|
||||
if ($res === false) {
|
||||
return sendErrorMessage();
|
||||
}
|
||||
return sendSuccessMessage();
|
||||
}
|
||||
|
||||
/*
|
||||
* 权限参数修改
|
||||
*/
|
||||
|
||||
public function authParamUpdate()
|
||||
{
|
||||
return $this->authParamAdd();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改排序
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function updateFieldModel()
|
||||
{
|
||||
$data = input('post.');
|
||||
if($data['childrenModel'])
|
||||
{
|
||||
$model = invoke('app\\'.$data['model'].'\\model\\' .$data['childrenModel'].'\\'. parse_name($data['table'], 1));
|
||||
}else{
|
||||
$model = invoke('app\\'.$data['model'].'\\model\\' . parse_name($data['table'], 1));
|
||||
}
|
||||
if (array_key_exists('operate_value', $data) && $data['operate_value'] == 'sort') {
|
||||
$data['id'] = json_decode($data['id'], true);
|
||||
$res = $model->saveAll($data['id']);
|
||||
} else {
|
||||
$update_data = [$data['field'] => $data['value']];
|
||||
if ($data['field'] == "delete_time") {
|
||||
$data['value'] = time();
|
||||
}
|
||||
if($data['field'] == 'is_publish'){
|
||||
if($data['value'] == 0)
|
||||
{
|
||||
$update_data['publish_time'] = 0;
|
||||
}else{
|
||||
$update_data['publish_time'] = time();
|
||||
}
|
||||
}
|
||||
if($data['field'] == 'is_recommend'){
|
||||
if($data['value'] == 0)
|
||||
{
|
||||
$update_data['recommend_time'] = 0;
|
||||
}else{
|
||||
$update_data['recommend_time'] = time();
|
||||
}
|
||||
}
|
||||
$res = $model->where(['id'=>$data['id']])->update($update_data);
|
||||
}
|
||||
if ($res === false) {
|
||||
return sendErrorMessage();
|
||||
}
|
||||
$this->createMenu();
|
||||
|
||||
return sendSuccessMessage();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->createMenu();
|
||||
}
|
||||
/**
|
||||
* 调用生成菜单方法
|
||||
* @auth Alan
|
||||
* @time 2019-02-27
|
||||
*/
|
||||
public function createMenu()
|
||||
{
|
||||
$authLogic = new \app\auth\logic\Auth();
|
||||
$authLogic->createMenu();
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\auth\controller\admin;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\auth\controller\admin;
|
||||
|
||||
use rongyun\User;
|
||||
use think\facade\View;
|
||||
|
||||
class Config extends Base
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
$object = new User();
|
||||
$res = $object->updateUser('211111','221111','http://juchenghb1.oss-cn-qingdao.aliyuncs.com/tp/uid2/member/20210508/f6dbd5b9eeac71cb09d9a87421e3b05c_0.png');
|
||||
dump($res);
|
||||
}
|
||||
}
|
@ -0,0 +1,257 @@
|
||||
<?php
|
||||
|
||||
namespace app\auth\logic;
|
||||
|
||||
|
||||
|
||||
use app\auth\model\AuthGroupRule;
|
||||
use app\auth\model\AuthRule;
|
||||
use app\auth\model\AuthRuleParam;
|
||||
|
||||
class Auth extends Base
|
||||
{
|
||||
public function getMenu($controller_name,$action_name)
|
||||
{
|
||||
$json_string = file_get_contents('menu.json');
|
||||
$menu = json_decode($json_string, true);
|
||||
$login_er = serializeMysql(session('login_er'),1);
|
||||
if(!$login_er){
|
||||
return $login_er;
|
||||
}
|
||||
$index = strpos($action_name, 'indie'); //权限控制
|
||||
if($login_er['rank'] > 0 || $index){
|
||||
$auth_rule_model = new AuthRule();
|
||||
//获取角色授权id列表
|
||||
$auth_group_rule_model = new AuthGroupRule();
|
||||
$rule_data = $auth_group_rule_model->where(['role_id' => $login_er['role_id']])->column('rule_id');
|
||||
|
||||
$group = $auth_rule_model->field('rule_val,group_name')->where([['id','in',$rule_data], ['type','<>',1]])->select();
|
||||
|
||||
$controller_group = [];
|
||||
$auth_group = [];
|
||||
|
||||
foreach ($group as $key => $value) {
|
||||
$auth_group[] = $value['group_name'];
|
||||
$controller_group[$value['group_name']][] = $value['rule_val'];
|
||||
}
|
||||
$auth_group = array_unique($auth_group);
|
||||
foreach ($menu as $key => &$value) {
|
||||
if (!in_array($value['group'], $auth_group)) {
|
||||
unset($menu[$key]);
|
||||
} else {
|
||||
if (empty($value['_child'])) { //只有一级
|
||||
if (!in_array($value['url'], $controller_group[$value['group']])) {
|
||||
unset($menu[$key]);
|
||||
}
|
||||
foreach ($value['_auth'] as $k3 => $v3) {
|
||||
if (!in_array($v3['url'], $controller_group[$value['group']])) {
|
||||
unset($menu[$key]['_auth'][$k3]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($value['_child'] as $key1 => &$val) {
|
||||
if (!in_array($val['url'], $controller_group[$value['group']])) {
|
||||
unset($menu[$key]['_child'][$key1]);
|
||||
}
|
||||
foreach ($val['_auth'] as $k1 => $v1) {
|
||||
if (!in_array($v1['url'], $controller_group[$value['group']])) {
|
||||
unset($menu[$key]['_child'][$key1]['_auth'][$k1]);
|
||||
unset($menu[$key]['_child'][$key1]['_auth'][$k1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//如果是总账号要把不让总账号可见的权限剔除
|
||||
if($login_er['rank'] === 0){
|
||||
|
||||
foreach ($menu as $key => &$value) {
|
||||
if ($value['is_total_visible'] == 0) {
|
||||
unset($menu[$key]);
|
||||
} else {
|
||||
if (!empty($value['_child'])) { //只有一级
|
||||
foreach ($value['_child'] as $key1 => &$val) {
|
||||
if ($val['is_total_visible'] == 0) {
|
||||
unset($menu[$key]['_child'][$key1]);
|
||||
}
|
||||
// foreach ($val['_auth'] as $k1 => $v1) {
|
||||
// if (!in_array($v1['url'], $controller_group[$value['group']])) {
|
||||
// unset($menu[$key]['_child'][$key1]['_auth'][$k1]);
|
||||
// unset($menu[$key]['_child'][$key1]['_auth'][$k1]);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$group_name = '';
|
||||
$auth_name = [];
|
||||
$three_level = [];
|
||||
|
||||
foreach ($menu as $key1 => &$menu1) {
|
||||
if (empty($menu1['_child'])) { //一级为最后一级
|
||||
$param_base = empty($menu1['param']) ? [] : $menu1['param'];
|
||||
$param_r = [];
|
||||
if (!empty($menu1['_param'])) {
|
||||
$param_r = ['r' => $menu1['_param'][0]['r']];
|
||||
}
|
||||
if (!array_key_exists('url', $menu1)) {
|
||||
continue;
|
||||
}
|
||||
$menu1['linkurl'] = getMenuLinkurl($menu1['module'],$menu1['group'], $menu1['url'], array_merge($param_base, $param_r));
|
||||
if ($controller_name == $menu1['group']) {
|
||||
$menu1['cur'] = 1; //一级高亮
|
||||
$group_name = $menu1['url']; //当前组和权限组
|
||||
$urls = array_column($menu1['_auth'], 'url');
|
||||
$auth_name = array_merge([$menu1['url']], $urls);
|
||||
if (!empty($menu1['_param'])) {
|
||||
$three_level = $menu1['_param'];
|
||||
$r = input('param.r');
|
||||
foreach ($three_level as $k => $v) {
|
||||
$three_level[$k]['linkurl'] = getMenuLinkurl($menu1['module'],$menu1['group'], $menu1['url'], array_merge($param_base, ['r' => $v['r']]));
|
||||
if ($r == $v['r']) {
|
||||
$three_level[$k]['cur'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($menu1['_child'] as $key2 => &$menu2) {
|
||||
//二级是最后一级
|
||||
$param_base = empty($menu2['param']) ? [] : $menu2['param'];
|
||||
$param_r = [];
|
||||
if (!empty($menu2['_param'])) {
|
||||
$param_r = ['r' => $menu2['_param'][0]['r']];
|
||||
}
|
||||
if (!array_key_exists('url', $menu2)) {
|
||||
continue;
|
||||
}
|
||||
$menu2['linkurl'] = getMenuLinkurl($menu1['module'],$menu1['group'], $menu2['url'], array_merge($param_base, $param_r));
|
||||
$urls = array_column($menu2['_auth'], 'url');
|
||||
$arr = array_merge([$menu2['url']], $urls);
|
||||
if ($controller_name == $menu1['group'] && in_array($action_name, $arr)) {
|
||||
$menu1['cur'] = 1; //一级高亮
|
||||
$menu2['cur'] = 1; //二级高亮
|
||||
|
||||
$group_name = $menu2['url']; //当前组和权限组
|
||||
$auth_name = $arr;
|
||||
|
||||
if (!empty($menu2['_param'])) {
|
||||
$three_level = $menu2['_param'];
|
||||
$r = input('param.r');
|
||||
foreach ($three_level as $k => $v) {
|
||||
$three_level[$k]['linkurl'] = getMenuLinkurl($menu1['module'],$menu1['group'], $menu2['url'], array_merge($param_base, ['r' => $v['r']]));
|
||||
if ($r == $v['r']) {
|
||||
$three_level[$k]['cur'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// dump($menu);
|
||||
// exit();
|
||||
return ['menu'=>$menu,'group_name'=>$group_name,'auth_name'=>$auth_name,'three_level'=>$three_level];
|
||||
}
|
||||
|
||||
/*
|
||||
* 生成menu.json文件
|
||||
*/
|
||||
public function createMenu()
|
||||
{
|
||||
//获取一级权限
|
||||
$auth_rule_model = new AuthRule();
|
||||
$auth_rule_param_model = new AuthRuleParam();
|
||||
$data = $auth_rule_model->where(array('pid' => 0, 'uid' => UID))->order('sort desc,id asc')->select();
|
||||
$redata = array();
|
||||
if (!empty($data)) {
|
||||
$idData = array();
|
||||
foreach ($data as $value) {
|
||||
$idData[] = $value['id'];
|
||||
}
|
||||
//dump($idData);
|
||||
//获取二级权限
|
||||
$where = [];
|
||||
$where[] = ['pid', 'in', $idData];
|
||||
$where[] = ['type', '=', 2];
|
||||
$where[] = ['uid', '=', UID];
|
||||
$list = $auth_rule_model
|
||||
->where(
|
||||
$where
|
||||
)
|
||||
->order('sort desc,id asc')
|
||||
// ->fetchSql(true)
|
||||
->select();
|
||||
//dump($list);
|
||||
$idData1 = array();
|
||||
foreach ($list as $value) {
|
||||
$idData1[] = $value['id'];
|
||||
}
|
||||
//获取三级权限
|
||||
$list_next = $auth_rule_model->where(
|
||||
array(['pid', "IN", $idData1], ['type', '=', 3], ['uid', '=', UID])
|
||||
)->order('sort desc,id asc')->select();
|
||||
|
||||
//获取参数
|
||||
$authParam = $auth_rule_param_model->getListByRule();
|
||||
$two_level_list = [];
|
||||
//拼装二级权限数组
|
||||
foreach ($list as $value) {
|
||||
$temp = array();
|
||||
$temp['id'] = $value['id'];
|
||||
$temp['pid'] = $value['pid'];
|
||||
$temp['name'] = $value['title'];
|
||||
$temp['url'] = $value['rule_val'];
|
||||
$temp['is_total_visible'] = $value['is_total_visible'];
|
||||
$temp['_auth'] = [];
|
||||
foreach ($list_next as $val) {
|
||||
if ($val['pid'] == $value['id']) {
|
||||
$tem = [
|
||||
'name' => $val['title'],
|
||||
'url' => $val['rule_val']
|
||||
];
|
||||
$temp['_auth'][] = $tem;
|
||||
}
|
||||
}
|
||||
if (isset($authParam[$value['id']])) {
|
||||
$temp['_param'] = $authParam[$value['id']];
|
||||
}
|
||||
$two_level_list[] = $temp;
|
||||
}
|
||||
//拼装权限组数组
|
||||
foreach ($data as $value) {
|
||||
$temp = array();
|
||||
$temp['module'] = $value['module'];
|
||||
$temp['group'] = $value['rule_val'];
|
||||
$temp['icon'] = $value['icon'];
|
||||
$temp['name'] = $value['title'];
|
||||
$temp['is_total_visible'] = $value['is_total_visible'];
|
||||
$temp['_child'] = [];
|
||||
foreach ($two_level_list as $val) {
|
||||
if ($val['pid'] == $value['id']) {
|
||||
unset($val['id']);
|
||||
unset($val['pid']);
|
||||
$temp['_child'][] = $val;
|
||||
}
|
||||
}
|
||||
$redata[] = $temp;
|
||||
}
|
||||
}
|
||||
$json_string = json_encode($redata);
|
||||
$res = file_put_contents('menu.json', $json_string);
|
||||
if ($res == FALSE) {
|
||||
return sendArray([], 101, '生成失败');
|
||||
}
|
||||
return sendArray();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\auth\logic;
|
||||
|
||||
use app\BaseLogic;
|
||||
|
||||
class Base extends BaseLogic
|
||||
{
|
||||
|
||||
protected $mid;
|
||||
protected $userAgent;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @date 2020-07-27
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
|
||||
if (isset($data['uid'])) {
|
||||
$mid = $data['uid'];
|
||||
} else {
|
||||
if (defined('UID')) {
|
||||
$mid = UID;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['user_agent'])) {
|
||||
$this->userAgent = $data['user_agent'];
|
||||
} else {
|
||||
if (defined('USER_AGENT')) {
|
||||
$this->userAgent = USER_AGENT;
|
||||
}
|
||||
}
|
||||
|
||||
$this->mid = isset($mid) ? $mid : 2;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace app\auth\model;
|
||||
|
||||
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
class AuthGroup extends Base
|
||||
{
|
||||
use SoftDelete;
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace app\auth\model;
|
||||
|
||||
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class AuthGroupRule extends Base
|
||||
{
|
||||
/*
|
||||
* 根据角色id获取权限id
|
||||
*/
|
||||
public function getIds($id)
|
||||
{
|
||||
return $this->where(['role_id' => $id])->column('rule_id');
|
||||
}
|
||||
/*
|
||||
* 保存权限数据
|
||||
*/
|
||||
public function saveData($role_id, $data)
|
||||
{
|
||||
if (empty($data)) {
|
||||
$this->where(['role_id' => $role_id])->delete();
|
||||
return true;
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$this->where(['role_id' => $role_id])->delete();
|
||||
$insertData = [];
|
||||
foreach ($data as $val) {
|
||||
$insertData[] = ['role_id' => $role_id, 'rule_id' => $val];
|
||||
}
|
||||
$this->insertAll($insertData);
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* 判断大量的权限是否被授权过
|
||||
*/
|
||||
public function getCountByRuleMany($arr)
|
||||
{
|
||||
return $this->where([['rule_id', 'IN', $arr]])->count('role_id');
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace app\auth\model;
|
||||
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
class AuthRule extends Base
|
||||
{
|
||||
use SoftDelete;
|
||||
|
||||
/*
|
||||
* 获取列表信息
|
||||
*/
|
||||
public function getListAll()
|
||||
{
|
||||
//获取一级权限
|
||||
$data = $this->where(array('pid' => 0))->order('sort desc,id asc')->select();
|
||||
$redata = array();
|
||||
if (!empty($data)) {
|
||||
$idData = array();
|
||||
foreach ($data as $value) {
|
||||
$idData[] = $value['id'];
|
||||
}
|
||||
//获取二级权限
|
||||
$list = $this->where('type', 2)->whereIn('pid', implode(',', $idData))->order('sort desc,id asc')->select();
|
||||
$idData1 = array();
|
||||
foreach ($list as $value) {
|
||||
$idData1[] = $value['id'];
|
||||
}
|
||||
//获取三级权限
|
||||
$list_next = $this->where('type', 3)->whereIn('pid',implode(',', $idData1))->order('sort desc,id asc')->select();
|
||||
foreach ($data as $value) {
|
||||
$temp = array();
|
||||
$temp['id'] = $value['id'];
|
||||
$temp['pid'] = $value['pid'];
|
||||
$temp['title'] = $value['title'];
|
||||
$temp['rule_val'] = $value['rule_val'];
|
||||
$temp['rule_url'] = $value['rule_url'];
|
||||
$temp['icon'] = $value['icon'];
|
||||
$temp['type'] = $value['type'];
|
||||
$temp['sort'] = $value['sort'];
|
||||
$temp['list'] = array();
|
||||
//写入下一级信息
|
||||
foreach ($list as $val) {
|
||||
if ($val['pid'] == $value['id']) {
|
||||
$temp['list'][] = $val;
|
||||
}
|
||||
}
|
||||
//写入下二级信息
|
||||
if (!empty($temp['list'])) {
|
||||
foreach ($temp['list'] as $key => $val) {
|
||||
$val['next'] = array();
|
||||
$next = array();
|
||||
foreach ($list_next as $v) {
|
||||
if ($v['pid'] == $val['id']) {
|
||||
$next[] = $v;
|
||||
}
|
||||
}
|
||||
$val['next'] = $next;
|
||||
$temp['list'][$key] = $val;
|
||||
}
|
||||
}
|
||||
$redata[] = $temp;
|
||||
}
|
||||
}
|
||||
return $redata;
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取等级数据(用于角色授权页面)
|
||||
*/
|
||||
public function getLevelData()
|
||||
{
|
||||
$data = $this->where(['uid' => $this->mid,'is_sub_visible'=>1])->order('pid asc, sort desc,id asc')->select();
|
||||
if (empty($data)) {
|
||||
return $data;
|
||||
}
|
||||
$ret = [];
|
||||
$thridarr = [];
|
||||
foreach ($data as $val) {
|
||||
if ($val['type'] == 3) {
|
||||
$temp = ['id' => $val->id, 'title' => $val->title, 'pid' => $val->pid, 'rule_val' => $val->rule_val];
|
||||
if (!isset($thridarr[$val->pid])) {
|
||||
$thridarr[$val->pid][] = $temp;
|
||||
} else {
|
||||
array_push($thridarr[$val->pid], $temp);
|
||||
}
|
||||
}
|
||||
if ($val->pid == 0) {
|
||||
$ret[$val->id] = ['id' => $val->id, 'title' => $val->title, 'pid' => $val->pid, 'rule_val' => $val->rule_val];
|
||||
} elseif (isset($ret[$val->pid])) {
|
||||
$ret[$val->pid]['children'][$val->id] = ['id' => $val->id, 'title' => $val->title, 'pid' => $val->pid, 'rule_val' => $val->rule_val];
|
||||
}
|
||||
|
||||
}
|
||||
foreach ($ret as $key => $value) {
|
||||
if (!empty($value['children'])) {
|
||||
foreach ($value['children'] as $k => $val) {
|
||||
foreach ($thridarr as $kk => $vv) {
|
||||
if ($k == $kk) {
|
||||
$val['next'] = $vv;
|
||||
}
|
||||
}
|
||||
$value['children'][$k] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
$ret[$key] = $value;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\auth\model;
|
||||
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
class AuthRuleParam extends Base
|
||||
{
|
||||
use SoftDelete;
|
||||
|
||||
/*
|
||||
* 获取所有的参数
|
||||
*/
|
||||
public function getListByRule(){
|
||||
$data = $this->where(array('uid' => $this->mid))->order('sort desc,id asc')->select();
|
||||
|
||||
if (empty($data)) {
|
||||
return $data;
|
||||
}
|
||||
$ret=array();
|
||||
foreach($data as $value){
|
||||
$temp=['r' => $value->param_val, 'name' => $value->param_name];
|
||||
if (!isset($thridarr[$value->rule_id])) {
|
||||
$ret[$value->rule_id][] = $temp;
|
||||
} else {
|
||||
array_push($thridarr[$value->rule_id], $temp);
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace app\auth\model;
|
||||
|
||||
use app\BaseModel;
|
||||
|
||||
class Base extends BaseModel
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @date 2020-07-27
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
use think\facade\Route;
|
||||
|
||||
Route::rule(':controller_name/:function_name', 'admin.:controller_name/:function_name')
|
||||
->middleware(\app\middleware\CheckAdmin::class);
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\app\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
use think\facade\Request;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 配置
|
||||
* @date 2021-02-18
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\app\api;
|
||||
|
||||
use app\base\model\app\AppUser;
|
||||
use think\App;
|
||||
|
||||
class Test extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取access_token
|
||||
* @date 2021-02-18
|
||||
*/
|
||||
public function getTokenByDeviceId()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
|
||||
$user_model = new AppUser();
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
|
||||
//获取用户信息
|
||||
$data = $user_model->getOneData([
|
||||
['device_id','=',$param['device_id']]
|
||||
]);
|
||||
|
||||
// 签发token
|
||||
$arr = [
|
||||
'uid' => UID,
|
||||
'device_id' => $data['device_id'],
|
||||
'app_user_id' => $data['id'],
|
||||
'user_id' => $data['user_id'],
|
||||
];
|
||||
$res_token = $jwt_class->signToken($arr);
|
||||
|
||||
$r_data = $arr;
|
||||
$r_data['access_token'] = $res_token['token'];
|
||||
$r_data['access_token_expire_time'] = $res_token['exp'];
|
||||
|
||||
|
||||
return sendSuccessMessage($r_data);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\app\api;
|
||||
|
||||
use app\base\model\app\AppUser;
|
||||
|
||||
class User extends Base
|
||||
{
|
||||
/**
|
||||
* 获取APP用户基础信息
|
||||
* @date 2021-02-18
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
|
||||
$app_user_model = new AppUser();
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
|
||||
|
||||
//更新APP用户信息
|
||||
$data = [
|
||||
'uid' => UID,
|
||||
'device_id' => $param['device_id'],
|
||||
'brand' => $param['brand'],
|
||||
'model' => $param['model'],
|
||||
'pixel_ratio' => $param['pixel_ratio'],
|
||||
'language' => $param['language'],
|
||||
'version' => $param['version'],
|
||||
'system' => $param['system'],
|
||||
'platform' => $param['platform']
|
||||
];
|
||||
if(!empty($param['client_id'])){
|
||||
$data['client_id'] = $param['client_id'];
|
||||
}
|
||||
$res = $app_user_model->updateUser($data);
|
||||
|
||||
//获取APP用户信息
|
||||
$user = $app_user_model->getOneData([
|
||||
['device_id', '=', $data['device_id']]
|
||||
], 'id,user_id,device_id');
|
||||
|
||||
//签发token
|
||||
$arr = [
|
||||
'uid' => UID,
|
||||
'device_id' => $user['device_id'],
|
||||
'app_user_id' => $user['id'],
|
||||
'user_id' => $user['user_id'],
|
||||
# FIXED 临时用于解决uni-app官方BUG 20220923 deviceID获取相同
|
||||
// 'user_id' => '',
|
||||
];
|
||||
$res_token = $jwt_class->signToken($arr);
|
||||
|
||||
$r_data = $arr;
|
||||
$r_data['access_token'] = $res_token['token'];
|
||||
$r_data['access_token_expire_time'] = $res_token['exp'];
|
||||
|
||||
return sendSuccessMessage($r_data);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,238 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\auth\admin;
|
||||
|
||||
|
||||
use app\base\model\auth\AuthRule;
|
||||
use app\BaseController;
|
||||
use Godruoyi\Snowflake\Snowflake;
|
||||
|
||||
class Menu extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取左侧菜单栏
|
||||
* @param \think\Request $request
|
||||
* @param \Closure $next
|
||||
* @date 2020-09-10
|
||||
*/
|
||||
public function getMenu()
|
||||
{
|
||||
$module = input('param.module'); //每个模块的菜单不一样
|
||||
|
||||
$auth_rule_model = new AuthRule();
|
||||
|
||||
$where = [
|
||||
['uid', '=', UID],
|
||||
['module', '=', $module],
|
||||
['type', 'in', [0, 1, 2, 3]]
|
||||
];
|
||||
$auth_rule_list = $auth_rule_model->getAllData($where, 'id,pid,type,menu_next,title,name,icon,sort,jump', 'sort desc')->toArray();
|
||||
$auth_rule_list = listToTree($auth_rule_list, 'id', 'pid', 'list', 1);
|
||||
|
||||
return sendSuccessMessage($auth_rule_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有模块列表
|
||||
* @param \think\Request $request
|
||||
* @param \Closure $next
|
||||
* @date 2020-09-10
|
||||
*/
|
||||
public function moduleList()
|
||||
{
|
||||
$limit = input('param.limit', 10);
|
||||
$page = input('param.page', 1);
|
||||
|
||||
$auth_rule_model = new AuthRule();
|
||||
|
||||
$where = [
|
||||
['uid', '=', UID],
|
||||
['type', '=', 0]
|
||||
];
|
||||
$auth_rule_list = $auth_rule_model->getDataList($where, $page, '*', 'sort desc', $limit);
|
||||
|
||||
$rdata = [
|
||||
'list' => $auth_rule_list
|
||||
];
|
||||
return sendSuccessMessage($rdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单模块所有权限列表
|
||||
* @param \think\Request $request
|
||||
* @param \Closure $next
|
||||
* @date 2020-09-15
|
||||
*/
|
||||
public function menuAdd()
|
||||
{
|
||||
$menu = $this->menuData();
|
||||
|
||||
$auth_rule_model = new AuthRule();
|
||||
$snow_flake = new Snowflake();
|
||||
|
||||
$pid = 0;
|
||||
|
||||
foreach ($menu as $k => $v) { //模块循环
|
||||
$data[] = [
|
||||
'module' => $v['name'],
|
||||
'title' => $v['title'],
|
||||
'name' => $v['name'],
|
||||
'pid' => $pid,
|
||||
'type' => $v['type'],
|
||||
'menu_next' => in_array($v['type'], [1, 2]) && in_array($v['type'] + 1, array_column($v['_child'], 'type')) ? 1 : 0,
|
||||
'jump'=>'',
|
||||
'icon'=>'',
|
||||
'id' => $pid = $snow_flake->id(),
|
||||
];
|
||||
|
||||
foreach($v['_child'] as $k1=>$v1){ //一级菜单循环
|
||||
$data[] = [
|
||||
'module' => $v['name'],
|
||||
'title' => $v1['title'],
|
||||
'name' => $v1['name'],
|
||||
'pid' => $pid,
|
||||
'type' => $v1['type'],
|
||||
'menu_next' => in_array($v1['type'], [1, 2]) && in_array($v1['type'] + 1, array_column($v1['_child'], 'type')) ? 1 : 0,
|
||||
'jump'=>'',
|
||||
'icon'=>'',
|
||||
'id' => $pid = $snow_flake->id(),
|
||||
];
|
||||
|
||||
foreach($v1['_child'] as $k2=>$v2){ //二级菜单循环
|
||||
$data[] = [
|
||||
'module' => $v['name'],
|
||||
'title' => $v1['title'],
|
||||
'name' => $v1['name'],
|
||||
'pid' => $pid,
|
||||
'type' => $v1['type'],
|
||||
'menu_next' => in_array($v1['type'], [1, 2]) && in_array($v1['type'] + 1, array_column($v1['_child'], 'type')) ? 1 : 0,
|
||||
'jump'=>'',
|
||||
'icon'=>'',
|
||||
'id' => $pid = $snow_flake->id(),
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 单模块所有权限列表(废弃)
|
||||
* @param \think\Request $request
|
||||
* @param \Closure $next
|
||||
* @date 2020-09-15
|
||||
*/
|
||||
public function moduleAuthList()
|
||||
{
|
||||
$module = input('param.module');
|
||||
|
||||
$auth_rule_model = new AuthRule();
|
||||
|
||||
$where = [
|
||||
['uid', '=', UID],
|
||||
['module', '=', $module],
|
||||
['type', 'in', [0, 1, 2, 3, 4]]
|
||||
];
|
||||
$auth_rule_list = $auth_rule_model->getAllData($where, 'id,pid,type,menu_next,title,name,icon,sort,jump', 'sort desc')->toArray();
|
||||
$auth_rule_list = listToTree($auth_rule_list, 'id', 'pid', 'list', 0);
|
||||
|
||||
$rdata = [
|
||||
'auth_rule_list' => $auth_rule_list
|
||||
];
|
||||
return sendSuccessMessage($rdata);
|
||||
}
|
||||
|
||||
|
||||
public function menuData()
|
||||
{
|
||||
$menu = [
|
||||
[
|
||||
'title' => '基础设置',
|
||||
'name' => 'base',
|
||||
'type' => 0,
|
||||
'_child' => [
|
||||
[
|
||||
'title' => '微信平台设置',
|
||||
'name' => 'wechat',
|
||||
'icon' => 'layui-icon-dialogue',
|
||||
'type' => 1,
|
||||
'_child' => [
|
||||
[
|
||||
'title' => '图文素材列表',
|
||||
'name' => 'news',
|
||||
'type' => 2,
|
||||
'_child' => [
|
||||
[
|
||||
'title' => '添加',
|
||||
'name' => 'add',
|
||||
'type' => 4,
|
||||
],
|
||||
[
|
||||
'title' => '修改',
|
||||
'name' => 'edit',
|
||||
'type' => 4,
|
||||
],
|
||||
[
|
||||
'title' => '删除',
|
||||
'name' => 'del',
|
||||
'type' => 4,
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => '关键词列表',
|
||||
'name' => 'keywords',
|
||||
'type' => 2,
|
||||
'_child' => [
|
||||
[
|
||||
'title' => '添加',
|
||||
'name' => 'add',
|
||||
'type' => 4,
|
||||
],
|
||||
[
|
||||
'title' => '修改',
|
||||
'name' => 'edit',
|
||||
'type' => 4,
|
||||
],
|
||||
[
|
||||
'title' => '删除',
|
||||
'name' => 'del',
|
||||
'type' => 4,
|
||||
],
|
||||
]
|
||||
],
|
||||
[
|
||||
'title' => '自定义菜单列表',
|
||||
'name' => 'classify',
|
||||
'type' => 2,
|
||||
'_child' => [
|
||||
[
|
||||
'title' => '修改',
|
||||
'name' => 'edit',
|
||||
'type' => 4,
|
||||
],
|
||||
[
|
||||
'title' => '删除',
|
||||
'name' => 'del',
|
||||
'type' => 4,
|
||||
],
|
||||
[
|
||||
'title' => '发布',
|
||||
'name' => 'publish',
|
||||
'type' => 4,
|
||||
],
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
return $menu;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\car\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\car\api;
|
||||
|
||||
use think\App;
|
||||
|
||||
class CarData extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 车型数据抓取
|
||||
* @date 2022-08-29
|
||||
*/
|
||||
public function getCarData(){
|
||||
$param = input('post.');
|
||||
$car_data_logic = new \app\base\logic\car\CarData();
|
||||
$car_data_logic -> getCarData($param);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\cos\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
protected $ossConfig; //阿里云OSS配置
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
$uid = input('param.uid');
|
||||
defined('UID') || define('UID', $uid);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\demo\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
use think\facade\Request;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 配置
|
||||
* @date 2021-02-18
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\demo\api;
|
||||
|
||||
|
||||
class Callback extends Base
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝预授权回调
|
||||
* @date 2022-04-01
|
||||
*/
|
||||
public function freezeNotify()
|
||||
{
|
||||
$uid = input('param.uid');
|
||||
$data = input('post.');
|
||||
|
||||
|
||||
defined('UID') || define('UID', $uid);
|
||||
$ali_pay_param = get_app_alipay_config();
|
||||
$ali_pay_class = new \ali\alipay\pay\AliPay($ali_pay_param);
|
||||
|
||||
//异步通知验签
|
||||
$result = $ali_pay_class->verifyNotify($data);
|
||||
|
||||
// 记录日志
|
||||
platformLog($data, $result, 'alipaysdk_pay_check_sign_freeze_' . UID);
|
||||
|
||||
//验签失败
|
||||
if (!$result) {
|
||||
exit;
|
||||
}
|
||||
|
||||
//在支付宝的业务通知中,资金预授权明细的状态:INIT--初始 SUCCESS--成功 CLOSED--关闭
|
||||
if ($data['status'] != 'SUCCESS') {
|
||||
exit;
|
||||
}
|
||||
|
||||
$order_number = $data['out_order_no']; //订单编号
|
||||
|
||||
echo "success";// 告诉支付宝,我已经处理完了,别再通知我了
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\demo\api;
|
||||
|
||||
use app\base\model\app\AppUser;
|
||||
use EasyWeChat\Factory;
|
||||
use think\App;
|
||||
use think\facade\Request;
|
||||
|
||||
class Mpalipay extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 预授权
|
||||
* @date 2022-04-01
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
$param = input('post.');
|
||||
$ali_pay_param = get_mp_alipay_config();
|
||||
|
||||
$ali_pay_class = new \ali\alipay\pay\AliPay($ali_pay_param);
|
||||
$notify_url = Request::domain() . '/index.php/base/demo/api/Callback/freezeNotify/uid/' . UID;
|
||||
$order_number = date("Ymd") . createNonceStr(4, ['number']);
|
||||
$result = $ali_pay_class->freeze($param['money'], $order_number, '预授权冻结', $notify_url);
|
||||
|
||||
//记录日志
|
||||
platformLog([
|
||||
'out_order_no' => $order_number,
|
||||
'out_request_no' => $order_number,
|
||||
'order_title' => '预授权冻结',
|
||||
'amount' => round($param['money'], 2),
|
||||
'product_code' => 'PRE_AUTH_ONLINE',
|
||||
], $result, 'alipaysdk_pay_mp_alipay_freeze_' . UID);
|
||||
|
||||
if (!isset($result['body'])) {
|
||||
return sendErrorMessage(4100, '生成预授权订单失败');
|
||||
}
|
||||
|
||||
return sendSuccessMessage(['pay_params' => $result['body']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预授权支付
|
||||
* @date 2022-04-02
|
||||
*/
|
||||
public function freezePay()
|
||||
{
|
||||
$param = input('post.');
|
||||
$ali_pay_param = get_mp_alipay_config();
|
||||
|
||||
$ali_pay_class = new \ali\alipay\pay\AliPay($ali_pay_param);
|
||||
// $notify_url = Request::domain() . '/index.php/base/demo/api/Callback/tradeNotify/uid/' . UID;
|
||||
$order_number = date("Ymd") . createNonceStr(4, ['number']);
|
||||
$result = $ali_pay_class->freezePay($param['money'], $order_number, '预授权冻结后支付', $param['auth_code']);
|
||||
|
||||
//记录日志
|
||||
platformLog([
|
||||
'order_number' => $order_number,
|
||||
'money' => $param['money'],
|
||||
'body' => '预授权冻结',
|
||||
'auth_code' => $param['auth_code']
|
||||
], $result, 'alipaysdk_pay_freeze_pay_' . UID);
|
||||
|
||||
dump($result);
|
||||
if ($result['code'] !== '10000') {
|
||||
return sendErrorMessage($result['code'], $result['sub_msg']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预授权资金解冻
|
||||
* @date 2022-04-02
|
||||
*/
|
||||
public function unfreeze()
|
||||
{
|
||||
$param = input('post.');
|
||||
$ali_pay_param = get_mp_alipay_config();
|
||||
|
||||
$ali_pay_class = new \ali\alipay\pay\AliPay($ali_pay_param);
|
||||
|
||||
$order_number = 'JD' . date("Ymd") . createNonceStr(4, ['number']);
|
||||
$result = $ali_pay_class->unfreeze($param['money'], $order_number, $param['auth_no'], '资金解冻');
|
||||
|
||||
//记录日志
|
||||
platformLog([
|
||||
'order_number' => $order_number,
|
||||
'money' => $param['money'],
|
||||
'remark' => '资金解冻',
|
||||
'auth_code' => $param['auth_no']
|
||||
], $result, 'alipaysdk_pay_unfreeze_' . UID);
|
||||
|
||||
dump($result);
|
||||
if ($result['code'] !== '10000') {
|
||||
return sendErrorMessage($result['code'], $result['sub_msg']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 预授权查询
|
||||
* @date 2022-04-01
|
||||
*/
|
||||
public function orderFind()
|
||||
{
|
||||
$param = input('post.');
|
||||
$ali_pay_param = get_mp_alipay_config();
|
||||
|
||||
$ali_pay_class = new \ali\alipay\pay\AliPay($ali_pay_param);
|
||||
|
||||
$result = $ali_pay_class->freezeQuery($param['order_number']);
|
||||
|
||||
//记录日志
|
||||
platformLog([
|
||||
'out_order_no' => $param['order_number'],
|
||||
'out_request_no' => $param['order_number'],
|
||||
], $result, 'alipaysdk_find_' . UID);
|
||||
|
||||
if ($result['code'] !== '10000') {
|
||||
return sendErrorArray($result['code'], $result['sub_msg']);
|
||||
}
|
||||
|
||||
dump($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预授权支付
|
||||
* @date 2022-04-02
|
||||
*/
|
||||
public function freezePayRefund()
|
||||
{
|
||||
$param = input('post.');
|
||||
$ali_pay_param = get_mp_alipay_config();
|
||||
|
||||
$ali_pay_class = new \ali\alipay\pay\AliPay($ali_pay_param);
|
||||
|
||||
$result = $ali_pay_class->refund($param['order_number'], $param['order_number'] . 'R', 0.01);
|
||||
|
||||
//记录日志
|
||||
platformLog([
|
||||
|
||||
], $result, 'alipaysdk_pay_freeze_pay111_' . UID);
|
||||
|
||||
dump($result);
|
||||
if ($result['code'] !== '10000') {
|
||||
return sendErrorMessage($result['code'], $result['sub_msg']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\demo\api;
|
||||
|
||||
use EasyWeChat\Factory;
|
||||
use think\App;
|
||||
|
||||
class Mpweixin extends Base
|
||||
{
|
||||
|
||||
protected $easyWechatMpWeixinConfig; //easywechat微信小程序配置文件
|
||||
|
||||
/**
|
||||
* 检测文本敏感词
|
||||
* @date 2022-01-05
|
||||
*/
|
||||
public function msgSecCheck()
|
||||
{
|
||||
$content = '你好';
|
||||
|
||||
$app = Factory::miniProgram($this->easyWechatMpWeixinConfig);
|
||||
$result = $app->content_security->checkText($content);
|
||||
if ($result['errcode'] != 0) {
|
||||
return sendErrorMessage($result['errcode'], $result['errmsg']);
|
||||
}
|
||||
|
||||
dump($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\demo\api;
|
||||
|
||||
|
||||
use think\App;
|
||||
|
||||
class Pinyin extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 文字转语音
|
||||
* @date 2022-05-13
|
||||
*/
|
||||
public function textToPinyin()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$pinyin_class = new \pinyin\Pinyin();
|
||||
|
||||
//汉字转成拼音
|
||||
$result = $pinyin_class->textToPinyin($param['text'], PINYIN_TONE);
|
||||
|
||||
//记录日志
|
||||
platformLog([
|
||||
'text' => $param['text'],
|
||||
'options' => PINYIN_TONE
|
||||
], $result, 'pinyin_text_to_pinyin_' . UID);
|
||||
|
||||
|
||||
dump($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 句子转拼音(带标点符号)
|
||||
* @date 2022-05-13
|
||||
*/
|
||||
public function sentenceToPinyin()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$pinyin_class = new \pinyin\Pinyin();
|
||||
|
||||
//句子转拼音(带标点符号)
|
||||
$result = $pinyin_class->sentenceToPinyin($param['text'], PINYIN_TONE, '-');
|
||||
|
||||
//记录日志
|
||||
platformLog([
|
||||
'text' => $param['text'],
|
||||
'options' => PINYIN_TONE,
|
||||
'delimter' => '-'
|
||||
], $result, 'pinyin_entence_to_pinyin_' . UID);
|
||||
|
||||
|
||||
dump($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\demo\api;
|
||||
|
||||
use think\App;
|
||||
|
||||
|
||||
class Push extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 通过cid单推
|
||||
* @date 2022-04-26
|
||||
*/
|
||||
public function singlePushByCid()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$uni_push_param = get_dcloud_uni_push_config();
|
||||
|
||||
$push_class = new \getui\push\Push($uni_push_param);
|
||||
|
||||
//推送消息
|
||||
$request_id = date("YmdHi") . createNonceStr(4, ['number']);
|
||||
// $title = '秒杀提醒';
|
||||
// $content = '您预约的产品即将开枪';
|
||||
$payload = 'spikenotice_1';
|
||||
$result = $push_class->toSinglePushByCid($param['client_id'], $request_id, $param['title'], $param['content'], $uni_push_param['package_name'], $payload);
|
||||
|
||||
// 记录日志
|
||||
platformLog([
|
||||
'client_id' => $param['client_id'],
|
||||
'request_id' => $request_id,
|
||||
'title' => $param['title'],
|
||||
'content' => $param['content'],
|
||||
'package_name' => $uni_push_param['package_name'],
|
||||
'payload' => $payload
|
||||
], $result, 'getui_to_single_by_cid_' . UID);
|
||||
dump($result);
|
||||
|
||||
|
||||
if ($result['code'] != 0) {
|
||||
return sendErrorMessage($result['code'], $result['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行cid批量推
|
||||
* @date 2022-04-26
|
||||
*/
|
||||
public function listPushByCid()
|
||||
{
|
||||
$param = input('post.');
|
||||
$param['client_id'] = explode(',', $param['client_id']);
|
||||
|
||||
$uni_push_param = get_dcloud_uni_push_config();
|
||||
|
||||
$push_class = new \getui\push\Push($uni_push_param);
|
||||
|
||||
$request_id = date("YmdHi") . createNonceStr(4, ['number']);
|
||||
$payload = 'spikenotice_1';
|
||||
//创建消息
|
||||
$result = $push_class->toListCreatePush($request_id, $param['title'], $param['content'], $uni_push_param['package_name'], $payload);
|
||||
|
||||
// 记录日志
|
||||
platformLog([
|
||||
'request_id' => $request_id,
|
||||
'title' => $param['title'],
|
||||
'content' => $param['content'],
|
||||
'package_name' => $uni_push_param['package_name'],
|
||||
'payload' => $payload
|
||||
], $result, 'getui_to_list_create_list_msg_' . UID);
|
||||
dump($result);
|
||||
|
||||
if ($result['code'] != 0) {
|
||||
return sendErrorMessage($result['code'], $result['msg']);
|
||||
}
|
||||
$task_id = $result['data']['taskid'];
|
||||
dump($task_id);
|
||||
|
||||
//批量推送
|
||||
$result = $push_class->toListPushByCid($param['client_id'], $task_id);
|
||||
|
||||
// 记录日志
|
||||
platformLog([
|
||||
'client_id' => $param['client_id'],
|
||||
'task_id' => $task_id
|
||||
], $result, 'getui_to_list_by_cid_' . UID);
|
||||
dump($result);
|
||||
|
||||
|
||||
if ($result['code'] != 0) {
|
||||
return sendErrorMessage($result['code'], $result['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行cid群推
|
||||
* @date 2022-04-27
|
||||
*/
|
||||
public function appPush()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$uni_push_param = get_dcloud_uni_push_config();
|
||||
|
||||
$push_class = new \getui\push\Push($uni_push_param);
|
||||
|
||||
$request_id = date("YmdHi") . createNonceStr(4, ['number']);
|
||||
$payload = 'spikenotice_1';
|
||||
//群推
|
||||
$result = $push_class->toAppPush($request_id, $param['title'], $param['content'], $uni_push_param['package_name'], $payload);
|
||||
|
||||
// 记录日志
|
||||
platformLog([
|
||||
'request_id' => $request_id,
|
||||
'title' => $param['title'],
|
||||
'content' => $param['content'],
|
||||
'package_name' => $uni_push_param['package_name'],
|
||||
'payload' => $payload
|
||||
], $result, 'getui_to_app_' . UID);
|
||||
dump($result);
|
||||
|
||||
if ($result['code'] != 0) {
|
||||
return sendErrorMessage($result['code'], $result['msg']);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\demo\api;
|
||||
|
||||
use think\App;
|
||||
use think\facade\Request;
|
||||
|
||||
class Weixin extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 发送模板消息
|
||||
* @date 2022-03-26
|
||||
*/
|
||||
public function sendTemplate()
|
||||
{
|
||||
$weixin_param = get_weixin_config();
|
||||
$template_class = new \tencent\wechat\weixin\Template($weixin_param);
|
||||
|
||||
|
||||
// 发送模板消息
|
||||
$data = [
|
||||
'touser' => 'okuRis8VoZgHXUfIFQKKWhEQmn4I', //接收者openid
|
||||
'template_id' => 'fdH3SheDR5DyCBqRRa98EyhncTbljXbFgHMdzx_R3us', //模板ID
|
||||
'url' => 'https://www.baidu.com', //模板跳转链接(海外帐号没有跳转能力)
|
||||
'data' => [ //模板数据,可以设定颜色,具体查看文档
|
||||
'first' => '您的订单已取消',
|
||||
'orderProductPrice' => '10.00',
|
||||
'orderProductName' => '商品1',
|
||||
'orderAddress' => '智慧山',
|
||||
'orderName' => date("Ymd") . createNonceStr(4, ['number']),
|
||||
'remark' => '具体查看详情'
|
||||
],
|
||||
];
|
||||
$result = $template_class->sendTemplate($data);
|
||||
dump($result);
|
||||
// 记录日志
|
||||
platformLog($data, $result, 'weixin_send_template_' . UID);
|
||||
|
||||
if($result['errcode'] != 0){
|
||||
return sendErrorMessage($result['errcode'],$result['errmsg']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\district\api;
|
||||
|
||||
use app\BaseController;
|
||||
|
||||
|
||||
class District extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取三级行政区域规划
|
||||
* @date 2021-02-05
|
||||
*/
|
||||
public function getDistrict()
|
||||
{
|
||||
$district_logic = new \app\base\logic\District();
|
||||
|
||||
$district_data = $district_logic->listDistrictTree();
|
||||
|
||||
return sendSuccessMessage([
|
||||
'district_list'=>$district_data
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\file\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
protected $ossConfig; //阿里云OSS配置
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\file\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Upload extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 文件上传到服务器
|
||||
* @date 2022-05-12
|
||||
*/
|
||||
public function fileUpload()
|
||||
{
|
||||
// 获取表单上传文件
|
||||
$file = request()->file('file');
|
||||
|
||||
// 上传到本地服务器
|
||||
$file_name = \think\facade\Filesystem::disk('public')->putFile('uploads/uid' . UID, $file);
|
||||
|
||||
if (!$file_name) {
|
||||
return sendErrorMessage(4001, '上传失败');
|
||||
}
|
||||
|
||||
$url = getDomain() . '/storage/' . $file_name;
|
||||
return sendSuccessMessage(['url' => $url]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取视频截图
|
||||
* @date 2021-06-01
|
||||
*/
|
||||
public function getVideoScreenshot()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$result = get_oss_video_screenshot($param['video_url']);
|
||||
|
||||
return sendSuccessMessage([
|
||||
'image_url'=>$result['url']
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\freight\admin;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\freight\admin;
|
||||
|
||||
|
||||
|
||||
use app\base\logic\District;
|
||||
use think\App;
|
||||
use think\facade\View;
|
||||
use think\Validate;
|
||||
|
||||
class Freight extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 运费设置
|
||||
* @return array|mixed|string
|
||||
*/
|
||||
public function freight()
|
||||
{
|
||||
$where = [
|
||||
'uid' => UID,
|
||||
];
|
||||
$freight_model = new \app\base\model\freight\Freight();
|
||||
$dataList = $freight_model->getAllData($where);
|
||||
View::assign('dataList', $dataList);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则添加
|
||||
*/
|
||||
public function freightmode()
|
||||
{
|
||||
$district_logic = new District();
|
||||
//获取省市数据
|
||||
$mode = input('param.mode', 1);
|
||||
$list = $district_logic->listDistrictTree();
|
||||
View::assign('list', $list);
|
||||
View::assign('mode', $mode);
|
||||
return View::fetch('freightmode');
|
||||
}
|
||||
|
||||
/**
|
||||
* 运费添加
|
||||
* @return array|mixed|string
|
||||
*/
|
||||
public function freightAdd()
|
||||
{
|
||||
$freight_model = new \app\base\model\freight\Freight();
|
||||
if (request()->isPost()) { //新增和更新
|
||||
$data = input('post.');
|
||||
$data['uid'] = UID;
|
||||
if ($data['type'] == 1) {
|
||||
$rule = [
|
||||
'name' => 'require|max:30',
|
||||
'type' => 'require',
|
||||
'first_number' => 'require',
|
||||
'first_number_money' => 'require',
|
||||
'second_number' => 'require',
|
||||
'second_number_money' => 'require',
|
||||
'free_money' => 'require',
|
||||
];
|
||||
$msg = [
|
||||
'name.require' => '规则名称必须',
|
||||
'name.max' => '规则名称最多不能超过30个字符',
|
||||
'type.require' => '运费方式必须',
|
||||
'first_number.require' => '首件必填',
|
||||
'first_number_money.require' => '首费必填',
|
||||
'second_number.require' => '续件必填',
|
||||
'second_number_money.require' => '续费必填',
|
||||
'free_money.require' => '免邮金额必填',
|
||||
];
|
||||
} else {
|
||||
$rule = [
|
||||
'name' => 'require|max:30',
|
||||
'type' => 'require',
|
||||
'first_weight' => 'require',
|
||||
'first_weight_money' => 'require',
|
||||
'second_weight' => 'require',
|
||||
'second_weight_money' => 'require',
|
||||
'free_money' => 'require',
|
||||
];
|
||||
$msg = [
|
||||
'name.require' => '规则名称必须',
|
||||
'name.max' => '规则名称最多不能超过30个字符',
|
||||
'type.require' => '运费方式必须',
|
||||
'first_weight.require' => '首重必填',
|
||||
'first_weight_money.require' => '首费必填',
|
||||
'second_weight.require' => '续重必填',
|
||||
'second_weight_money.require' => '续费必填',
|
||||
'free_money.require' => '免邮金额必填',
|
||||
];
|
||||
}
|
||||
$validate = new Validate($rule, $msg);
|
||||
if (!$validate->check($data)) {
|
||||
return sendErrorMessage(1,$validate->getError());
|
||||
}
|
||||
//检测数据的合理性
|
||||
|
||||
if (!empty($data['id'])) {
|
||||
$where['id'] = ['neq', $data['id']];
|
||||
}
|
||||
$data['fee_conf'] = array_key_exists('fee_conf',$data)?$data['fee_conf']:null;
|
||||
$res = $freight_model->dataUpdate($data);
|
||||
if ($res === false) {
|
||||
return sendErrorMessage();
|
||||
}
|
||||
return sendSuccessMessage();
|
||||
} else { //编辑,添加
|
||||
$id = input('param.id', 0);
|
||||
$data = $freight_model->getOneData(['id' => $id]);
|
||||
//运费
|
||||
$index = 0;
|
||||
if (!empty($data)) {
|
||||
if (!empty($data['fee_conf'])) {
|
||||
if(!empty($data['fee_conf'])){
|
||||
$index = max(array_keys($data['fee_conf']));
|
||||
}
|
||||
}
|
||||
}
|
||||
View::assign('data', $data);
|
||||
View::assign('index', $index); //搜索最大的key值
|
||||
View::assign('mode', isset($data['type']) ? $data['type'] : 1);
|
||||
return View::fetch('freightadd');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 运费修改
|
||||
* @return array|mixed|string
|
||||
*/
|
||||
public function freightUpdate()
|
||||
{
|
||||
return $this->freightAdd();
|
||||
}
|
||||
/**
|
||||
* 更新运费设置的默认项
|
||||
* @return array|string|void
|
||||
*/
|
||||
public function updateDefault()
|
||||
{
|
||||
|
||||
$data = input('post.');
|
||||
$mall_freight_model = new \app\base\model\freight\Freight();
|
||||
if ($data['afterchange'] == 1) {
|
||||
$mall_freight_model->where('id !=' . $data['id'])->update(['is_default' => 0]);
|
||||
}
|
||||
$res = $mall_freight_model->dataUpdate(['is_default' => $data['afterchange'], 'id' => $data['id']]);
|
||||
if ($res === false) {
|
||||
return sendErrorMessage();
|
||||
}
|
||||
return sendSuccessMessage();
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\freight\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* @date 2021-03-01
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\h5\api;
|
||||
|
||||
use think\App;
|
||||
|
||||
class Auth extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* H5生成TOKEN
|
||||
* @date 2020-11-30
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
|
||||
//获取token
|
||||
$info = [
|
||||
'uid' => UID,
|
||||
'user_id' => $param['user_id'],
|
||||
];
|
||||
$res_token = $jwt_class->signToken($info);
|
||||
|
||||
$r_data = $info;
|
||||
$r_data['access_token'] = $res_token['token'];
|
||||
$r_data['access_token_expire_time'] = $res_token['exp'];
|
||||
|
||||
return sendSuccessMessage($r_data);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\h5\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 公众平台配置
|
||||
* @date 2020-11-18
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\h5\api;
|
||||
|
||||
|
||||
use app\base\model\mpalipay\MpalipayUser;
|
||||
use think\App;
|
||||
|
||||
|
||||
class Test extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* H5 一般用于开发环境通过user_id获取token
|
||||
* @date 2020-11-30
|
||||
*/
|
||||
public function getTokenByUserId()
|
||||
{
|
||||
$user_id = input('post.user_id');
|
||||
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
|
||||
//获取token
|
||||
$info = [
|
||||
'uid' => UID,
|
||||
'user_id' => $user_id
|
||||
];
|
||||
$res_token = $jwt_class->signToken($info);
|
||||
|
||||
$r_data = $info;
|
||||
$r_data['access_token'] = $res_token['token'];
|
||||
$r_data['access_token_expire_time'] = $res_token['exp'];
|
||||
|
||||
return sendSuccessMessage($r_data);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\mpalipay\api;
|
||||
|
||||
use app\base\model\mpalipay\MpalipayUser;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class Auth extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 支付宝小程序 授权登录
|
||||
* @date 2020-11-30
|
||||
*/
|
||||
public function getAlipayUserId()
|
||||
{
|
||||
$code = input('post.code');
|
||||
$ali_pay_param = get_mp_alipay_config();
|
||||
|
||||
$mpalipay_user_model = new MpalipayUser();
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
$user_class = new \ali\alipay\mpalipay\User($ali_pay_param);
|
||||
|
||||
//获取支付宝小程序用户信息
|
||||
$result = $user_class->getAlipayUserId($code);
|
||||
|
||||
//记录日志
|
||||
platformLog(['code' => $code], $result, 'alipaysdk_mpalipay_get_user_id_by_code_' . UID);
|
||||
|
||||
if (!empty($result['code'])) {
|
||||
return sendErrorMessage($result['code'], $result['sub_msg']);
|
||||
}
|
||||
|
||||
//更新小程序用户信息表
|
||||
$user_info = [
|
||||
'uid' => UID,
|
||||
'openid' => isset($result['user_id']) ? $result['user_id'] : '',
|
||||
'access_token' => isset($result['access_token']) ? $result['access_token'] : '',
|
||||
'access_token_time' => time(),
|
||||
];
|
||||
$res = $mpalipay_user_model->updateUser($user_info);
|
||||
if(!$res){
|
||||
return sendErrorMessage(4001, '更新小程序用户信息失败');
|
||||
}
|
||||
|
||||
//获取用户信息
|
||||
$mpalipay_user = $mpalipay_user_model->getOneData([
|
||||
['openid', '=', $user_info['openid']]
|
||||
], 'id,user_id,openid');
|
||||
|
||||
//获取token
|
||||
$info = [
|
||||
'uid' => UID,
|
||||
'openid' => $mpalipay_user['openid'],
|
||||
'mpalipay_user_id' => $mpalipay_user['id'],
|
||||
'user_id' => $mpalipay_user['user_id'],
|
||||
];
|
||||
$res_token = $jwt_class->signToken($info);
|
||||
|
||||
$r_data = $info;
|
||||
$r_data['access_token'] = $res_token['token'];
|
||||
$r_data['access_token_expire_time'] = $res_token['exp'];
|
||||
|
||||
return sendSuccessMessage($r_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝小程序 授权获取手机号
|
||||
* @date 2021-12-30
|
||||
*/
|
||||
public function getPhoneNumber()
|
||||
{
|
||||
$param = input('post.');
|
||||
$param['last_user_id'] = input('post.last_user_id', '');
|
||||
$ali_pay_param = get_mp_alipay_config();
|
||||
|
||||
$user_logic = new \app\base\logic\User();
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
$user_class = new \ali\alipay\mpalipay\User($ali_pay_param);
|
||||
|
||||
//换取用户手机号
|
||||
$result = $user_class->getPhoneNumber($param['encrypted_data']);
|
||||
|
||||
//记录三方日志
|
||||
platformLog(['encrypted_data' => $param['encrypted_data']], $result, 'alipaysdk_mpalipay_get_phone_number_' . UID);
|
||||
|
||||
if ($result['code'] != 10000) {
|
||||
return sendErrorMessage($result['code'], $result['subMsg']);
|
||||
}
|
||||
|
||||
$mobile_phone = $result['mobile'];
|
||||
Db::startTrans();
|
||||
|
||||
//根据不同平台组合info参数
|
||||
$info = TOKEN_DATA;
|
||||
$info['user_agent'] = USER_AGENT;
|
||||
|
||||
//登录并更新相关信息(用户表和平台用户表)
|
||||
$res = $user_logic->login($mobile_phone, $info, $param['last_user_id']);
|
||||
if ($res['code'] != 0) {
|
||||
Db::rollback();
|
||||
return json($res);
|
||||
}
|
||||
$user_id = $res['data']['user_id'];
|
||||
Db::commit();
|
||||
|
||||
|
||||
//绑定三方平台
|
||||
// 签发token
|
||||
$arr = TOKEN_DATA;
|
||||
$arr['user_id'] = $user_id;
|
||||
|
||||
$res_token = $jwt_class->signToken($arr);
|
||||
|
||||
$r_data = [
|
||||
'user_id' => $user_id,
|
||||
'access_token' => $res_token['token'],
|
||||
'access_token_expire_time' => $res_token['exp']
|
||||
];
|
||||
|
||||
return sendSuccessMessage($r_data);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\mpalipay\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
protected $mpAlipayConfig; //小程序配置
|
||||
|
||||
/**
|
||||
* 公众平台配置
|
||||
* @date 2020-11-18
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
$ali_pay_param = get_mp_alipay_config();
|
||||
$this->mpAlipayConfig = $ali_pay_param;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\mpalipay\api;
|
||||
|
||||
use app\base\model\mpalipay\MpalipayUser;
|
||||
use app\base\model\user\UserInfo;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class User extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 平台用户信息更新
|
||||
* @date 2022-02-010
|
||||
*/
|
||||
public function updateUserInfo()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$mpalipay_user_model = new MpalipayUser();
|
||||
$info_model = new UserInfo();
|
||||
|
||||
Db::startTrans();
|
||||
//更新微信小程序用户表
|
||||
$data = [
|
||||
'uid' => UID,
|
||||
'openid' => $param['openid'],
|
||||
'nickname' => $param['nickname'],
|
||||
'headimgurl' => $param['headimgurl'],
|
||||
'gender' => $param['gender'],
|
||||
'country' => $param['country'],
|
||||
'province' => $param['province'],
|
||||
'city' => $param['city']
|
||||
];
|
||||
$res = $mpalipay_user_model->updateUser($data);
|
||||
if (!$res) {
|
||||
Db::rollback();
|
||||
return sendErrorMessage(4001, '更新支付宝小程序信息失败');
|
||||
}
|
||||
|
||||
//更新用户信息表
|
||||
$info_data = [
|
||||
'uid' => UID,
|
||||
'user_id' => USER_ID,
|
||||
'user_agent' => USER_AGENT,
|
||||
'nick_name' => $param['nickname'],
|
||||
'head_img' => $param['headimgurl'],
|
||||
];
|
||||
|
||||
$res = $info_model->updateUser($info_data);
|
||||
if (!$res) {
|
||||
Db::rollback();
|
||||
return sendErrorMessage(4002, '更新用户信息失败');
|
||||
}
|
||||
Db::commit();
|
||||
|
||||
return sendSuccessMessage();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\mpalipay\platform;
|
||||
|
||||
use think\App;
|
||||
|
||||
class Notice extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 公众平台和服务器对接
|
||||
* @date 2020-07-23
|
||||
*/
|
||||
public function serveConfig()
|
||||
{
|
||||
dump(111);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\mpqq\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
protected $mpQqConfig; //小程序平台配置
|
||||
|
||||
/**
|
||||
* 配置
|
||||
* @date 2021-07-01
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
$this->mpQqConfig = get_mp_qq_config();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\mptoutiao\api;
|
||||
|
||||
use think\App;
|
||||
|
||||
class Auth extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 抖音小程序 授权登录
|
||||
* @param string $param ['code'] 接口返回的登录凭证
|
||||
* @param string $param ['anonymous_code'] 接口返回的匿名登录凭证
|
||||
* @date 2022-10-19
|
||||
*/
|
||||
public function getOpenid()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$auth_logic = new \app\base\logic\mptoutiao\Auth();
|
||||
|
||||
// 授权登录
|
||||
$result = $auth_logic->getOpenid($param['code'], $param['anonymous_code']);
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝小程序 授权获取手机号
|
||||
* @date 2021-12-30
|
||||
*/
|
||||
public function getPhoneNumber()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\mptoutiao\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
protected $mpAlipayConfig; //小程序配置
|
||||
|
||||
/**
|
||||
* 公众平台配置
|
||||
* @date 2022-10-19
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\mptoutiao\api;
|
||||
|
||||
|
||||
use app\base\model\mpalipay\MpalipayUser;
|
||||
use app\base\model\user\UserInfo;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class User extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 平台用户信息更新
|
||||
* @param string $param ['openid'] OPENID
|
||||
* @param string $param ['nickname'] 昵称
|
||||
* @param string $param ['headimgurl'] 头像
|
||||
* @param string $param ['country'] 国家
|
||||
* @param string $param ['province'] 省
|
||||
* @param string $param ['city'] 市
|
||||
* @param int $param ['gender'] 性别
|
||||
* @param string $param ['language'] 语言
|
||||
* @date 2022-10-19
|
||||
*/
|
||||
public function updateUserInfo()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$user_logic = new \app\base\logic\mptoutiao\User();
|
||||
|
||||
// 更新头衔昵称
|
||||
$result = $user_logic->updateUserInfo($param);
|
||||
|
||||
return json($result);
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\mpweixin\api;
|
||||
|
||||
use app\base\model\mpweixin\MpweixinUser;
|
||||
use tencent\wechat\mpweixin\User;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class Auth extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 微信小程序 wx.login
|
||||
* @date 2020-11-30
|
||||
*/
|
||||
public function getOpenid()
|
||||
{
|
||||
$code = input('post.code');
|
||||
$mp_weixin_config = get_mp_weixin_config();
|
||||
|
||||
$mpweixin_user_model = new MpweixinUser();
|
||||
$user_class = new User($mp_weixin_config);
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
|
||||
// 获取微信小程序用户信息
|
||||
$res = $user_class->getOpenid($code);
|
||||
|
||||
// 更新小程序用户信息表
|
||||
$user_info = [
|
||||
'uid' => UID,
|
||||
'openid' => isset($res['openid']) ? $res['openid'] : '',
|
||||
'unionid' => isset($res['unionid']) ? $res['unionid'] : '',
|
||||
'session_key' => isset($res['session_key']) ? $res['session_key'] : '',
|
||||
'session_key_time' => time(),
|
||||
];
|
||||
if (!$user_info['openid']) {
|
||||
return sendErrorMessage($res['errcode'], $res['errmsg']);
|
||||
}
|
||||
|
||||
$res = $mpweixin_user_model->updateUser($user_info);
|
||||
|
||||
// 获取用户信息
|
||||
$mpweixin_user = $mpweixin_user_model->getOneData([
|
||||
['openid', '=', $user_info['openid']]
|
||||
], 'id,user_id,openid');
|
||||
|
||||
// 获取token
|
||||
$info = [
|
||||
'uid' => UID,
|
||||
'openid' => $mpweixin_user['openid'],
|
||||
'mpweixin_user_id' => $mpweixin_user['id'],
|
||||
'user_id' => empty($mpweixin_user['user_id']) ? '' : $mpweixin_user['user_id'],
|
||||
];
|
||||
$res_token = $jwt_class->signToken($info);
|
||||
|
||||
$r_data = $info;
|
||||
$r_data['access_token'] = $res_token['token'];
|
||||
$r_data['access_token_expire_time'] = $res_token['exp'];
|
||||
|
||||
return sendSuccessMessage($r_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信小程序 授权获取手机号
|
||||
* @date 2021-12-30
|
||||
*/
|
||||
public function getPhoneNumber()
|
||||
{
|
||||
$param = input('post.');
|
||||
$param['last_user_id'] = input('post.last_user_id', '');
|
||||
$mp_weixin_param = get_mp_weixin_config();
|
||||
|
||||
$user_logic = new \app\base\logic\User();
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
$user_class = new User($mp_weixin_param);
|
||||
|
||||
//换取用户手机号
|
||||
$result = $user_class->getPhoneNumber($param['code']);
|
||||
|
||||
if ($result['errcode'] != 0) {
|
||||
return sendErrorMessage($result['errcode'], $result['errmsg']);
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
//根据不同平台组合info参数
|
||||
$info = TOKEN_DATA;
|
||||
$info['user_agent'] = USER_AGENT;
|
||||
|
||||
//登录并更新相关信息(用户表和平台用户表)
|
||||
$res = $user_logic->login($result['phone_info']['phoneNumber'], $info, $param['last_user_id']);
|
||||
if ($res['code'] != 0) {
|
||||
Db::rollback();
|
||||
return json($res);
|
||||
}
|
||||
$user_id = $res['data']['user_id'];
|
||||
Db::commit();
|
||||
|
||||
|
||||
//绑定三方平台
|
||||
// 签发token
|
||||
$arr = TOKEN_DATA;
|
||||
$arr['user_id'] = $user_id;
|
||||
|
||||
$res_token = $jwt_class->signToken($arr);
|
||||
|
||||
$r_data = [
|
||||
'user_id' => $user_id,
|
||||
'access_token' => $res_token['token'],
|
||||
'access_token_expire_time' => $res_token['exp']
|
||||
];
|
||||
|
||||
return sendSuccessMessage($r_data);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\mpweixin\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
protected $mpWeixinConfig; //小程序配置
|
||||
|
||||
/**
|
||||
* 公众平台配置
|
||||
* @date 2020-11-18
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
$mp_weixin_param = get_mp_weixin_config();
|
||||
$this->mpWeixinConfig = $mp_weixin_param;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\oss\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
|
||||
$uid = input('param.uid');
|
||||
defined('UID') || define('UID', $uid);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\oss\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Upload extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 服务端签名直传
|
||||
* @date 2021-03-01
|
||||
*/
|
||||
public function getOssSignature()
|
||||
{
|
||||
// $is_original_name = input('post.is_original_name/d', 0);
|
||||
// $file_path = input('post.file_path/s', '');
|
||||
// $file_path = $this->uploadNameHandel($file_path);
|
||||
|
||||
|
||||
$oss_param = get_ali_oss_config();
|
||||
$service_sign_class = new \ali\oss\ServiceSign(array_merge($oss_param, ['uid' => UID]));
|
||||
|
||||
$data = $service_sign_class->getOssSignature();
|
||||
return sendSuccessMessage($data);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\oss\platform;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
use think\facade\Request;
|
||||
|
||||
class Callback extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 从服务器上传到OSS服务器源文件删除
|
||||
* @date 2022-06-28
|
||||
*/
|
||||
public function uploadCallback()
|
||||
{
|
||||
$header = Request::header();
|
||||
$data = input('post.');
|
||||
|
||||
// 验证签名的参数
|
||||
$authorization_base64 = $header['authorization'];
|
||||
$oss_pub_key_url_base64 = $header['x-oss-pub-key-url'];
|
||||
|
||||
// 参数不存在,则抛出异常
|
||||
if (!$authorization_base64 || !$oss_pub_key_url_base64) {
|
||||
header("http/1.1 403 Forbidden");
|
||||
exit();
|
||||
}
|
||||
|
||||
// 获取公钥链接
|
||||
$oss_pub_key_url = base64_decode($oss_pub_key_url_base64);
|
||||
|
||||
// 获取公钥
|
||||
$pub_key = http_data_get($oss_pub_key_url, 0);
|
||||
|
||||
// 公钥不存在,抛出异常
|
||||
if (!$pub_key) {
|
||||
header("http/1.1 403 Forbidden");
|
||||
exit();
|
||||
}
|
||||
|
||||
// 获取回调body
|
||||
$body = file_get_contents('php://input');
|
||||
|
||||
// 拼接待签名字符串
|
||||
$auth_str = '';
|
||||
// 当前完整URL
|
||||
$path = Request::url();
|
||||
// 返回字符串在另一个字符串中第一次出现的位置。如果没有找到该字符串,则返回 false
|
||||
$pos = strpos($path, '?');
|
||||
if ($pos === false) {
|
||||
$auth_str = urldecode($path) . "\n" . $body;
|
||||
} else {
|
||||
$auth_str = urldecode(substr($path, 0, $pos)) . substr($path, $pos, strlen($path) - $pos) . "\n" . $body;
|
||||
}
|
||||
|
||||
// 验证签名
|
||||
$ok = verifySignData($auth_str, $authorization_base64, $pub_key, 0, OPENSSL_ALGO_MD5);
|
||||
|
||||
// 验证没有成功
|
||||
if (!$ok) {
|
||||
header("http/1.1 403 Forbidden");
|
||||
exit();
|
||||
}
|
||||
|
||||
// 删除文件
|
||||
$file_path = $data['file_path'];
|
||||
unlink($file_path);
|
||||
|
||||
header("Content-Type: application/json");
|
||||
$data = [
|
||||
"Status" => "Ok"
|
||||
];
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\token\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 公众平台配置
|
||||
* @date 2020-11-18
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\token\api;
|
||||
|
||||
use app\base\model\app\AppUser;
|
||||
use think\App;
|
||||
|
||||
class Test extends Base
|
||||
{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 解析token
|
||||
* @date 2021-03-01
|
||||
*/
|
||||
public function token(){
|
||||
$param = input('post.');
|
||||
|
||||
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
|
||||
//解析token
|
||||
$res = $jwt_class->checkToken($param['access_token']);
|
||||
if ($res['code'] != 0) {
|
||||
return sendErrorMessage(1002, 'token失效');
|
||||
}
|
||||
$data = $res['data']['data'] ?? null; //获取解密数据
|
||||
|
||||
|
||||
return sendSuccessMessage($data);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\token\api;
|
||||
|
||||
use app\base\model\app\AppUser;
|
||||
use think\App;
|
||||
|
||||
|
||||
class Token extends Base
|
||||
{
|
||||
/**
|
||||
* 用旧的token签发新的token
|
||||
* @date 2021-02-18
|
||||
*/
|
||||
public function signNewToken()
|
||||
{
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
|
||||
//TOKEN信息
|
||||
$token_data = TOKEN_DATA;
|
||||
|
||||
//签发新的token
|
||||
$res_token = $jwt_class->signToken($token_data);
|
||||
|
||||
$r_data = $token_data;
|
||||
$r_data['access_token'] = $res_token['token'];
|
||||
$r_data['access_token_expire_time'] = $res_token['exp'];
|
||||
|
||||
return sendSuccessMessage($r_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取access_token
|
||||
* @date 2021-02-18
|
||||
*/
|
||||
public function getAccessToken()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
|
||||
$res_token = $jwt_class->signToken($param);
|
||||
|
||||
$r_data = $param;
|
||||
$r_data['access_token'] = $res_token['token'];
|
||||
$r_data['access_token_expire_time'] = $res_token['exp'];
|
||||
|
||||
return sendSuccessMessage($r_data);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\user\admin;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,369 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\user\admin;
|
||||
|
||||
|
||||
use app\distribution\logic\Commission;
|
||||
use app\distribution\model\DistributionCommissionLog;
|
||||
use app\integral\logic\Integral;
|
||||
use app\integral\model\IntegralLog;
|
||||
use app\money\logic\Money;
|
||||
use app\money\model\MoneyLog;
|
||||
use app\money\model\MoneyMy;
|
||||
use excel\Excel;
|
||||
use think\App;
|
||||
use think\facade\View;
|
||||
use think\Validate;
|
||||
|
||||
class User extends Base
|
||||
{
|
||||
/**
|
||||
* 用户列表
|
||||
* @return array|mixed|string
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
$search = input('get.');
|
||||
autoSearch(['time', 'nick_name', 'mobile_phone'], $search);
|
||||
$user_model = new \app\base\model\user\User();
|
||||
|
||||
$where = [['uid', '=', UID]];
|
||||
|
||||
$hasWhere = [];
|
||||
|
||||
if ($search['time']) {
|
||||
$time = explode('-', $search['time']);
|
||||
$where[] = ['create_time', 'between time', [$time[0], $time[1]]];
|
||||
}
|
||||
|
||||
if ($search['mobile_phone'] !== null && $search['mobile_phone'] !== '') {//手机号
|
||||
$where[] = ['mobile_phone', 'like', '%' . $search['mobile_phone'] . '%'];
|
||||
}
|
||||
|
||||
if ($search['nick_name'] !== null && $search['nick_name'] !== '') {//昵称
|
||||
$hasWhere[] = ['nick_name', 'like', '%' . $search['nick_name'] . '%'];
|
||||
}
|
||||
$where = $user_model->whereChange($where);
|
||||
session('where',$where);
|
||||
session('hasWhere',$hasWhere);
|
||||
$dataList = $user_model::hasWhere('userInfo', $hasWhere)->with(['userInfo', 'userMoney', 'userCommission', 'userIntegral'])
|
||||
->where($where)->order('id desc')->paginate([
|
||||
'list_rows' => 20,
|
||||
'page' => array_key_exists("page", $search) ? (string)$search['page'] : "1",
|
||||
'query' => $search
|
||||
], false)
|
||||
->each(function ($item, $key) {
|
||||
$item['money'] = $item['money'] ?? 0;
|
||||
$item['commission'] = $item['commission'] ?? 0;
|
||||
$item['integral'] = $item['integral'] ?? 0;
|
||||
return $item;
|
||||
});
|
||||
$attach = [
|
||||
'total_html' => [['用户总数', $dataList->total()]],
|
||||
];
|
||||
View::assign('attach', $attach);
|
||||
// dump($dataList->toArray());exit();
|
||||
View::assign('dataList', $dataList);
|
||||
View::assign('search', $search);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户列表导出
|
||||
* @return mixed
|
||||
*/
|
||||
public function userExport()
|
||||
{
|
||||
$where = session('where');
|
||||
$hasWhere = session('hasWhere');
|
||||
|
||||
$user_model = new \app\base\model\user\User();
|
||||
|
||||
$dataList = $user_model::hasWhere('userInfo', $hasWhere)->with(['userInfo', 'userMoney', 'userCommission', 'userIntegral'])
|
||||
->where($where)->order('id desc')->select()
|
||||
->each(function ($item, $key) {
|
||||
return $item;
|
||||
});
|
||||
|
||||
|
||||
foreach ($dataList as $key => $value) {
|
||||
|
||||
$data[$key] = [
|
||||
$value['id'], //ID
|
||||
$value['mobile_phone'], //手机号
|
||||
$value['nick_name'], //昵称
|
||||
$value['create_time'], //注册时间
|
||||
];
|
||||
};
|
||||
|
||||
$fileName = "用户列表";
|
||||
$headArr = ["ID", "手机号", '昵称', "注册时间"];
|
||||
$msg = '';
|
||||
$excel_class = new Excel();
|
||||
$res = $excel_class->excelExport($fileName, $headArr, $data, $msg);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户详情
|
||||
*/
|
||||
public function userDetail()
|
||||
{
|
||||
$vip_model = new \app\base\model\user\User();
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
$res = $vip_model->dataUpdate($data);
|
||||
if (!$res) {
|
||||
return sendErrorMessage();
|
||||
}
|
||||
return sendSuccessMessage();
|
||||
} else {
|
||||
$id = input('param.id', 0);
|
||||
$data = $vip_model->with(['userInfo', 'userMoney', 'userCommission', 'userIntegral'])->where(['id' => $id])->find();
|
||||
$data['gender_text'] = $data['gender_text'];
|
||||
View::assign('data', $data);
|
||||
return View::fetch('userdetail');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户余额明细
|
||||
*/
|
||||
public function userMoneyDetails()
|
||||
{
|
||||
$search = input('get.');
|
||||
autoSearch(['time', 'type', 'order_number'], $search);
|
||||
$money_log_model = new MoneyLog();
|
||||
$user_id = input('param.user_id', 0);
|
||||
$where = [
|
||||
['uid', '=', UID],
|
||||
['user_id', '=', $user_id]
|
||||
];
|
||||
if ($search['time']) {
|
||||
$time = explode('-', $search['time']);
|
||||
$where[] = ['create_time', 'between time', [$time[0], $time[1]]];
|
||||
}
|
||||
if ($search['type'] != '' && $search['type'] != null) {
|
||||
$where['type'] = ['type', '=', $search['type']];
|
||||
}
|
||||
if ($search['order_number']) {
|
||||
$where[] = ['relation_order_number', 'like', '%' . $search['order_number'] . '%'];
|
||||
}
|
||||
session('where', $where);
|
||||
|
||||
$page = array_key_exists("page", $search) ? (string)$search['page'] : "1";
|
||||
$dataList = $money_log_model
|
||||
->where($where)->order('id desc')
|
||||
->paginate(['list_rows' => 50, 'page' => $page], false)->each(function ($item, $key) {
|
||||
return $item;
|
||||
});
|
||||
|
||||
View::assign('dataList', $dataList);
|
||||
View::assign('search', $search);
|
||||
return View::fetch('moneydetails');
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加用户余额
|
||||
*/
|
||||
public function userMoneyRaise()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
//写日志变更记录
|
||||
$money_service = new \app\money\service\Money();
|
||||
return $money_service->change($data['user_id'], 7, $data['money'], '后台增加');
|
||||
|
||||
} else {
|
||||
$user_id = input('param.user_id');
|
||||
$source = input('param.source');
|
||||
View::assign('source', $source);
|
||||
View::assign('user_id', $user_id);
|
||||
return View::fetch('moneyraise');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少用户余额
|
||||
*/
|
||||
public function userMoneyReduce()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
if ($data['current_money'] < $data['money']) {
|
||||
return sendErrorMessage(1, '减少的余额数,不能大于当前余额!');
|
||||
}
|
||||
//写日志变更记录
|
||||
$money_service = new \app\money\service\Money();
|
||||
return $money_service->change($data['user_id'], 8, -$data['money'], '后台减少');
|
||||
} else {
|
||||
$user_id = input('param.user_id');
|
||||
$source = input('param.source');
|
||||
//获取当前余额
|
||||
$money_my_model = new MoneyMy();
|
||||
$current_money = $money_my_model->getOneData(['user_id' => $user_id], 'money');
|
||||
$current_money = $current_money ?? 0;
|
||||
|
||||
View::assign('current_money', $current_money);
|
||||
View::assign('source', $source);
|
||||
View::assign('user_id', $user_id);
|
||||
return View::fetch('moneyreduce');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户佣金明细
|
||||
*/
|
||||
public function userIncomeDetails()
|
||||
{
|
||||
$search = input('get.');
|
||||
autoSearch(['time', 'type', 'order_number'], $search);
|
||||
$user_id = input('param.user_id', 0);
|
||||
$distribution_log_model = new DistributionCommissionLog();
|
||||
|
||||
$where = [
|
||||
['uid', '=', UID],
|
||||
['user_id', '=', $user_id]
|
||||
];
|
||||
if ($search['time']) {
|
||||
$time = explode('-', $search['time']);
|
||||
$where[] = ['create_time', 'between time', [$time[0], $time[1]]];
|
||||
}
|
||||
if ($search['type'] != '' && $search['type'] != null) {
|
||||
$where['type'] = ['type', '=', $search['type']];
|
||||
}
|
||||
if ($search['order_number']) {
|
||||
$where[] = ['relation_order_number', 'like', '%' . $search['order_number'] . '%'];
|
||||
}
|
||||
session('where', $where);
|
||||
|
||||
$page = array_key_exists("page", $search) ? (string)$search['page'] : "1";
|
||||
$dataList = $distribution_log_model
|
||||
->where($where)->order('id desc')
|
||||
->paginate(['list_rows' => 50, 'page' => $page], false)->each(function ($item, $key) {
|
||||
return $item;
|
||||
});
|
||||
|
||||
View::assign('dataList', $dataList);
|
||||
View::assign('search', $search);
|
||||
return View::fetch('incomedetails');
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加用户佣金
|
||||
*/
|
||||
public function userIncomeRaise()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
//写日志变更记录
|
||||
$commission_service = new \app\distribution\service\Commission();
|
||||
return $commission_service->change($data['user_id'], 5, $data['commission'], '后台增加');
|
||||
} else {
|
||||
$user_id = input('param.user_id');
|
||||
$source = input('param.source');
|
||||
View::assign('source', $source);
|
||||
View::assign('user_id', $user_id);
|
||||
return View::fetch('incomeraise');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少用户佣金
|
||||
*/
|
||||
public function userIncomeReduce()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
//写日志变更记录
|
||||
$commission_service = new \app\distribution\service\Commission();
|
||||
|
||||
return $commission_service->change($data['user_id'], 6, -$data['commission'], '后台减少');
|
||||
} else {
|
||||
$user_id = input('param.user_id');
|
||||
$source = input('param.source');
|
||||
View::assign('source', $source);
|
||||
View::assign('user_id', $user_id);
|
||||
return View::fetch('incomereduce');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户积分明细
|
||||
*/
|
||||
public function userIntegralDetails()
|
||||
{
|
||||
$search = input('get.');
|
||||
autoSearch(['time', 'type', 'order_number'], $search);
|
||||
View::assign('search', $search);
|
||||
$user_id = input('param.user_id', 0);
|
||||
$integral_log_model = new IntegralLog();
|
||||
|
||||
$where = [
|
||||
['uid', '=', UID],
|
||||
['user_id', '=', $user_id]
|
||||
];
|
||||
if ($search['time']) {
|
||||
$time = explode('-', $search['time']);
|
||||
$where[] = ['create_time', 'between time', [$time[0], $time[1]]];
|
||||
}
|
||||
if ($search['type'] != '' && $search['type'] != null) {
|
||||
$where['type'] = ['type', '=', $search['type']];
|
||||
}
|
||||
if ($search['order_number']) {
|
||||
$where[] = ['relation_order_number', 'like', '%' . $search['order_number'] . '%'];
|
||||
}
|
||||
session('where', $where);
|
||||
|
||||
$page = array_key_exists("page", $search) ? (string)$search['page'] : "1";
|
||||
$dataList = $integral_log_model
|
||||
->where($where)->order('id desc')
|
||||
->paginate(['list_rows' => 50, 'page' => $page], false)->each(function ($item, $key) {
|
||||
return $item;
|
||||
});
|
||||
|
||||
View::assign('dataList', $dataList);
|
||||
return View::fetch('integraldetails');
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加用户积分
|
||||
*/
|
||||
public function userIntegralRaise()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
//写日志变更记录
|
||||
$integral_service = new \app\integral\service\Integral();
|
||||
return $integral_service->change($data['user_id'], 4, $data['integral'], '后台增加');
|
||||
|
||||
} else {
|
||||
$user_id = input('param.user_id');
|
||||
$source = input('param.source');
|
||||
View::assign('source', $source);
|
||||
View::assign('user_id', $user_id);
|
||||
return View::fetch('integralraise');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少用户积分
|
||||
*/
|
||||
public function userIntegralReduce()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$data = input('post.');
|
||||
|
||||
//写日志变更记录
|
||||
$integral_service = new \app\integral\service\Integral();
|
||||
return $integral_service->change($data['user_id'], 5, -$data['integral'], '后台减少');
|
||||
} else {
|
||||
$user_id = input('param.user_id');
|
||||
$source = input('param.source');
|
||||
//获取当前余额
|
||||
View::assign('source', $source);
|
||||
View::assign('user_id', $user_id);
|
||||
return View::fetch('integralreduce');
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,322 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\user\api;
|
||||
|
||||
use app\base\model\district\District;
|
||||
use app\base\model\user\UserAddress;
|
||||
use app\BaseController;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
class Address extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取默认地址
|
||||
* @date 2021-03-01
|
||||
*/
|
||||
public function getDefaultAddress()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$adress_logic = new \app\base\logic\user\Address();
|
||||
|
||||
$result = $adress_logic ->getDefaultAddress();
|
||||
if ($result['code']) {
|
||||
return json($result);
|
||||
}
|
||||
|
||||
return json($result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 我的地址列表
|
||||
* @date 2021-03-01
|
||||
*/
|
||||
public function getAddressList()
|
||||
{
|
||||
$address_model = new UserAddress();
|
||||
|
||||
|
||||
// 获取我的地址列表
|
||||
$list = $address_model->getAllData([
|
||||
['uid', '=', UID],
|
||||
['user_id', '=', USER_ID],
|
||||
], '*', 'is_default desc');
|
||||
|
||||
return sendSuccessMessage([
|
||||
'list' => $list
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有地址
|
||||
* @date 2021-03-01
|
||||
*/
|
||||
public function hasAddress()
|
||||
{
|
||||
$address_model = new UserAddress();
|
||||
|
||||
|
||||
// 获取我的地址列表
|
||||
$number = $address_model->getNumber([
|
||||
['uid', '=', UID],
|
||||
['user_id', '=', USER_ID],
|
||||
]);
|
||||
|
||||
return sendSuccessMessage([
|
||||
'is_frist' => empty($number) ? 1 : 0
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认地址
|
||||
* @date 2021-03-01
|
||||
*/
|
||||
public function setDefault()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
|
||||
$address_model = new UserAddress();
|
||||
|
||||
|
||||
//加载地址
|
||||
$address = $address_model->getOneData([
|
||||
['id', '=', $param['address_id']]
|
||||
]);
|
||||
if (empty($address)) {
|
||||
return sendErrorMessage(4001, '地址不存在');
|
||||
}
|
||||
if ($address['user_id'] != USER_ID) {
|
||||
return sendErrorMessage(4002, '非本人操作');
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
//设置为默认地址
|
||||
$data = [
|
||||
'is_default' => 1
|
||||
];
|
||||
$res = $address_model->dataUpdate($data, [
|
||||
['id', '=', $param['address_id']]
|
||||
]);
|
||||
if (!$res) {
|
||||
Db::rollback();
|
||||
return sendErrorMessage(4003, '设置失败');
|
||||
}
|
||||
|
||||
//其他地址取消默认地址
|
||||
$count = $address_model->getNumber([
|
||||
['user_id', '=', USER_ID],
|
||||
['id', '<>', $param['address_id']],
|
||||
['is_default', '=', 1],
|
||||
]);
|
||||
if (!empty($count)) {
|
||||
$data = [
|
||||
'is_default' => 0
|
||||
];
|
||||
$res = $address_model->dataUpdate($data, [
|
||||
['user_id', '=', USER_ID],
|
||||
['is_default', '=', 1],
|
||||
['id', '<>', $param['address_id']]
|
||||
]);
|
||||
if (!$res) {
|
||||
Db::rollback();
|
||||
return sendErrorMessage(4004, '设置失败');
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return sendSuccessMessage([], '设置成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消默认地址
|
||||
* @date 2021-03-01
|
||||
*/
|
||||
public function cancelDefault()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
|
||||
$address_model = new UserAddress();
|
||||
|
||||
|
||||
//加载地址
|
||||
$address = $address_model->getOneData([
|
||||
['id', '=', $param['address_id']]
|
||||
]);
|
||||
if (empty($address)) {
|
||||
return sendErrorMessage(4001, '地址不存在');
|
||||
}
|
||||
if ($address['user_id'] != USER_ID) {
|
||||
return sendErrorMessage(4002, '非本人操作');
|
||||
}
|
||||
|
||||
//取消默认地址
|
||||
$data = [
|
||||
'is_default' => 0
|
||||
];
|
||||
$res = $address_model->dataUpdate($data, [
|
||||
['id', '=', $param['address_id']]
|
||||
]);
|
||||
if (!$res) {
|
||||
return sendErrorMessage(4003, '设置失败');
|
||||
}
|
||||
|
||||
return sendSuccessMessage([], '取消默认地址成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除我的地址
|
||||
* @date 2021-03-01
|
||||
*/
|
||||
public function delAddress()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
|
||||
$address_model = new UserAddress();
|
||||
|
||||
|
||||
$res = $address_model->dataDel([
|
||||
['id', '=', $param['address_id']]
|
||||
]);
|
||||
if (!$res) {
|
||||
return sendErrorMessage(4001, '删除失败');
|
||||
}
|
||||
|
||||
return sendSuccessMessage([], '删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的地址
|
||||
* @date 2021-03-01
|
||||
*/
|
||||
public function getAddressData()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$address_model = new UserAddress();
|
||||
|
||||
$data = $address_model->getOneData(['id' => $param['address_id']]);
|
||||
|
||||
return sendSuccessMessage(['data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加修改地址
|
||||
* @date 2021-03-01
|
||||
*/
|
||||
public function addressUpdate()
|
||||
{
|
||||
$param = input('post.');
|
||||
$validate = [
|
||||
'linkman' => 'require',
|
||||
'mobile_phone' => 'require|mobile',
|
||||
'address' => 'require',
|
||||
];
|
||||
$this->validate($param, $validate, [
|
||||
'linkman.require' => '请填写联系人',
|
||||
'mobile_phone.require' => '请填写联系方式',
|
||||
'mobile_phone.mobile' => '请输入正确的手机号',
|
||||
'address.require' => '请填写详细地址',
|
||||
]);
|
||||
|
||||
$address_model = new UserAddress();
|
||||
$district_model = new District();
|
||||
|
||||
$data = [
|
||||
'uid' => UID,
|
||||
'user_agent' => USER_AGENT,
|
||||
'user_id' => USER_ID,
|
||||
'linkman' => $param['linkman'],
|
||||
'mobile_phone' => $param['mobile_phone'],
|
||||
'province_id' => $param['province_id'],
|
||||
'city_id' => $param['city_id'],
|
||||
'area_id' => $param['area_id'],
|
||||
'province' => $district_model->getDistrictName($param['province_id']),
|
||||
'city' => $district_model->getDistrictName($param['city_id']),
|
||||
'area' => $district_model->getDistrictName($param['area_id']),
|
||||
'address' => $param['address'],
|
||||
'lat' => $param['lat'],
|
||||
'lng' => $param['lng'],
|
||||
'is_default' => $param['is_default']
|
||||
];
|
||||
if (!empty($param['id'])) {
|
||||
$data['id'] = $param['id'];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
|
||||
if ($data['is_default'] == 1) {
|
||||
//获取默认地址数量
|
||||
$count = $address_model->getNumber([
|
||||
['user_id', '=', USER_ID],
|
||||
['is_default', '=', 1],
|
||||
]);
|
||||
if (!empty($count)) {
|
||||
$data_update = [
|
||||
'is_default' => 0,
|
||||
'update_time' => time()
|
||||
];
|
||||
$res = $address_model->where([
|
||||
['user_id', '=', USER_ID]
|
||||
])->update($data_update);
|
||||
if (!$res) {
|
||||
Db::rollback();
|
||||
return sendErrorMessage(4001, '更新地址失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$res = $address_model->dataUpdate($data);
|
||||
if (!$res) {
|
||||
Db::rollback();
|
||||
return sendErrorMessage(4002, '更新地址失败');
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return sendSuccessMessage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取地址
|
||||
* @throws \app\exception\SendInfo
|
||||
*/
|
||||
public function loadAddress()
|
||||
{
|
||||
$lat = input('post.lat/f', '');
|
||||
$lng = input('post.lng/f', '');
|
||||
if (!$lat || !$lng) {
|
||||
sendSuccessMessage([
|
||||
'address' => '未知位置'
|
||||
]);
|
||||
}
|
||||
$jcapi_logic = new \app\api\logic\JcApi();
|
||||
|
||||
$address_info = $jcapi_logic->coordinateToAddressByTencentMap($lat, $lng);
|
||||
$address = $address_info['result']['formatted_addresses']['recommend'] ?? '未获取到';
|
||||
sendSuccessMessage([
|
||||
'address' => $address,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据经纬度获取城市
|
||||
* @throws \app\exception\SendInfo
|
||||
*/
|
||||
public function getLocationCity()
|
||||
{
|
||||
$lat = input('lat', 0);
|
||||
$lng = input('lng', 0);
|
||||
$result = invoke(JcApi::class)->coordinateToAddressByTencentMap($lat, $lng);
|
||||
sendSuccessMessage($result['result']['address_component']['city']);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\user\api;
|
||||
|
||||
use think\App;
|
||||
|
||||
class Alipay extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取用户支付宝信息
|
||||
* @date 2022-12-27
|
||||
*/
|
||||
public function getAlipay()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$alipay_logic = new \app\base\logic\user\Alipay();
|
||||
|
||||
$result = $alipay_logic->getAlipay();
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户支付宝信息
|
||||
* @date 2022-12-27
|
||||
*/
|
||||
public function updateAlipay()
|
||||
{
|
||||
$param = input('post.');
|
||||
$validate = [
|
||||
'account' => 'require',
|
||||
'name' => 'require'
|
||||
];
|
||||
$this->validate($param, $validate, [
|
||||
'account.require' => '请输入支付宝账号',
|
||||
'name.require' => '请输入支付宝姓名'
|
||||
]);
|
||||
|
||||
$alipay_logic = new \app\base\logic\user\Alipay();
|
||||
|
||||
$result = $alipay_logic->updateAlipay($param);
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否绑定支付宝
|
||||
* @date 2022-03-02
|
||||
*/
|
||||
public function isBindAliPay()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$alipay_logic = new \app\base\logic\user\Alipay();
|
||||
|
||||
$result = $alipay_logic->isBindAliPay();
|
||||
|
||||
return json($result);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\user\api;
|
||||
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Base extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 公众平台配置
|
||||
* @date 2020-11-18
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\user\api;
|
||||
|
||||
use app\project\model\ProjectCheck;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class Login extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 发送手机验证码
|
||||
* @param string $param ['mobile_phone'] 新手机号
|
||||
* @param string $param ['type'] 验证码场景 1--注册或登录发送验证码 2--绑定手机号 3--修改密码 4--换绑手机号验证之前手机号 5--换绑手机号绑定新手机号
|
||||
* @date 2022-10-10
|
||||
*/
|
||||
public function sendCodeMessage()
|
||||
{
|
||||
$param = input('post.');
|
||||
$validate = [
|
||||
'type' => 'number',
|
||||
'mobile_phone' => 'require|mobile',
|
||||
];
|
||||
$this->validate($param, $validate, [
|
||||
'mobile_phone.require' => '请输入手机号',
|
||||
'mobile_phone.mobile' => '请输入正确的手机号'
|
||||
]);
|
||||
$param['type'] = $param['type'] ?? 1;
|
||||
|
||||
$login_logic = new \app\base\logic\user\Login();
|
||||
|
||||
$result = $login_logic->sendCodeMessage($param['mobile_phone'], $param['type']);
|
||||
if ($result['code']) {
|
||||
return json($result);
|
||||
}
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @date 2022-10-12
|
||||
*/
|
||||
public function updatePassword()
|
||||
{
|
||||
$param = input('post.');
|
||||
$validate = [
|
||||
'mobile_phone' => 'require|mobile',
|
||||
'code' => 'require|number|length:4',
|
||||
'password' => 'require|graph|min:6',
|
||||
'password_confirm' => 'require|confirm:password',
|
||||
];
|
||||
$this->validate($param, $validate, [
|
||||
'mobile_phone.require' => '请输入手机号',
|
||||
'mobile_phone.mobile' => '手机号码格式不正确',
|
||||
'code.require' => '请输入验证码',
|
||||
'code.number' => '验证码格式有误',
|
||||
'code.length' => '验证码长度有误',
|
||||
'password.require' => '请输入新密码',
|
||||
'password.graph' => '密码格式有误',
|
||||
'password.min' => '密码最低长度为6位',
|
||||
'password_confirm.require' => '请再次输入新密码',
|
||||
'password_confirm.confirm' => '您输入的两次密码不同'
|
||||
]);
|
||||
|
||||
$login_logic = new \app\base\logic\user\Login();
|
||||
|
||||
$result = $login_logic->updatePassword($param['password'], $param['mobile_phone'], $param['code']);
|
||||
if ($result['code']) {
|
||||
return json($result);
|
||||
}
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认地址
|
||||
* @param string $param ['mobile_phone'] 手机号
|
||||
* @param string $param ['code'] 验证码
|
||||
* @date 2022-10-10
|
||||
*/
|
||||
public function verifyOldMobilePhone()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
// 参数校验
|
||||
$validate = [
|
||||
'mobile_phone' => 'require',
|
||||
'code' => 'require',
|
||||
];
|
||||
$this->validate($param, $validate, [
|
||||
'mobile_phone.require' => '请输入手机号',
|
||||
'code.require' => '请输入验证码'
|
||||
]);
|
||||
|
||||
$login_logic = new \app\base\logic\user\Login();
|
||||
|
||||
$result = $login_logic->verifyOldMobilePhone($param['mobile_phone'], $param['code'], 4);
|
||||
if ($result['code']) {
|
||||
return json($result);
|
||||
}
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更换手机号第二步--绑定新手机号
|
||||
* @param string $param ['mobile_phone'] 新手机号
|
||||
* @param string $param ['code'] 验证码
|
||||
* @param string $param ['mobile_phone_old'] 旧手机号
|
||||
* @date 2022-10-10
|
||||
*/
|
||||
public function bindNewMobilePhone()
|
||||
{
|
||||
$param = input('post.');
|
||||
$validate = [
|
||||
'mobile_phone' => 'require|different:mobile_phone_old',
|
||||
'mobile_phone_old' => 'require',
|
||||
'code' => 'require',
|
||||
];
|
||||
$this->validate($param, $validate, [
|
||||
'mobile_phone.require' => '请输入手机号',
|
||||
'mobile_phone.different' => '新手机号不能和旧手机号一致',
|
||||
'mobile_phone_old.require' => '没有获取到旧手机号',
|
||||
'code.require' => '请输入验证码',
|
||||
]);
|
||||
|
||||
$login_logic = new \app\base\logic\user\Login();
|
||||
|
||||
$result = $login_logic->bindNewMobilePhone($param['mobile_phone'], $param['code'], $param['mobile_phone_old']);
|
||||
if ($result['code']) {
|
||||
return json($result);
|
||||
}
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户登录&注册
|
||||
* @date 2021-02-25
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$param = input('post.');
|
||||
$param['last_user_id'] = input('post.last_user_id', '');
|
||||
$param['third_type'] = input('post.third_type', ''); //APP登录时可能有
|
||||
$param['third_id'] = input('post.third_id', ''); //APP登录时可能有
|
||||
$validate = [
|
||||
'type' => 'require|in:1,2',
|
||||
'mobile_phone' => 'require|mobile',
|
||||
];
|
||||
if ($param['type'] == 1) {
|
||||
$validate['code'] = 'require';
|
||||
} else if ($param['type'] == 2) {
|
||||
$validate['password'] = 'require';
|
||||
}
|
||||
$this->validate($param, $validate, [
|
||||
'mobile_phone.require' => '请输入手机号',
|
||||
'mobile_phone.mobile' => '请输入正确的手机号'
|
||||
]);
|
||||
|
||||
$check_model = new ProjectCheck();
|
||||
$user_logic = new \app\base\logic\User();
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
$login_service = new \app\base\service\user\Login();
|
||||
|
||||
|
||||
//根据不同平台组合info参数
|
||||
$info = TOKEN_DATA;
|
||||
$info['user_agent'] = USER_AGENT;
|
||||
|
||||
Db::startTrans();
|
||||
if ($param['type'] == 1) { //1--手机号验证码登录 2--账号密码登录
|
||||
$is_check = $check_model->isCheck(); //如果是审核状态则不校验验证码
|
||||
if ($is_check != 1) {
|
||||
// 检查验证码是否正确
|
||||
$res = $login_service->checkCode($param['mobile_phone'], $param['code'], 1);
|
||||
if ($res['code'] != 0) {
|
||||
Db::rollback();
|
||||
return json($res);
|
||||
}
|
||||
} else {
|
||||
# TODO 手机号是否为系统已存在手机号 如果不是 提示审核人员输入提供手机号
|
||||
}
|
||||
} else if ($param['type'] == 2) {
|
||||
//检查密码是否正确
|
||||
$res = $user_logic->checkPassword($param['mobile_phone'], $param['password']);
|
||||
if ($res['code'] != 0) {
|
||||
Db::rollback();
|
||||
return json($res);
|
||||
}
|
||||
}
|
||||
|
||||
//登录并更新相关信息
|
||||
$res = $user_logic->login($param['mobile_phone'], $info, $param['last_user_id'], $param['third_type'], $param['third_id']);
|
||||
if ($res['code'] != 0) {
|
||||
Db::rollback();
|
||||
return json($res);
|
||||
}
|
||||
$user_id = $res['data']['user_id']; //USER_ID
|
||||
|
||||
|
||||
Db::commit();
|
||||
|
||||
//绑定三方平台
|
||||
// 签发token
|
||||
$arr = TOKEN_DATA;
|
||||
$arr['user_id'] = $user_id;
|
||||
|
||||
$res_token = $jwt_class->signToken($arr);
|
||||
|
||||
return sendSuccessMessage([
|
||||
'user_id' => $user_id,
|
||||
'access_token' => $res_token['token'],
|
||||
'access_token_expire_time' => $res_token['exp'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户退出登录(APP/H5)
|
||||
* @date 2022-12-27
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$login_logic = new \app\base\logic\user\Login();
|
||||
|
||||
$result = $login_logic->logout();
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\user\api;
|
||||
|
||||
use app\base\model\user\UserInfo;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class User extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取用户个人信息
|
||||
* @date 2022-12-27
|
||||
*/
|
||||
public function getUserInfo()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$user_logic = new \app\base\logic\user\User();
|
||||
|
||||
$result = $user_logic->getUserInfo();
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户个人信息
|
||||
* @date 2022-12-27
|
||||
*/
|
||||
public function updateUserInfo()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$validate = [
|
||||
'head_img' => 'require',
|
||||
'nick_name' => 'require',
|
||||
];
|
||||
$this->validate($param, $validate, [
|
||||
'head_img.require' => '请选择头像',
|
||||
'nick_name.require' => '请填写昵称',
|
||||
]);
|
||||
|
||||
$user_logic = new \app\base\logic\user\User();
|
||||
|
||||
$result = $user_logic->updateUserInfo($param);
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户账户信息
|
||||
* @date 2022-08-29
|
||||
*/
|
||||
public function getAccountInfo()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$user_logic = new \app\base\logic\user\User();
|
||||
|
||||
// 获取用户账户信息
|
||||
$result = $user_logic->getAccountInfo();
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户手机号
|
||||
* @date 2022-10-09
|
||||
*/
|
||||
public function getMobilePhone()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$user_logic = new \app\base\logic\user\User();
|
||||
|
||||
$result = $user_logic->getMobilePhone();
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销账户
|
||||
* @date 2022-12-27
|
||||
*/
|
||||
public function deleteUser()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$user_logic = new \app\base\logic\user\User();
|
||||
|
||||
$result = $user_logic->deleteUser();
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户账号设置
|
||||
* @date 2022-12-27
|
||||
*/
|
||||
public function getAccountConfig()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$user_logic = new \app\base\logic\user\User();
|
||||
|
||||
$result = $user_logic->getAccountConfig();
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户个性化开关状态
|
||||
* @date 2022-12-27
|
||||
*/
|
||||
public function updateAccountConfig()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$user_logic = new \app\base\logic\user\User();
|
||||
|
||||
$result = $user_logic->updateAccountConfig($param['is_personal_recommend']);
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\wechat\admin;
|
||||
|
||||
use app\base\logic\Wechat;
|
||||
use app\base\model\wechat\WechatClassify;
|
||||
use app\base\model\wechat\WechatReply;
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
|
||||
class Classify extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取自定义菜单
|
||||
* @date 2020-10-19
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
$weixin_classify_model = new WechatClassify();
|
||||
|
||||
$data = $weixin_classify_model->getOneData(['uid' => UID]);
|
||||
if(empty($data)){
|
||||
$data['id'] = '';
|
||||
$data['content'] = [];
|
||||
}
|
||||
$rdata = [
|
||||
'data' => $data
|
||||
];
|
||||
return sendSuccessMessage($rdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存自定义菜单
|
||||
* @date 2020-10-21
|
||||
*/
|
||||
public function dataAdd()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$weixin_classify_model = new WechatClassify();
|
||||
|
||||
$classify = [];
|
||||
if (isset($param['name_0'])) {
|
||||
$classify_one_name = $param['name_0'];
|
||||
foreach ($classify_one_name as $k => $v) {
|
||||
$button = [];
|
||||
if (!isset($param['sub_type_' . $k])) { //二级菜单不存在
|
||||
if (!$param['type_0'][$k]) {
|
||||
return sendErrorMessage(4002,'请将自定义菜单填写完整');
|
||||
}
|
||||
$button = ['name' => $v, 'type' => $param['type_0'][$k], 'content' => $param['content_0'][$k]];
|
||||
} else { //二级菜单存在
|
||||
$button['name'] = $v;
|
||||
foreach ($param['sub_type_' . $k] as $k1 => $v1) {
|
||||
if (!$v1) {
|
||||
return sendErrorMessage(4002,'请将自定义菜单填写完整');
|
||||
} else {
|
||||
$button['sub_button'][] = ['name' => $param['sub_name_' . $k][$k1], 'type' => $v1, 'content' => $param['sub_content_' . $k][$k1]];
|
||||
}
|
||||
}
|
||||
}
|
||||
$classify[] = $button;
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id'=>$param['id'],
|
||||
'uid'=>UID,
|
||||
'content'=>$classify
|
||||
];
|
||||
// dump($data);exit;
|
||||
$res = $weixin_classify_model->dataUpdate($data);
|
||||
if(!$res){
|
||||
return sendErrorMessage(4001,'操作失败');
|
||||
}
|
||||
|
||||
return sendSuccessMessage([],'操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布菜单
|
||||
* @date 2020-10-21
|
||||
*/
|
||||
public function classifyPublish()
|
||||
{
|
||||
$weixin_classify_model = new WechatClassify();
|
||||
$wechat_logic = new Wechat();
|
||||
|
||||
//自定义菜单格式化
|
||||
$data = $weixin_classify_model->getOneData(['uid' => UID]);
|
||||
foreach ($data['content'] as $k => $v) {
|
||||
$button = [];
|
||||
if (isset($v['sub_button'])) { //二级菜单存在
|
||||
$button['name'] = $v['name'];
|
||||
foreach ($v['sub_button'] as $vv) {
|
||||
$button['sub_button'][] = $weixin_classify_model->buttonFormat($vv['name'], $vv['type'], $vv['content']);
|
||||
}
|
||||
} else { //二级菜单不存在
|
||||
$button = $weixin_classify_model->buttonFormat($v['name'], $v['type'], $v['content']);
|
||||
}
|
||||
$classify[] = $button;
|
||||
}
|
||||
|
||||
//发布菜单
|
||||
$res = $wechat_logic->classifyPublish($classify);
|
||||
if ($res['errcode'] == 0) {
|
||||
return sendSuccessMessage([],'菜单发布成功');
|
||||
} else {
|
||||
return sendErrorMessage(4001,$res['errmsg']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
* @date 2020-10-19
|
||||
*/
|
||||
public function classifydel()
|
||||
{
|
||||
$weixin_classify_model = new WechatClassify();
|
||||
$wechat_logic = new Wechat();
|
||||
|
||||
$res = $wechat_logic->classifyDel();
|
||||
if ($res['errcode'] == 0) {
|
||||
return sendSuccessMessage([],'菜单删除成功');
|
||||
} else {
|
||||
return sendErrorMessage(4001,$res['errmsg']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自动回复列表
|
||||
* @date 2020-10-20
|
||||
*/
|
||||
public function replyList()
|
||||
{
|
||||
$wechat_reply_model = new WechatReply();
|
||||
|
||||
$reply_list = $wechat_reply_model->getAllData([
|
||||
['uid', '=', UID]
|
||||
])->each(function ($item, $key){
|
||||
$item['type_text'] = $item->type_text;
|
||||
return $item;
|
||||
});
|
||||
|
||||
$rdata = [
|
||||
'list' => $reply_list
|
||||
];
|
||||
return sendSuccessMessage($rdata);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\wechat\admin;
|
||||
|
||||
use ali\oss\Oss;
|
||||
use app\base\logic\Wechat;
|
||||
use app\BaseController;
|
||||
use app\base\controller\wechat\api\Material;
|
||||
use app\base\model\wechat\WechatNews;
|
||||
use think\App;
|
||||
|
||||
|
||||
class News extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取微信图文消息
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$wechat_news_model = new WechatNews();
|
||||
|
||||
$where = [
|
||||
['uid', '=', UID]
|
||||
];
|
||||
if (!empty($param['keyword'])) {
|
||||
$where[] = ['name', 'like', '%' . $param['keyword'] . '%'];
|
||||
}
|
||||
$wechat_news_list = $wechat_news_model->getDataList($where, $param['page'], '*', 'id desc', $param['limit'])->each(function ($item, $key) {
|
||||
$item['type_text'] = $item->type_text;
|
||||
$item['news_number'] = count($item->content);
|
||||
return $item;
|
||||
});
|
||||
|
||||
$rdata = [
|
||||
'list' => $wechat_news_list
|
||||
];
|
||||
return sendSuccessMessage($rdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信图文消息编辑
|
||||
* @date 2020-09-30
|
||||
*/
|
||||
public function dataAdd()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$wechat_news_model = new WechatNews();
|
||||
|
||||
if (empty($param['news_item_title'])) {
|
||||
return sendErrorMessage(2001, '至少添加1条图文');
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id' => $param['id'],
|
||||
'uid' => UID,
|
||||
'name' => $param['name'],
|
||||
'type' => 1,
|
||||
];
|
||||
foreach ($param['news_item_title'] as $k => $v) {
|
||||
$data['content'][] = [
|
||||
'title' => $param['news_item_title'][$k],
|
||||
'description' => $param['news_item_description'][$k],
|
||||
'image' => $param['news_item_image'][$k],
|
||||
'url' => $param['news_item_url'][$k]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$res = $wechat_news_model->dataUpdate($data);
|
||||
if (!$res) {
|
||||
return sendErrorMessage(4001, '操作失败');
|
||||
}
|
||||
|
||||
return sendSuccessMessage([], '操作成功');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除微信图文消息
|
||||
* @param string $id 数据ID
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
public function dataDel()
|
||||
{
|
||||
$id = input('param.id');
|
||||
|
||||
$wechat_news_model = new WechatNews();
|
||||
|
||||
$res = $wechat_news_model->dataDel($id);
|
||||
if (!$res) {
|
||||
return sendErrorMessage(4001, '删除失败');
|
||||
}
|
||||
|
||||
return sendSuccessMessage([], '删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步微信平台微信图文消息
|
||||
* @date 2020-10-09
|
||||
*/
|
||||
public function dataSynchronize()
|
||||
{
|
||||
$wechat_news_model = new WechatNews();
|
||||
$wechat_logic = new Wechat();
|
||||
|
||||
$oss_param = get_ali_oss_config();
|
||||
$ali_config = [
|
||||
'oss' => $oss_param
|
||||
];
|
||||
$oss_class = new Oss($ali_config);
|
||||
|
||||
$material_logic = new \app\base\logic\weixin\Material();
|
||||
|
||||
// 获取所有素材
|
||||
$news_list = $material_logic->listMaterial('news');
|
||||
|
||||
$media_ids = $wechat_news_model->where('media_id', 'not null')->column('id', 'media_id');
|
||||
|
||||
foreach ($news_list as $k => $v) {
|
||||
if (array_key_exists($v['media_id'], $media_ids)) {
|
||||
$data['id'] = $media_ids[$v['media_id']];
|
||||
}
|
||||
|
||||
$data['media_id'] = $v['media_id'];
|
||||
$data['platform_news_content'] = $v;
|
||||
$data['name'] = $v['content']['news_item'][0]['title'];
|
||||
$data['uid'] = UID;
|
||||
$data['type'] = 2;
|
||||
|
||||
$content = [];
|
||||
foreach ($v['content']['news_item'] as $k1 => $v1) {
|
||||
$stream = $wechat_logic->getPermanentMaterial($v1['thumb_media_id']);
|
||||
$picurl = '';
|
||||
if ($stream instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
|
||||
// 以内容 md5 为文件名
|
||||
$file_path = $stream->save('./temp/', md5(microtime(true)));
|
||||
$result = $oss_class->uploadFile('./temp/' . $file_path, 'uid' . UID . '/member/' . date("Ymd"));
|
||||
$picurl = $result['info']['url'];
|
||||
}
|
||||
$content[] = [
|
||||
'title' => $v1['title'],
|
||||
'description' => $v1['digest'],
|
||||
'image' => $picurl,
|
||||
'url' => $v1['url'],
|
||||
];
|
||||
}
|
||||
|
||||
$data['content'] = $content;
|
||||
$wechat_news_model->dataUpdate($data);
|
||||
}
|
||||
|
||||
return sendSuccessMessage([], '同步成功');
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\wechat\admin;
|
||||
|
||||
use app\BaseController;
|
||||
use app\base\model\wechat\WechatNews;
|
||||
use app\base\model\wechat\WechatReply;
|
||||
|
||||
class Reply extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取微信自动回复
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$wechat_reply_model = new WechatReply();
|
||||
|
||||
$where = [
|
||||
['uid', '=', UID]
|
||||
];
|
||||
if(!empty($param['keyword'])){
|
||||
$where[] = ['name', 'like', '%' . $param['keyword'] . '%'];
|
||||
}
|
||||
|
||||
$wechat_reply_list = $wechat_reply_model->getDataList($where, $param['page'],'*', 'id desc', $param['limit']);
|
||||
|
||||
$rdata = [
|
||||
'list' => $wechat_reply_list
|
||||
];
|
||||
return sendSuccessMessage($rdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信自动回复编辑
|
||||
* @param string $id 数据ID
|
||||
* @date 2020-09-24
|
||||
*/
|
||||
public function dataAdd()
|
||||
{
|
||||
$param = input('post.');
|
||||
|
||||
$wechat_reply_model = new WechatReply();
|
||||
|
||||
$data = [
|
||||
'id'=>$param['id'],
|
||||
'uid'=>UID,
|
||||
'trigger_type'=>$param['trigger_type'],
|
||||
'name'=>$param['trigger_type'] == 1 ? $param['name'] : '',
|
||||
'matching_type'=>$param['trigger_type'] == 1 ? $param['matching_type'] : 1,
|
||||
'type'=>$param['type'],
|
||||
];
|
||||
|
||||
if($param['type'] == 'text'){
|
||||
$data['content'] = [
|
||||
'text' => $param['text_content']
|
||||
];
|
||||
}else if($param['type'] == 'image'){
|
||||
$data['content'] = [
|
||||
'image_url' => $param['image_url']
|
||||
];
|
||||
}else if($param['type'] == 'voice'){
|
||||
$data['content'] = [
|
||||
'voice_url' => $param['voice_url']
|
||||
];
|
||||
}else if($param['type'] == 'video'){
|
||||
$data['content'] = [
|
||||
'title' => $param['video_title'],
|
||||
'description' => $param['video_description'],
|
||||
'video_url' => $param['video_url']
|
||||
];
|
||||
}else if($param['type'] == 'music'){
|
||||
$data['content'] = [
|
||||
'title' => $param['music_title'],
|
||||
'description' => $param['music_description'],
|
||||
'music_url' => $param['music_url'],
|
||||
'hq_music_url'=>$param['music_url'],
|
||||
'thumb_url'=>$param['thumb_url']
|
||||
];
|
||||
}else if($param['type'] == 'news'){
|
||||
$data['content'] = [
|
||||
'news_id' => $param['news_id']
|
||||
];
|
||||
}
|
||||
|
||||
$res = $wechat_reply_model->dataUpdate($data);
|
||||
if(!$res){
|
||||
return sendErrorMessage(4001,'操作失败');
|
||||
}
|
||||
|
||||
return sendSuccessMessage([],'操作成功');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除微信自动回复
|
||||
* @param string $id 数据ID
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
public function dataDel()
|
||||
{
|
||||
$id = input('param.id');
|
||||
|
||||
$wechat_reply_model = new WechatReply();
|
||||
|
||||
$res = $wechat_reply_model->dataDel($id);
|
||||
if (!$res) {
|
||||
return sendErrorMessage(4001, '删除失败');
|
||||
}
|
||||
|
||||
return sendSuccessMessage([], '删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图文消息列表
|
||||
* @param string $id 数据ID
|
||||
* @date 2020-09-24
|
||||
*/
|
||||
public function newsList()
|
||||
{
|
||||
$wechat_news_model = new WechatNews();
|
||||
|
||||
$news_list = $wechat_news_model->getAllData([
|
||||
['uid', '=', UID]
|
||||
]);
|
||||
|
||||
$rdata = [
|
||||
'list' => $news_list
|
||||
];
|
||||
return sendSuccessMessage($rdata);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\wechat\api;
|
||||
|
||||
use app\base\model\wechat\WechatUser;
|
||||
use EasyWeChat\Factory;
|
||||
use think\App;
|
||||
|
||||
class Auth extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* Auth2.0 发起授权页
|
||||
* @param string $url 授权后重定向的回调链接地址
|
||||
* @date 2020-08-18
|
||||
*/
|
||||
public function oauth()
|
||||
{
|
||||
$url = input('post.url');
|
||||
$weixin_param = get_weixin_config();
|
||||
$auth_class = new \tencent\wechat\weixin\Auth($weixin_param);
|
||||
|
||||
//获取跳转链接
|
||||
$redirect_url = $auth_class->getRedirectUrl($url);
|
||||
|
||||
//记录三方日志
|
||||
platformLog(['url' => $url], $redirect_url, 'wechat_oauth_get_redirect_url_' . UID);
|
||||
|
||||
return sendSuccessMessage([
|
||||
'redirect_url' => $redirect_url
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Auth2.0 接收用户授权后的状态,并获取用户信息
|
||||
* @param string $code 授权码
|
||||
* @date 2020-08-18
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
$code = input('post.code');
|
||||
$weixin_param = get_weixin_config();
|
||||
|
||||
$wechat_user_model = new WechatUser();
|
||||
$jwt_class = new \jwt\Jwt();
|
||||
$auth_class = new \tencent\wechat\weixin\Auth($weixin_param);
|
||||
|
||||
$result = $auth_class->getUserInfoByCode($code);
|
||||
$result->getTokenResponse();
|
||||
$wechat_data = $result->getRaw();
|
||||
platformLog(['code' => $code], $wechat_data, 'wechat_oauth_get_user_' . UID);
|
||||
|
||||
// 更新微信用户信息
|
||||
$user_wechat_data = [
|
||||
'uid' => UID,
|
||||
'openid' => $wechat_data['openid'],
|
||||
'nickname' => $wechat_data['nickname'],
|
||||
'headimgurl' => $wechat_data['headimgurl'],
|
||||
'sex' => $wechat_data['sex'],
|
||||
'province' => $wechat_data['province'],
|
||||
'city' => $wechat_data['city'],
|
||||
'country' => $wechat_data['country'],
|
||||
'language' => $wechat_data['language'],
|
||||
'unionid' => isset($wechat_data['unionid']) ? $wechat_data['unionid'] : ''
|
||||
];
|
||||
$res = $wechat_user_model->updateUser($user_wechat_data);
|
||||
|
||||
//获取用户信息
|
||||
$wechat_user = $wechat_user_model->getOneData([
|
||||
['openid', '=', $user_wechat_data['openid']]
|
||||
], 'id,user_id,openid');
|
||||
|
||||
$info = [
|
||||
'uid' => UID,
|
||||
'openid' => $wechat_user['openid'],
|
||||
'wechat_user_id' => $wechat_user['id'],
|
||||
'user_id' => $wechat_user['user_id'],
|
||||
];
|
||||
$res_token = $jwt_class->signToken($info);
|
||||
|
||||
$r_data = $info;
|
||||
$r_data['access_token'] = $res_token['token'];
|
||||
$r_data['access_token_expire_time'] = $res_token['exp'];
|
||||
|
||||
return sendSuccessMessage($r_data);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\controller\wechat\api;
|
||||
|
||||
use think\App;
|
||||
|
||||
class Jssdk extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 组装JSSDK配置文件
|
||||
* @param boolean $debug 调试模式是否打开 0--关闭 1--打开
|
||||
* @param string $url 域名链接
|
||||
* @date 2020-08-13
|
||||
*/
|
||||
public function buildConfig()
|
||||
{
|
||||
$debug = input('post.debug', false);
|
||||
$debug = $debug ? true : false;
|
||||
$url = input('post.url');
|
||||
$weixin_param = get_weixin_config();
|
||||
|
||||
$jssdk_class = new \tencent\wechat\weixin\Jssdk($weixin_param);
|
||||
|
||||
$api_list = [
|
||||
'updateAppMessageShareData',
|
||||
'updateTimelineShareData',
|
||||
'onMenuShareTimeline', //即将废弃
|
||||
'onMenuShareAppMessage', //即将废弃
|
||||
'onMenuShareQQ', //即将废弃
|
||||
'onMenuShareWeibo',
|
||||
'onMenuShareQZone',
|
||||
'startRecord',
|
||||
'stopRecord',
|
||||
'onVoiceRecordEnd',
|
||||
'playVoice',
|
||||
'pauseVoice',
|
||||
'stopVoice',
|
||||
'onVoicePlayEnd',
|
||||
'uploadVoice',
|
||||
'downloadVoice',
|
||||
'chooseImage',
|
||||
'previewImage',
|
||||
'uploadImage',
|
||||
'downloadImage',
|
||||
'translateVoice',
|
||||
'getNetworkType',
|
||||
'openLocation',
|
||||
'getLocation',
|
||||
'hideOptionMenu',
|
||||
'showOptionMenu',
|
||||
'hideMenuItems',
|
||||
'showMenuItems',
|
||||
'hideAllNonBaseMenuItem',
|
||||
'showAllNonBaseMenuItem',
|
||||
'closeWindow',
|
||||
'scanQRCode',
|
||||
'chooseWXPay',
|
||||
'openProductSpecificView',
|
||||
'addCard',
|
||||
'chooseCard',
|
||||
'openCard'
|
||||
];
|
||||
|
||||
$config = $jssdk_class->buildConfig($api_list, $debug, $url);
|
||||
|
||||
platformLog(['debug' => $debug, 'url' => $url], $config, 'wechat_build_jssdk_config_' . UID);
|
||||
|
||||
return sendSuccessMessage($config);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace app\base\logic;
|
||||
|
||||
use app\BaseLogic;
|
||||
|
||||
class Base extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @date 2020-07-27
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue