master
郭向斌 2 years ago
commit 53c180105a

8
.gitignore vendored

@ -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,312 @@
<?php
namespace app;
use Godruoyi\Snowflake\Snowflake;
use think\Model;
class BaseModel extends Model
{
protected $mid;
protected $userAgent; //客户端 weixin--微信公众号 mp_weixin--微信小程序 mp_qq--QQ小程序 app--APP
// 用户ID
protected $userId;
/**
* 构造函数
* @date 2020-07-27
*/
public function __construct(array $data = [])
{
parent::__construct($data);
// UID
if (isset($data['uid'])) {
$this->mid = $data['uid'];
} else {
if (defined('UID')) {
$this->mid = UID;
}
}
// USER_AGENT
if (isset($data['user_agent'])) {
$this->userAgent = $data['user_agent'];
} else {
if (defined('USER_AGENT')) {
$this->userAgent = USER_AGENT;
}
}
// USER_ID
if (isset($data['user_id'])) {
$this->userId = $data['user_id'];
} else {
if (defined('USER_ID')) {
$this->userId = USER_ID;
}
}
}
/**
* 查找单条数据或单个字段
* @param array $where 条件
* @param string $field 获取字段
* @param string $order 排序条件
* @param array $with_table 关联查询
* @date 2020-07-27
*/
public function getOneData($where = [], $field = '*', $order = '', $with_table = [])
{
$primary_key_name = $this->getPk();
if (empty($order)) {
$order = (empty($data[$primary_key_name]) ? 'id' : $data[$primary_key_name]) . ' desc';
}
$array = explode(',', $field);
if ($field != '*') {
if (count($array) <= 1) {
return $this->with($with_table)->where($where)->order($order)->value($field);
} else {
return $this->with($with_table)->field($field)->where($where)->order($order)->find();
}
} else {
return $this->with($with_table)->where($where)->order($order)->find();
}
}
/**
* 查找全部数据
* @param array $where 查询条件
* @param string $field 查询字段
* @param string $order 排序方式
* @param int $limit 查询前几条
* @param array $with_table 关联查询
* @date 2020-09-09
*/
public function getAllData($where, $field = '*', $order = '', $limit = 0, $with_table = [])
{
$primary_key_name = $this->getPk();
if (empty($order)) {
$order = (empty($data[$primary_key_name]) ? 'id' : $data[$primary_key_name]) . ' desc';
}
return $this->with($with_table)->field($field)->where($where)->order($order)->limit($limit)->select();
}
/**
* 查找全部数据--带分页
* @param array $where 查询条件
* @param string $field 查询字段
* @param string $order 排序方式
* @param int $page 当前页数
* @param int $per_page_number 每页条数
* @date 2020-09-10
*/
public function getDataList($where, $page, $field = '*', $order = '', $per_page_number = 10)
{
$primary_key_name = $this->getPk();
if (empty($order)) {
$order = (empty($data[$primary_key_name]) ? 'id' : $data[$primary_key_name]) . ' desc';
}
$dataList = $this->field($field)->where($where)->order($order)
->paginate(['list_rows' => $per_page_number, 'page' => $page], false);
return $dataList;
}
/**
* 更新单条数据
* @param array $data 需要更新的信息
* @param array $where 条件
* @date 2020-07-27
*/
public function dataUpdate($data, $where = [])
{
if (empty($data)) {
return false;
}
//有条件更新
$primary_key_name = $this->getPk();
if (!empty($where)) {
$model = $this->where($where)->find();
$res = $model->save($data);
if (!$res) {
return false;
}
$result[$primary_key_name] = $model[$primary_key_name];
} else {
if (array_key_exists($primary_key_name, $data) && !empty($data[$primary_key_name])) { // 数据修改
$result = self::update($data);
} else { // 数据插入
$snow_flake = new Snowflake();
$data[$primary_key_name] = $snow_flake->id();
$result = self::create($data);
}
}
if ($result !== false) {
return $result[$primary_key_name] ? $result[$primary_key_name] : true;
} else {
return false;
}
}
/**
* 数据软删除
* @param array|string $where 条件
* @date 2020-09-16
*/
public function dataDel($where)
{
$res = $this->where($where)->useSoftDelete('delete_time', time())->delete();
if (!$res) {
return false;
}
return true;
}
/**
* 数据删除
* @param array|string $where 条件
* @date 2021-03-25
*/
public function dataDestory($where)
{
$res = $this->where($where)->delete();
if (!$res) {
return false;
}
return true;
}
/**
* 统计数量
* @param array $where 条件
* @return int 没有返回0 有返回数量
* @date 2020-11-30
*/
public function getNumber($where = [])
{
return $this->where($where)->count();
}
/**
* 统计总数
* @param string $field 字段
* @param array $where 条件
* @date 2020-11-30
*/
public function getSum($field, $where)
{
return $this->where($where)->sum($field);
}
/**
* 生成订单编号
* @param string $char 订单编号首位标识
* @param int $length 订单编号末位随机数长度
* @date 2020-11-30
*/
public function createOrderNumber($char = "", $length = 4)
{
$count = 0;
do {
$order_number = $char . date('YmdHis');
for ($i = 0; $i < $length; $i++) {
$order_number .= rand(0, 9);
}
$count = $this->getNumber(['order_number' => $order_number]); //保证生成的订单编号不会重复
} while ($count > 0);
return $order_number;
}
/*
* 修改搜索条件数组始搜索条件数组key加表名
*/
public function whereChange($where)
{
$temp_where = array();
foreach ($where as $key => $value) {
if (strpos($key, $this->name . ".") == false) {
$value[0] = $this->name . "." . $value[0];
$temp_where[] = $value;
} else {
$temp_where[$key] = $value;
}
}
return $temp_where;
}
/**
* 获取无限级数据
* @param array $where 条件
* @param string $order 排序
* @param int $limit_level 查询几级结束
* @param string $relation_id 关联ID字段名
* @param string $keyword 返回数组中当期级别的名称
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfinite($where, $order = '', $limit_level = 0, $relation_id = 'pid', $keyword = 'level')
{
return $this->getInfiniteData($where, $order, $limit_level, $relation_id, $keyword, 0, []);
}
/**
* 无限级数据查询方法
* @param $where
* @param string $order
* @param int $limit_level
* @param string $relation_id
* @param string $keyword
* @param int $now_level
* @param array $return_data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfiniteData($where, $order = '', $limit_level = 0, $relation_id = 'pid', $keyword = 'level', $now_level = 0, $return_data = [])
{
if (!empty($limit_level)) {
if ($limit_level <= $now_level) {
return $return_data;
}
}
if ($now_level == 0) {
$where[$relation_id] = ['elt', 0];
}
if (empty($order)) {
$order = [$this->getPk() => 'desc'];
}
$array = $this->where($where)->order($order)->select();
if (empty($array)) {
return $return_data;
}
foreach ($array as $key => $value) {
$where[$relation_id] = $value[$this->getPk()];
$value[$keyword] = $now_level;
$return_data[] = $value;
$return_data = $this->getInfiniteData($where, $order, $limit_level, $relation_id, $keyword, $now_level + 1, $return_data);
}
return $return_data;
}
}

@ -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,258 @@
<?php
namespace app\base\controller\app\api;
use app\base\model\app\AppAppleUser;
use app\base\model\app\AppQqUser;
use app\base\model\app\AppSinaweiboUser;
use app\base\model\app\AppWeixinUser;
use app\base\model\user\User;
use think\App;
use think\facade\Db;
class ThirdAuth extends Base
{
/**
* APP发起三方授权
* @date 2022-12-27
*/
public function updateThirdAuthInfo()
{
$param = input('post.');
$validate = [
'type' => 'require',
'openid' => 'require',
];
$this->validate($param, $validate);
$third_auth_logic = new \app\base\logic\app\ThirdAuth();
$type = $param['type'];
unset($param['type']);
$result = $third_auth_logic->updateThirdAuthInfo($type,$param);
return json($result);
}
/**
* 解绑授权
* @param string $param ['type'] 类型 weixin--微信 qq--QQ sinaweibo--新浪微博 apple--苹果
* @date 2022-12-27
*/
public function deleteThirdAuthInfo()
{
$param = input('post.');
$third_auth_logic = new \app\base\logic\app\ThirdAuth();
$result = $third_auth_logic->deleteThirdAuthInfo($param['type']);
return json($result);
}
/**
* APP是否发起过三方授权
* @date 2021-03-01
*/
public function getInfo()
{
$param = input('post.');
$validate = [
'type' => 'require',
'openid' => 'require',
];
$this->validate($param, $validate);
$user_model = new User();
$user_logic = new \app\base\logic\User();
$jwt_class = new \jwt\Jwt();
if ($param['type'] == 'weixin') {
$third_platform_user_model = new AppWeixinUser();
$data = [
'uid' => UID,
'openid' => $param['openid'],
'unionid' => $param['unionid'],
'nickname' => $param['nickname'],
'headimgurl' => $param['headimgurl'],
'sex' => $param['sex'],
'province' => $param['province'],
'city' => $param['city'],
'country' => $param['country'],
'language' => $param['language']
];
} else if ($param['type'] == 'qq') {
$third_platform_user_model = new AppQqUser();
$data = [
'uid' => UID,
'openid' => $param['openid'],
'nickname' => $param['nickname'],
'headimgurl' => $param['headimgurl'],
'gender' => $param['gender'],
'gender_type' => $param['gender_type'],
'year' => $param['year'],
'province' => $param['province'],
'city' => $param['city'],
'figureurl_type' => $param['figureurl_type'],
'figureurl' => $param['figureurl'],
'figureurl_qq' => $param['figureurl_qq'],
'is_lost' => $param['is_lost'],
'level' => $param['level'],
'is_yellow_vip' => $param['is_yellow_vip'],
'is_yellow_year_vip' => $param['is_yellow_year_vip'],
'yellow_vip_level' => $param['yellow_vip_level'],
'vip' => $param['vip'],
'constellation' => $param['constellation'],
];
} else if ($param['type'] == 'sinaweibo') {
$third_platform_user_model = new AppSinaweiboUser();
$data = [
'uid' => UID,
'openid' => $param['openid'],
'nickname' => $param['nickname'],
'name' => $param['name'],
'headimgurl' => $param['headimgurl'],
'gender' => $param['gender'],
'province' => $param['province'],
'city' => $param['city'],
'location' => $param['location'],
'description' => $param['description'],
'url' => $param['url'],
'profile_url' => $param['profile_url'],
'domain' => $param['domain'],
'weihao' => $param['weihao'],
'followers_count' => $param['followers_count'],
'friends_count' => $param['friends_count'],
'statuses_count' => $param['statuses_count'],
'favourites_count' => $param['favourites_count'],
'created_at' => $param['created_at'],
'remark' => $param['remark'],
'language' => $param['language'],
];
} else if ($param['type'] == 'apple') {
$third_platform_user_model = new AppAppleUser();
$data = [
'uid' => UID,
'openid' => $param['openid'],
'authorization_code' => $param['authorization_code'],
'identity_token' => $param['identity_token'],
'real_user_status' => $param['real_user_status'],
'scope' => $param['scope']
];
if ($param['family_name']) {
$data['family_name'] = $param['family_name'];
}
if ($param['give_name']) {
$data['give_name'] = $param['give_name'];
}
if ($param['given_name']) {
$data['given_name'] = $param['given_name'];
}
if ($param['email']) {
$data['email'] = $param['email'];
}
}
Db::startTrans();
//更新APP三方授权用户信息
$res = $third_platform_user_model->updateUser($data);
if (!$res) {
Db::rollback();
return sendErrorMessage(4001, '更新授权用户信息失败');
}
//查找APP三方授权用户信息
$third_platform_user = $third_platform_user_model->getOneData([
['openid', '=', $param['openid']]
]);
//token
$token_data = TOKEN_DATA;
$token_user_id = $token_data['user_id']; //ACCESS_TOKEN是否携带user_id
//根据不同情况做出操作
if ($token_user_id) { //如果token携带user_id则为APP用户绑定三方授权或换绑
if ($third_platform_user['user_id'] && $third_platform_user['user_id'] != $token_user_id) {
Db::rollback();
return sendErrorMessage(4002, '该微信已被绑定其他的账号');
}
//绑定三方平台授权信息
$res = $third_platform_user_model->dataUpdate([
'id' => $third_platform_user['id'],
'user_id' => $token_user_id
]);
if (!$res) {
Db::rollback();
return sendErrorMessage(4003, '绑定授权用户失败');
}
//换绑-删除之前的绑定信息
$is_change_bind = $third_platform_user_model->getOneData([
['user_id', '=', $token_user_id],
['openid', '<>', $param['openid']]
]);
if (!empty($is_change_bind)) {
$res = $third_platform_user_model->dataUpdate([
'id' => $is_change_bind['id'],
'user_id' => 0
]);
if (!$res) {
Db::rollback();
return sendErrorMessage(4004, '换绑失败');
}
}
$r_data = [
'type' => 3,
];
} else if ($third_platform_user['user_id']) {//授权登录
//查找用户信息
$user = $user_model->getOneData([
['id', '=', $third_platform_user['user_id']]
]);
//根据不同平台组合info参数
$info = TOKEN_DATA;
$info['user_agent'] = USER_AGENT;
//绑定device_id和user_id
$res = $user_logic->login($user['mobile_phone'], $info);
if ($res['code'] != 0) {
Db::rollback();
return json($res);
}
// 签发token
$arr = TOKEN_DATA;
$arr['user_id'] = $user['id'];
$res_token = $jwt_class->signToken($arr);
$r_data['access_token'] = $res_token['token'];
$r_data['access_token_expire_time'] = $res_token['exp'];
$r_data = [
'type' => 2, //1--授权注册 2--授权登录 3--授权绑定或换绑
'third_platform_user' => $third_platform_user,
'user_id' => $user['id'],
'access_token' => $res_token['token'],
'access_token_expire_time' => $res_token['exp'],
];
} else { //授权注册
$r_data = [
'type' => 1,
'third_platform_user' => $third_platform_user
];
}
Db::commit();
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,100 @@
<?php
namespace app\base\controller\cos\admin;
use app\BaseController;
use think\App;
use think\facade\Request;
class File extends BaseController
{
/**
* 上传图片
* @date 2022-11-29
*/
public function getCosParam()
{
$is_original_name = input('post.is_original_name/d', 0);
$file_path = input('post.file_path/s', '');
$tecent_cos_param = get_tencent_cos_config(UID);
$credentials_class = new \tencent\sts\credentials\Credentials($tecent_cos_param);
// 是否保留原文件名
if (empty($is_original_name)) {
$file_name = md5(microtime(true));
} else {
$file_name = '';
}
// 获取临时密钥
$policy = [
// 描述策略语法版本。该元素是必填项。目前仅允许值为“2.0”
"version" => "2.0",
// 描述一条或多条权限的详细信息
"statement" => [
[
// 描述声明产生的结果是“允许”还是“显式拒绝”。包括 allow允许和 deny (显式拒绝)两种情况。该元素是必填项
"effect" => "allow",
// 描述允许或拒绝的操作
"action" => [
"cos:PutObject",
"cos:PostObject"
],
// 描述授权的具体数据
"resource" => [
/* qcs-qcloud service 的简称,表示是腾讯云的云资源
service_type:cos产品简称
region:$tecent_cos_param['region'] 描述地域信息
account::uid/$tecent_cos_param['main_app_id'] 描述资源拥有者的主账号信息目前支持两种方式描述资源拥有者uin 和 uid 方式
*/
"qcs::cos:" . $tecent_cos_param['region'] . ":uid/" . $tecent_cos_param['main_app_id'] . ":" . $tecent_cos_param['bucket_name'] . "/*"
],
]
]
];
$result = $credentials_class->getFederationToken('cos', $policy);
$return_data = [
'token' => $result['Credentials']['Token'],
'tem_secret_id' => $result['Credentials']['TmpSecretId'],
'tem_secret_key' => $result['Credentials']['TmpSecretKey'],
'bucket' => $tecent_cos_param['bucket_name'],
'region' => $tecent_cos_param['region'],
'scheme' => Request::scheme(),
// 请求地址
'host' => Request::scheme() . '://' . $tecent_cos_param['bucket_name'] . '.cos.' . $tecent_cos_param['region'] . '.myqcloud.com/',
// 目录
'dir' => empty($file_path) ? $tecent_cos_param['first_directory'] . '/uid' . UID . '/member/' . date('Ymd') . '/' . $file_name : $file_path . date('YmdHis'),
// 展示地址
'show_url' => $tecent_cos_param['show_url']
];
return sendSuccessMessage($return_data);
}
/**
* 本地图片转cos
* @param $param ['url'] 本地路径 示例:/ueditor/php/upload/image/20221205/1670210864567835.jpg
* @date 2022-12-05
*/
public function ueditorFileUploadToCos()
{
$param = input('post.');
$tencent_cos_param = get_tencent_cos_config(2);
$file_class = new \tencent\cos\object\File($tencent_cos_param);
$cos_file_dirname = 'uid' . 2 . '/ueditor/' . date("Ymd");
$result = $file_class->uploadFile('.' . $param['url'], $cos_file_dirname);
return sendSuccessMessage([
// 图片COS地址
'url' => $result
]);
}
}

@ -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,72 @@
<?php
namespace app\base\controller\cos\api;
use app\BaseController;
use think\App;
use think\facade\Request;
class Upload extends BaseController
{
/**
* 上传图片
* @date 2022-12-12
*/
public function getCosParam()
{
// $is_original_name = input('post.is_original_name/d', 0);
// $file_path = input('post.file_path/s', '');
$tecent_cos_param = get_tencent_cos_config(UID);
$credentials_class = new \tencent\sts\credentials\Credentials($tecent_cos_param);
// 获取临时密钥
$policy = [
// 描述策略语法版本。该元素是必填项。目前仅允许值为“2.0”
"version" => "2.0",
// 描述一条或多条权限的详细信息
"statement" => [
[
// 描述声明产生的结果是“允许”还是“显式拒绝”。包括 allow允许和 deny (显式拒绝)两种情况。该元素是必填项
"effect" => "allow",
// 描述允许或拒绝的操作
"action" => [
"cos:PutObject",
"cos:PostObject"
],
// 描述授权的具体数据
"resource" => [
/* qcs-qcloud service 的简称,表示是腾讯云的云资源
service_type:cos产品简称
region:$tecent_cos_param['region'] 描述地域信息
account::uid/$tecent_cos_param['main_app_id'] 描述资源拥有者的主账号信息目前支持两种方式描述资源拥有者uin 和 uid 方式
*/
"qcs::cos:" . $tecent_cos_param['region'] . ":uid/" . $tecent_cos_param['main_app_id'] . ":" . $tecent_cos_param['bucket_name'] . "/*"
],
]
]
];
$result = $credentials_class->getFederationToken('cos', $policy);
$return_data = [
'token' => $result['Credentials']['Token'],
'tem_secret_id' => $result['Credentials']['TmpSecretId'],
'tem_secret_key' => $result['Credentials']['TmpSecretKey'],
'bucket' => $tecent_cos_param['bucket_name'],
'region' => $tecent_cos_param['region'],
'scheme' => Request::scheme(),
// 请求地址
'host' => Request::scheme() . '://' . $tecent_cos_param['bucket_name'] . '.cos.' . $tecent_cos_param['region'] . '.myqcloud.com/',
// 目录
'dir' => $tecent_cos_param['first_directory'] . '/uid' . UID . '/api/' . date('Ymd'),
// 展示地址
'show_url' => $tecent_cos_param['show_url']
];
return sendSuccessMessage($return_data);
}
}

@ -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,245 @@
<?php
namespace app\base\controller\demo\api;
use think\App;
class Xunfei extends Base
{
/**
* 活体检测 图片
*/
public function detectLivingFace()
{
$param = input('post.');
$ivision_param = get_ali_ivision_config();
$detect_living_face_class = new \ali\alibabacloud\ivision\facebody\DetectLivingFace($ivision_param);
// 最多支持10张图片同时检测
$image_url = [
['url' => $param['image_url']]
];
$result = $detect_living_face_class->detectLivingFace($image_url);
// 有错误
if (isset($result['Code']) && $result['Code'] !== 0) {
return sendErrorMessage($result['Code'], $result['Message']);
}
if ($result['Data']['Elements'][0]['Results'][0]['Suggestion'] == 'pass') {
dump('检测通过');
} else {
dump('检测未通过');
}
}
/**
* 活体检测 视频
*/
public function detectVideoLivingFace()
{
$param = input('post.');
$ivision_param = get_ali_ivision_config();
$detect_living_face_class = new \ali\alibabacloud\ivision\facebody\DetectLivingFace($ivision_param);
$video_url = $param['video_url'];
$result = $detect_living_face_class->detectVideoLivingFace($video_url);
// 有错误
if (isset($result['Code']) && $result['Code'] !== 0) {
return sendErrorMessage($result['Code'], $result['Message']);
}
if ($result['Data']['Elements'][0]['FaceConfidence'] > 0.8 && $result['Data']['Elements'][0]['LiveConfidence'] > 0.8) {
dump('检测通过');
} else {
dump('检测未通过');
}
}
/**
* 人脸识别
*/
public function compareFace()
{
$param = input('post.');
$ivision_param = get_ali_ivision_config();
$compare_class = new \ali\alibabacloud\ivision\facebody\Compare($ivision_param);
//要对比的图片
$image_url_a = $param['image_url_a'];
$image_url_b = $param['image_url_b'];
$result = $compare_class->compareFace($image_url_a, $image_url_b);
// 有错误
if (isset($result['Code']) && $result['Code'] !== 0) {
return sendErrorMessage($result['Code'], $result['Message']);
}
if ($result['Data']['Confidence'] < 75) {
dump('检测未通过');
}
dump('检测通过');
}
/**
* 语音合成
* @date 2022-05-11
*/
public function textToVoice()
{
// $param = input('post.');
// $platform = config('platform');
//
// $oss_param = get_ali_oss_config();
// $ise_class = new \xunfei\ise\Ise($platform[UID]['xunfei']['ise']);
// $oss_class = new \ali\oss\Oss($oss_param);
//
// // 设置合成参数
// $tts_config = [
// 'aue' => 'lame',
// 'sfl' => 1,
// 'vcn' => 'aisjiuxu', //发音人,可选值:请到控制台添加试用或购买发音人,添加后即显示发音人参数值
// 'speed' => 30, //语速,可选值:[0-100]默认为50
// 'volume' => 80, //音量,可选值:[0-100]默认为50
// //...
// ];
//
// //语音合成
// $result = $ise_class->tts($param['text'], $tts_config);
//
// //记录日志
// platformLog([
// 'text' => $param['text'],
// 'tts_config' => $tts_config
// ], $result, 'xunfei_tts_' . UID);
//
// // 录音文件本地路径
// $local_file_url = $result;
// $oss_file_dirname = 'uid' . UID . '/tts/' . date("Ymd"); //录音文件OSS存放路径
//
// //文件上传到OSS
// $result = $oss_class->uploadFile($local_file_url, $oss_file_dirname);
//
// $url = $result['url'];
// dump($url);
}
/**
* 语音识别
* @date 2022-05-06
*/
public function ise()
{
// $param = input('post.');
// $platform = config('platform');
//
// $oss_param = get_ali_oss_config();
// $ise_class = new \xunfei\ise\Ise($platform[UID]['xunfei']['ise']);
// $oss_class = new \ali\oss\Oss($oss_param);
//
// //本地存储路径
// $local_file_url = './temp/' . md5(microtime(true)) . '.mp3';
// $result = $oss_class->getObject($param['file'], $local_file_url, true);
//
// //OSS下载文件报错
// if (isset($result['Code'])) {
// return sendErrorMessage(4100, $result['Message']);
// }
//
// //本地文件
// $local_file_url = $result['local_file_url'];
//// dump($local_file_url);
// $text = $param['text'];
// $type = $param['type']; //read_syllable--单字朗读,汉语专有 read_word--词语朗读 read_sentence--句子朗读 read_chapter--篇章朗读
//
// // 设置评测参数
// $tts_config = [
// 'aue' => 'lame',
// 'ent' => 'cn_vip',
// 'category' => $type
// //...
// ];
//
// //语音评测
// $result = $ise_class->ise($local_file_url, $text, $tts_config);
//// dump($result);
// // 记录日志
// platformLog([
// 'file' => $local_file_url,
// 'text' => $text,
// 'tts_config' => $tts_config
// ], $result, 'xunfei_ise_ise_' . UID);
//
// if (isset($result['code']) && $result['code'] != 0) {
// return sendErrorMessage($result['code'], $result['message']);
// }
//
// #TODO 删除服务器语音文件
// unlink($local_file_url);
//
// //单字朗读,汉语专有返回
// $read_result = $result[$type]['rec_paper'][$type];
// return sendSuccessMessage([
// 'data' => $read_result
// ]);
//
// //dump($result);
}
/**
* 语音识别(传到服务器)
* @date 2022-05-06
*/
public function iseServer()
{
// $param = input('post.');
// $platform = config('platform');
//
// $oss_param = get_ali_oss_config();
//
// $ise_class = new \xunfei\ise\Ise($platform[UID]['xunfei']['ise']);
// $oss_class = new \ali\oss\Oss($oss_param);
//
// //本地文件
// $local_file_url = getFileRealativePath($param['file'], '.net/');
// $local_file_url = './' . $local_file_url;
// $text = $param['text'];
//
// // 设置评测参数
// $tts_config = [
// 'aue' => 'lame',
// 'ent' => 'cn_vip', //中文cn_vip 英文en_vip
// 'category' => 'read_word' //中文题型 read_word--词语朗读
// //...
// ];
//// dump($local_file_url);
// //语音评测
// $result = $ise_class->ise($local_file_url, $text, $tts_config);
//// dump($result);
// // 记录日志
// platformLog([
// 'file' => $local_file_url,
// 'text' => $text,
// 'tts_config' => $tts_config
// ], $result, 'xunfei_ise_ise_' . UID);
//
// if (isset($result['code']) && $result['code'] != 0) {
// return sendErrorMessage($result['code'], $result['message']);
// }
// return sendSuccessMessage($result['read_word']['rec_paper']['read_word']);
////
//// dump($result);
}
}

@ -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,28 @@
<?php
namespace app\base\controller\mpalipay\platform;
use app\BaseController;
use think\App;
use think\facade\Request;
class Base extends BaseController
{
protected $config; //小程序配置
/**
* 公众平台配置
* @date 2020-07-23
*/
public function __construct(App $app)
{
parent::__construct($app);
// 不基于JWTuid为推送时链接自带传参
$uid = input('param.uid');
defined('UID') || define('UID', $uid);
$ali_pay_param = get_mp_alipay_config();
$this->config = $ali_pay_param;
}
}

@ -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,124 @@
<?php
namespace app\base\controller\mpqq\api;
use app\base\model\mpqq\MpqqUser;
use think\App;
class Auth extends Base
{
/**
* 微信小程序 wx.login
* @date 2021-07-01
*/
public function getOpenid()
{
$code = input('post.code');
$qq_param = get_mp_qq_config();
$mpqq_user_model = new MpqqUser();
$jwt_class = new \jwt\Jwt();
$auth_class = new \tencent\qq\Auth($qq_param);
//获取微信小程序用户信息
$res = $auth_class->getOpenid($code);
if (empty($res['openid'])) {
return sendErrorMessage(4001, '授权失败');
}
//更新小程序用户信息表
$user_info = [
'uid' => UID,
'openid' => $res['openid'],
'unionid' => isset($res['unionid']) ? $res['unionid'] : '',
'session_key' => isset($res['session_key']) ? $res['session_key'] : '',
'session_key_time' => time(),
];
$res = $mpqq_user_model->updateUser($user_info);
//获取用户信息
$mpqq_user = $mpqq_user_model->getOneData([
['openid', '=', $user_info['openid']]
], 'id,user_id,openid');
//获取token
$info = [
'uid' => UID,
'openid' => $mpqq_user['openid'],
'mpqq_user_id' => $mpqq_user['id'],
'user_id' => $mpqq_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-07-01
*/
public function userInfoUpdate()
{
$param = input('post.');
$mpqq_user_model = new MpqqUser();
$data = [
'uid' => UID,
'openid' => OPENID,
'nickname' => $param['nickname'],
'headimgurl' => $param['headimgurl'],
'gender' => $param['gender'],
'country' => $param['country'],
'province' => $param['province'],
'city' => $param['city'],
'language' => $param['language']
];
$res = $mpqq_user_model->updateUser($data);
if (!$res) {
return sendErrorMessage(4001, '更新信息失败');
}
return sendSuccessMessage();
}
/**
* 微信小程序 通过openid获取信息一般用于测试openid或access_token过期后重新获取
* @date 2021-07-01
*/
public function getUserByOpenid()
{
$openid = input('post.openid');
$mpqq_user_model = new MpqqUser();
$jwt_class = new \jwt\Jwt();
//获取用户信息
$mpqq_user = $mpqq_user_model->getOneData([
['openid', '=', $openid]
], 'id,user_id,openid');
//获取token
$info = [
'uid' => UID,
'openid' => $mpqq_user['openid'],
'mpqq_user_id' => $mpqq_user['id'],
'user_id' => $mpqq_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,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,22 @@
<?php
namespace app\base\controller\mpweixin\api;
class User extends Base
{
/**
* 根据unionid判断是否关注微信在同一微信开放平台下绑定
* @date 2022-12-28
*/
public function isSubscribeWeixin()
{
$param = input('post');
$user_logic = new \app\base\logic\mpweixin\User();
$result = $user_logic -> isSubscribeWeixin();
return json($result);
}
}

@ -0,0 +1,28 @@
<?php
namespace app\base\controller\mpweixin\platform;
use app\BaseController;
use think\App;
use think\facade\Request;
class Base extends BaseController
{
protected $mpWeixinConfig; //小程序配置
/**
* 公众平台配置
* @date 2020-07-23
*/
public function __construct(App $app)
{
parent::__construct($app);
// 不基于JWTuid为推送时链接自带传参
$uid = input('param.uid');
defined('UID') || define('UID', $uid);
$mp_weixin_param = get_mp_weixin_config();
$this->mpWeixinConfig = $mp_weixin_param;
}
}

@ -0,0 +1,99 @@
<?php
namespace app\base\controller\mpweixin\platform;
use app\base\model\mpweixin\MpweixinUser;
use EasyWeChat\Factory;
use think\App;
class Notice extends Base
{
/**
* 公众平台和服务器对接
* @date 2020-07-23
*/
public function serveConfig()
{
$mp_weixin_param = get_mp_weixin_config();
$notice_class = new \tencent\wechat\mpweixin\Notice($mp_weixin_param);
$mp_weixin_config = $notice_class->getMpWeixinConfig();
$app = Factory::miniProgram($mp_weixin_config);
$app->server->push(function ($message) {
platformLog('', $message, 'mp_weixin_get_user_message_' . UID);
$result = Notice::messageResponse($message);
return $result;
});
$response = $app->server->serve();
// 将响应输出
$response->send();
exit;
}
/**
* 接收普通消息并处理
* @param array $message 普通微信用户向公众账号发消息时,微信服务器请求的服务器携带参数 xml已转array
* @date 2020-07-23
*/
protected function messageResponse($message = [])
{
switch ($message['MsgType']) {
case 'event':
if ($message['Event'] == 'user_authorization_revoke') { //用户撤回 user_info_modified用户资料变更user_authorization_revoke用户撤回
$this->replyUserAuthorizationRevoke($message);
return 'success';
} else if ($message['Event'] == 'user_info_modified') {
return '';
} else if ($message['Event'] == 'subscribe_msg_sent_event') { //发送订阅消息之后
return '';
}
return '收到事件消息';
break;
default:
return '收到其它消息';
break;
}
}
/**
* 回复用户消息 - 用户撤回授权信息
* @param array $message 普通微信用户向公众账号发消息时,微信服务器请求的服务器携带参数 xml已转array
* @param string $message ['ToUserName'] 小程序的UserName
* @param string $message ['FromUserName'] 平台推送服务UserName
* @param string $message ['MsgType'] 消息类型Event
* @param string $message ['Event'] user_info_modified用户资料变更user_authorization_revoke用户撤回
* @param int $message ['CreateTime'] 消息创建时间 (整型)
* @param string $message ['OpenID'] 撤回或变更资料的用户OpenID
* @param string $message ['AppID'] 小程序的AppID
* @param string $message ['RevokeInfo'] 用户撤回的授权信息1:车牌号,2:地址,3:发票信息,4:蓝牙,5:麦克风,6:昵称和头像,7:摄像头,8:手机号,12:微信运动步数,13:位置信息,14:选中的图片或视频,15:选中的文件,16:邮箱地址
* @param string $message ['PluginID'] 插件场景用户撤回插件的AppID
* @param string $message ['OpenPID'] 插件场景用户撤回撤回用户的OpenPID
* @date 2020-07-27
*/
protected function replyUserAuthorizationRevoke($message)
{
if ($message['RevokeInfo'] == 6) {
$openid = $message['OpenID'];
$mpweixin_user_model = new MpweixinUser();
//删除用户头像和昵称
$data = [
'openid' => $openid,
'nickname' => '',
'headimgurl' => '',
];
$res = $mpweixin_user_model->updateUser($data);
// TODO 是否需要删除userinfo表 以及是否给微信服务器正常返回需测试
}
}
}

@ -0,0 +1,118 @@
<?php
namespace app\base\controller\oss\admin;
use app\BaseController;
use think\App;
class Oss extends BaseController
{
/**
* 格式话上传文件名
* @param $name
* @return mixed
*/
private function uploadNameHandel($name)
{
//+过滤
$name = str_replace("+", "", $name);
//空格过滤
$name = str_replace(' ', '', $name);
return $name;
}
private function gmtIso8601($time)
{
$dtStr = date("c", $time);
$pos = strpos($dtStr, '+');
$expiration = substr($dtStr, 0, $pos);
return $expiration . ".000Z";
}
/**
* 上传图片
* @date 2020-09-17
*/
public function getOssParam()
{
$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();
$oss_config = $oss_param;
$protocol = getProtocol();
$accessKeyId = $oss_config['access_key_id'];
$accessKeySecret = $oss_config['access_key_secret'];
$bucketDefaultDomain = $oss_config['bucket_default_url'];
$showUrlDomain = $oss_config['show_url'] . '/';
$projectName = config('database.connections.mysql.database');
if (empty($is_original_name)) {
$file_name = date('Ymd') . '/' . md5(microtime(true));
} else {
$file_name = '';
}
$callback_param = array(
'callbackUrl' => 'https://ym2.jucheng01.net/' . 'member/Oss/fileCallBack',
'callbackBody' => 'bucket=${bucket}&object=${object}&show_url_domain=${show_url_domain}',
'callbackBodyType' => "application/x-www-form-urlencoded"
);
//var_dump($callback_param);die;
$callback_string = json_encode($callback_param);
$base64_callback_body = base64_encode($callback_string);
$now = time();
$expire = 30; //设置该policy超时时间是10s. 即这个policy过了这个有效时间将不能访问。
$end = $now + $expire;
$expiration = $this->gmtIso8601($end);
$conditions = [
// 上传Object的最小和最大允许大小
array(0 => 'content-length-range', 1 => 0, 2 => 1048576000),//最大文件大小.用户可以自己设置
array(0 => 'starts-with', 1 => '$key', 2 => $projectName)// 表示用户上传的数据,必须是以$dir开始不然上传会失败这一步不是必须项只是为了安全起见防止用户通过policy上传到别人的目录。
];
$policy = array('expiration' => $expiration, 'conditions' => $conditions);
$policy = json_encode($policy);
$base64_policy = base64_encode($policy);
$string_to_sign = $base64_policy;
$signature = base64_encode(hash_hmac('sha1', $string_to_sign, $accessKeySecret, true));
$response = array();
$response['accessid'] = $accessKeyId;
$response['host'] = $bucketDefaultDomain;
$response['showUrlDomain'] = $showUrlDomain;
$response['policy'] = $base64_policy;
$response['signature'] = $signature;
$response['expire'] = $end;
$response['callback'] = $base64_callback_body;
$response['dir'] = empty($file_path) ? $projectName . '/uid' . 2 . '/member/' . $file_name : $file_path . date('YmdHis'); // 这个参数是设置用户上传文件时指定的前缀。
return sendSuccessMessage($response);
}
/**
* 本地图片转oss
* @param $param ['url'] 本地路径
* @date 2022-12-05
*/
public function ossload()
{
$param = input('post.');
$oss_param = get_ali_oss_config(2);
$oss_class = new \ali\oss\Oss($oss_param);
$oss_file_dirname = 'uid' . 2 . '/ueditor/' . date("Ymd");
$oss = $oss_class->uploadFile('.' . $param['url'], $oss_file_dirname);
$url = $oss['url'];
return sendSuccessMessage(['url' => $url]);
}
}

@ -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,612 @@
<?php
namespace app\base\controller\wechat\admin;
use ali\oss\Oss;
use app\base\logic\weixin\Material;
use app\base\model\wechat\WechatClassify;
use app\base\model\wechat\WechatNews;
use app\base\model\wechat\WechatReply;
use app\BaseController;
use think\App;
use think\facade\View;
use EasyWeChat\Factory;
class Wechat extends BaseController
{
protected $easyWechatConfig; //easywechat微信配置文件
public function __construct(App $app)
{
parent::__construct($app);
$uid = input('param.uid');
defined('UID') || define('UID', $uid);
$weixin_param = get_weixin_config();
$this->easyWechatConfig = [
'app_id' => $weixin_param['app_id'],
'secret' => $weixin_param['app_secret'],
'token' => $weixin_param['token'],
'response_type' => 'array',
//日志 配置
'log' => [
'default' => 'dev', // 默认使用的 channel生产环境可以改为下面的 prod
'channels' => [
// 测试环境
'dev' => [
'driver' => 'daily',
'path' => root_path() . 'runtime/easywechat/easywechat.log',
'level' => 'debug',
'days' => 1
]
],
],
//OAuth 配置
'oauth' => [
'scopes' => ['snsapi_userinfo'],
],
];
}
public function classify()
{
$classify_model = new WechatClassify();
if (request()->isPost()) {
$data = input('post.');
$data['uid'] = UID;
if (isset($data['name_0'])) {
$classify_one_name = $data['name_0'];
foreach ($classify_one_name as $k => $v) {
$button = [];
$cur = $k + 1;
if (!isset($data['type_' . $cur])) { //二级菜单不存在
if (!$data['type_0'][$k]) {
return ['ret' => 0, 'msg' => '请将自定义菜单填写完整'];
}
$button = ['name' => $v, 'type' => $data['type_0'][$k], 'content' => $data['content_0'][$k]];
} else { //二级菜单存在
$button['name'] = $v;
foreach ($data['type_' . $cur] as $k1 => $v1) {
if (!$v1) {
return ['ret' => 0, 'msg' => '请将自定义菜单填写完整'];
} else {
$button['sub_button'][] = ['name' => $data['name_' . $cur][$k1], 'type' => $v1, 'content' => $data['content_' . $cur][$k1]];
}
}
}
$classify[] = $button;
}
$data['content'] = $classify;
} else {
$data['content'] = '';
}
$res = $classify_model->dataUpdate($data);
if (!$res) {
return sendErrorMessage();
}
return sendSuccessMessage();
} else {
$data = $classify_model->getOneData(['uid' => UID]);
View::assign('data', $data);
return View::fetch();
}
}
/**
* 发布菜单 2017-10-15
*/
public function classifypublish()
{
$classify_model = new WechatClassify();
$wechat_logic = new \app\base\logic\Wechat();
//自定义菜单格式化
$data = $classify_model->getOneData(['uid' => UID]);
$classify = [];
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'][] = $classify_model->buttonFormat($vv['name'], $vv['type'], $vv['content']);
}
} else { //二级菜单不存在
$button = $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']);
}
}
/**
* 删除菜单 2017-10-15
*/
public function classifydel()
{
$weixin_classify_model = new WechatClassify();
$wechat_logic = new \app\base\logic\Wechat();
$res = $wechat_logic->classifyDel();
if ($res['errcode'] == 0) {
return sendSuccessMessage([], '菜单删除成功');
} else {
return sendErrorMessage(4001, $res['errmsg']);
}
}
/**
* 设置菜单操作浮层
* @return string
*/
public function loadclassify()
{
$data = input('post.');
$data['keywords_id'] = 0;
$data['linkurl'] = '';
$data['appid'] = '';
$data['pagepath'] = '';
$data['url'] = '';
if ($data['type'] == 'click') {
$data['keywords_id'] = $data['content'];
} else if ($data['type'] == 'view') {
$data['linkurl'] = $data['content'];
} else if ($data['type'] == 'miniprogram') {
$data['content'] = explode(' ', $data['content']);
$data['appid'] = $data['content'][0];
$data['pagepath'] = $data['content'][1];
$data['url'] = $data['content'][2];
}
$reply_model = new WechatReply();
$keywordsList = $reply_model->getAllData(['trigger_type' => 1, 'uid' => UID]);
View::assign('data', $data);
View::assign('keywordsList', $keywordsList);
return View::fetch('loadclassify');
}
/**
* 菜单操作报存
* @return \think\response\Json
*/
public function classifysave()
{
$data = input('post.');
if ($data['type'] == 'click') {
$data['content'] = $data['keywords_id'];
} else if ($data['type'] == 'view') {
$data['content'] = $data['linkurl'];
} else if ($data['type'] == 'miniprogram') {
$data['content'] = $data['appid'] . ' ' . $data['pagepath'] . ' ' . $data['url'];
}
return sendSuccessMessage($data);
}
/**
* 图文素材列表
* @return mixed
*/
public function news()
{
$search = input('get.');
autoSearch(['keyword'], $search);
View::assign('search', $search);
$page = array_key_exists("page", $search) ? (string)$search['page'] : "1";
$where = [
'uid' => UID,
];
$news_model = new WechatNews();
$dataList = $news_model->getDataList($where, $page, '*', 'id desc');
View::assign('dataList', $dataList);
return View::fetch();
}
/**
* 添加图文素材
* @return array
*/
public function newsadd()
{
$news_model = new WechatNews();
if (request()->isPost()) {
$data = input('post.');
if (empty($data['title'])) {
return ['ret' => 0, 'msg' => '请至少添加一条完整图文消息'];
}
//数据信息
foreach ($data['title'] as $k => $v) {
if (!$v || !$data['image'][$k]) {
continue;
}
$data['content'][] = [
'title' => $v,
'description' => $data['description'][$k],
'image' => $data['image'][$k],
'url' => $data['url'][$k],
];
}
if (empty($data['content'])) {
return ['ret' => 0, 'msg' => '请至少添加一条完整图文消息1'];
}
$data['uid'] = UID;
$res = $news_model->dataUpdate($data);
if (!$res) {
return sendErrorMessage();
}
return sendSuccessMessage();
}
$id = input('param.id', 0);
$data = $news_model->getOneData(['id' => $id]);
View::assign('data', $data);
return View::fetch('newsadd');
}
/**
* 修改图文素材
* @return array
*/
public function newsupdate()
{
return $this->newsadd();
}
/**
* 同步图文素材
* @date 2022-12-01
*/
public function updatePlatformNews()
{
$news_model = new WechatNews();
$wechat_logic = new \app\base\logic\Wechat();
$oss_param = get_ali_oss_config();
$ali_config = $oss_param;
$oss_class = new Oss($ali_config);
$material_logic = new Material();
// 获取所有素材
$news_list = $material_logic->listMaterial('news');
$media_ids = $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['url'];
}
$content[] = [
'title' => $v1['title'],
'description' => $v1['digest'],
'image' => $picurl,
'url' => $v1['url'],
];
}
$data['content'] = $content;
$news_model->dataUpdate($data);
}
return sendSuccessMessage([], '同步成功');
}
/**
* 首关设置 2017-10-15
*/
public function event()
{
$reply_model = new WechatReply();
if (request()->isPost()) {
$param = input('post.');
$data = [
'id' => $param['id'],
'uid' => UID,
'trigger_type' => 2,
'matching_type' => 1,
'type' => $param['type'],
];
$app = Factory::officialAccount($this->easyWechatConfig);
if ($param['type'] == 'text') {
$data['content'] = [
'text' => $param['reply_text']
];
} else if ($param['type'] == 'image') {
$file = saveFileToLocal($param['image_url']);
$result = $app->media->uploadImage($file['local_file_url']);
platformLog($file['local_file_url'], $result, 'wechat_upload_image_uid_' . UID);
unlink($file['local_file_url']);
$data['content'] = [
'image_url' => $param['image_url'],
'media_id' => $result['media_id']
];
} else if ($param['type'] == 'voice') {
$file = saveFileToLocal($param['voice_url']);
$result = $app->media->uploadVoice($file['local_file_url']);
platformLog($file['local_file_url'], $result, 'wechat_upload_image_uid_' . UID);
unlink($file['local_file_url']);
$data['content'] = [
'voice_url' => $param['voice_url'],
'media_id' => $result['media_id']
];
} else if ($param['type'] == 'video') {
$file = saveFileToLocal($param['video_url']);
$result = $app->media->uploadVideo($file['local_file_url']);
platformLog($file['local_file_url'], $result, 'wechat_upload_image_uid_' . UID);
unlink($file['local_file_url']);
$data['content'] = [
'title' => $param['video_title'],
'description' => $param['video_description'],
'video_url' => $param['video_url'],
'media_id' => $result['media_id']
];
} else if ($param['type'] == 'music') {
$file = saveFileToLocal($param['thumb_url']);
$result = $app->media->uploadThumb($file['local_file_url']);
platformLog($file['local_file_url'], $result, 'wechat_upload_image_uid_' . UID);
unlink($file['local_file_url']);
$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'],
'media_id' => $result['thumb_media_id']
];
} else if ($param['type'] == 'news') {
$data['content'] = [
'news_id' => $param['news_id']
];
}
$res = $reply_model->dataUpdate($data);
if (!$res) {
return sendErrorMessage(4001, '操作失败');
}
return sendSuccessMessage([], '操作成功');
} else {
$id = input('param.id', 0);
$data = $reply_model->getOneData(['trigger_type' => 2]);
$news_model = new WechatNews();
$newsList = $news_model->getAllData(['uid' => UID]);
View::assign('data', $data);
View::assign('newsList', $newsList);
return View::fetch();
}
}
/**
* 回复设置
* @return mixed
*/
public function reply()
{
$search = input('get.');
autoSearch(['time', 'keyword', 'type'], $search);
$news_model = new WechatNews();
$news = $news_model->column('name', 'id');
$where = [
['uid', '=', UID],
// ['trigger_type', '=', 1]
];
$reply_model = new WechatReply();
if ($search['time']) {
$time = explode('-', $search['time']);
$where[] = ['create_time', 'between time', [$time[0], $time[1]]];
}
if ($search['keyword']) {
$where[] = ['name', 'like', '%' . $search['keyword'] . '%'];
}
if ($search['type']) {
$where[] = ['type', '=', $search['type']];
}
$dataList = $reply_model
->where($where)
->order('trigger_type desc')
->paginate([
'list_rows' => 20,
'page' => array_key_exists("page", $search) ? (string)$search['page'] : "1",
'query' => $search
], false)->each(function ($item, $key) use ($news) {
if ($item['type'] == 'news' && !empty($news[$item['content']['news_id']])) {
$item['news_name'] = $news[$item['content']['news_id']];
} else {
$item['news_name'] = '图文已被删除';
}
return $item;
});
View::assign('search', $search);
View::assign('dataList', $dataList);
return View::fetch();
}
//关键词回复设置添加
public function replyadd()
{
$reply_model = new WechatReply();
if (request()->isPost()) {
$param = input('post.');
$data = [
'id' => $param['id'],
'uid' => UID,
// 'name' => $param['name'],
'trigger_type' => $param['trigger_type'],
// 'matching_type' => $param['matching_type'],
'type' => $param['type']
];
if ($param['trigger_type'] == 1) {
$data['name'] = $param['name'];
$data['matching_type'] = $param['matching_type'];
}
if ($param['trigger_type'] == 2 || $param['trigger_type'] == 3) {
$where = [
['uid', '=', UID],
['trigger_type', '=', $param['trigger_type']],
];
if($param['id']){
$where[] = ['id', '<>', $param['id']];
}
$number = $reply_model->getNumber($where);
if ($number) {
return sendErrorMessage(1, '同类型事件只能有1个');
}
}
$app = Factory::officialAccount($this->easyWechatConfig);
if ($param['type'] == 'text') {
if (!$param['reply_text']) {
return sendErrorMessage(1, '请填写文本信息');
}
$data['content'] = [
'text' => $param['reply_text']
];
} else if ($param['type'] == 'image') {
if (!$param['image_url']) {
return sendErrorMessage(1, '请上传图片');
}
$file = saveFileToLocal($param['image_url']);
$result = $app->media->uploadImage($file['local_file_url']);
platformLog($file['local_file_url'], $result, 'wechat_upload_image_uid_' . UID);
unlink($file['local_file_url']);
$data['content'] = [
'image_url' => $param['image_url'],
'media_id' => $result['media_id']
];
} else if ($param['type'] == 'voice') {
if (!$param['voice_url']) {
return sendErrorMessage(1, '请上传语音文件');
}
$file = saveFileToLocal($param['voice_url']);
$result = $app->media->uploadVoice($file['local_file_url']);
platformLog($file['local_file_url'], $result, 'wechat_upload_image_uid_' . UID);
unlink($file['local_file_url']);
$data['content'] = [
'voice_url' => $param['voice_url'],
'media_id' => $result['media_id']
];
} else if ($param['type'] == 'video') {
if (!$param['video_title']) {
return sendErrorMessage(1, '请填写视频标题');
}
if (!$param['video_url']) {
return sendErrorMessage(1, '请上传视频文件');
}
if (!$param['video_description']) {
return sendErrorMessage(1, '请填写视频描述');
}
$file = saveFileToLocal($param['video_url']);
$result = $app->media->uploadVideo($file['local_file_url']);
platformLog($file['local_file_url'], $result, 'wechat_upload_image_uid_' . UID);
unlink($file['local_file_url']);
$data['content'] = [
'title' => $param['video_title'],
'description' => $param['video_description'],
'video_url' => $param['video_url'],
'media_id' => $result['media_id']
];
} else if ($param['type'] == 'music') {
if (!$param['music_title']) {
return sendErrorMessage(1, '请填写音乐标题');
}
if (!$param['thumb_url']) {
return sendErrorMessage(1, '请上传音乐封面');
}
if (!$param['music_url']) {
return sendErrorMessage(1, '请上传音乐文件');
}
if (!$param['music_description']) {
return sendErrorMessage(1, '请填写音乐描述');
}
$file = saveFileToLocal($param['thumb_url']);
$result = $app->media->uploadThumb($file['local_file_url']);
platformLog($file['local_file_url'], $result, 'wechat_upload_image_uid_' . UID);
unlink($file['local_file_url']);
$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'],
'media_id' => $result['thumb_media_id']
];
} else if ($param['type'] == 'news') {
if (!$param['news_id']) {
return sendErrorMessage(1, '请选择图文信息');
}
$data['content'] = [
'news_id' => $param['news_id']
];
}
// dump($data);exit();
$res = $reply_model->dataUpdate($data);
if (!$res) {
return sendErrorMessage(4001, '操作失败');
}
return sendSuccessMessage([], '操作成功');
} else {
$id = input('param.id', 0);
$data = $reply_model->getOneData(['id' => $id]);
$news_model = new WechatNews();
$newsList = $news_model->getAllData(['uid' => UID]);
View::assign('data', $data);
View::assign('newsList', $newsList);
return View::fetch('replyadd');
}
}
//修改关键词
public function replyupdate()
{
return $this->replyadd();
}
}

@ -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,54 @@
<?php
namespace app\base\controller\wechat\api;
use app\BaseController;
use think\App;
use think\facade\Request;
class Base extends BaseController
{
protected $easyWechatWeixinConfig; //easywechat微信公众号配置文件
protected $wechatConfig; //公众平台配置
/**
* 公众平台配置
* @date 2020-07-23
*/
public function __construct(App $app)
{
parent::__construct($app);
$weixin_param = get_weixin_config();
$this->wechatConfig = $weixin_param;
$this->easyWechatWeixinConfig = [
'app_id' => $weixin_param['app_id'],
'secret' => $weixin_param['app_secret'],
'token' => $weixin_param['token'],
'response_type' => 'array',
//日志 配置
'log' => [
'default' => 'dev', // 默认使用的 channel生产环境可以改为下面的 prod
'channels' => [
// 测试环境
'dev' => [
'driver' => 'daily',
'path' => root_path() . 'runtime/easywechat/easywechat.log',
'level' => 'debug',
'days' => 1
]
],
],
//OAuth 配置
'oauth' => [
'scopes' => ['snsapi_userinfo'],
// 'callback' => '/examples/oauth_callback.php',
],
];
}
}

@ -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,50 @@
<?php
namespace app\base\controller\wechat\api;
use think\App;
class Media extends Base
{
/**
* 将前台录音文件的MediaId即serverId文件下载到本地并上传至OSS
* @param array $param
* @param string $param ['media_id'] 录音文件媒体ID
* @date 2022-08-14
*/
public function getRecordMediaToOss()
{
$param = input('post.');
$media_logic = new \app\base\service\weixin\Media();
// 将前台录音文件的MediaId即serverId文件下载到本地转为mp3并上传至OSS
$result = $media_logic->getRecordMediaToOss($param['media_id']);
return sendSuccessMessage([
'oss_url' => $result
]);
}
/**
* 将前台图片文件的MediaId即serverId文件下载到本地并上传至OSS
* @param array $param
* @param string $param ['media_id'] 图片媒体ID
* @param string $param ['is_original_name'] 是否保留原文件名 0--不保留 1--保留
* @date 2022-08-15
*/
public function getImageMediaToOss()
{
$param = input('post.');
$media_logic = new \app\base\service\weixin\Media();
// 将前台图片文件的MediaId即serverId文件下载到本地并上传至OSS
$result = $media_logic->getImageMediaToOss($param['media_id'],$param['is_original_name']);
return sendSuccessMessage([
'oss_url' => $result
]);
}
}

@ -0,0 +1,43 @@
<?php
namespace app\base\controller\wechat\api;
use app\base\model\wechat\WechatUser;
use app\BaseController;
use think\App;
class Test extends BaseController
{
/**
* 微信公众号 通过openid获取TOKEN一般用于测试openid或access_token过期后重新获取
* @date 2020-11-13
*/
public function getTokenByOpenid()
{
$openid = input('post.openid');
$wechat_user_model = new WechatUser();
$jwt_class = new \jwt\Jwt();
$wechat_user = $wechat_user_model->getOneData([
'openid' => $openid
]);
$info = [
'uid' => UID,
'openid' => $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,30 @@
<?php
namespace app\base\controller\wechat\platform;
use app\BaseController;
use think\App;
use think\facade\Request;
class Base extends BaseController
{
protected $weixinConfig; //公众平台配置
/**
* 公众平台配置
* @date 2020-07-23
*/
public function __construct(App $app)
{
parent::__construct($app);
// 不基于JWTuid为推送时链接自带传参
$uid = input('param.uid');
defined('UID') || define('UID', $uid);
$weixin_param = get_weixin_config();
$this->weixinConfig = $weixin_param;
}
}

@ -0,0 +1,388 @@
<?php
namespace app\base\controller\wechat\platform;
use app\base\model\wechat\WechatNews;
use app\base\model\wechat\WechatReply;
use app\base\model\wechat\WechatUser;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\Image;
use EasyWeChat\Kernel\Messages\News;
use EasyWeChat\Kernel\Messages\NewsItem;
use EasyWeChat\Kernel\Messages\Raw;
use EasyWeChat\Kernel\Messages\Text;
use EasyWeChat\Kernel\Messages\Transfer;
use EasyWeChat\Kernel\Messages\Video;
use EasyWeChat\Kernel\Messages\Voice;
use think\App;
class Notice extends Base
{
/**
* 公众平台和服务器对接
* @date 2020-07-23
*/
public function serveConfig()
{
$weixin_param = get_weixin_config();
$notice_class = new \tencent\wechat\weixin\Notice($weixin_param);
$weixin_config = $notice_class->getWeixinConfig();
$app = Factory::officialAccount($weixin_config);
$app->server->push(function ($message) {
platformLog('', $message, 'wechat_get_user_message_' . UID);
$result = Notice::messageResponse($message);
return $result;
});
$response = $app->server->serve();
// 将响应输出
$response->send();
exit;
}
/**
* 接收普通消息并处理
* @param array $message 普通微信用户向公众账号发消息时,微信服务器请求的服务器携带参数 xml已转array
* @date 2020-07-23
*/
protected function messageResponse($message = [])
{
switch ($message['MsgType']) {
case 'event':
if ($message['Event'] == 'subscribe') { //关注事件
return $this->replySubscribe($message); //$message['EventKey']--用户扫描带场景值二维码,未关注公众号并关注公众号
} else if ($message['Event'] == 'unsubscribe') { //取消关注事件
return $this->replyUnsubscribe($message);
} else if ($message['Event'] == 'SCAN') { //用户扫描带场景值二维码,已关注公众号进入公众号
return '';
} else if ($message['Event'] == 'LOCATION') { //上报地理位置事件
return '';
} else if ($message['Event'] == 'CLICK') { //自定义菜单事件-点击菜单拉取消息时的事件推送
return $this->replyClick($message);
} else if ($message['Event'] == 'VIEW') { //自定义菜单事件-点击菜单跳转链接时的事件推送
return '';
}
return '收到事件消息';
break;
case 'text':
return $this->replyText($message);
break;
case 'image':
return $this->replyDefaultMessage($message);
break;
case 'voice':
return $this->replyDefaultMessage($message);
// return '收到语音消息';
break;
case 'video':
return $this->replyDefaultMessage($message);
// return '收到视频消息';
break;
case 'shortvideo':
return $this->replyDefaultMessage($message);
// return '收到小视频消息';
break;
case 'location':
return $this->replyDefaultMessage($message);
// return '收到地理位置消息';
break;
case 'link':
return $this->replyDefaultMessage($message);
// return '收到链接消息';
break;
case 'file':
return $this->replyDefaultMessage($message);
// return '收到文件消息';
default:
return $this->replyDefaultMessage($message);
// return '收到其它消息';
break;
}
}
/**
* 被动回复用户消息 - 默认消息
* @param array $message 普通微信用户向公众账号发消息时,微信服务器请求的服务器携带参数 xml已转array
* @param string $message ['ToUserName'] 开发者微信号
* @param string $message ['FromUserName'] 发送方帐号一个OpenID
* @param int $message ['CreateTime'] 消息创建时间 (整型)
* @param string $message ['MsgType'] 消息类型text
* @param string $message ['Content'] 文本消息内容
* @param string $message ['MsgId'] 消息id64位整型
* @date 2022-12-01
*/
protected function replyDefaultMessage($message)
{
$openid = $message['FromUserName'];
// 获取关键字回复内容
$wechat_reply_model = new WechatReply();
$wechat_reply_data = $wechat_reply_model->getOneData([
['uid', '=', UID],
['trigger_type', '=', 3],
]);
$reply = $this->getReplyDataByKeyword($wechat_reply_data, $openid);
return $reply;
}
/**
* 被动回复用户消息 - 文本消息
* @param array $message 普通微信用户向公众账号发消息时,微信服务器请求的服务器携带参数 xml已转array
* @param string $message ['ToUserName'] 开发者微信号
* @param string $message ['FromUserName'] 发送方帐号一个OpenID
* @param int $message ['CreateTime'] 消息创建时间 (整型)
* @param string $message ['MsgType'] 消息类型text
* @param string $message ['Content'] 文本消息内容
* @param string $message ['MsgId'] 消息id64位整型
* @date 2020-07-27
*/
protected function replyText($message)
{
$openid = $message['FromUserName'];
// 获取关键字回复内容
$wechat_reply_model = new WechatReply();
$wechat_reply_data = $wechat_reply_model->getWechatReply($message['Content']);
// 没有找到关键词采用默认回复
if (empty($wechat_reply_data)) {
$wechat_reply_data = $wechat_reply_model->getOneData([
['uid', '=', UID],
['trigger_type', '=', 3],
]);
}
$reply = $this->getReplyDataByKeyword($wechat_reply_data, $openid);
return $reply;
}
/**
* 回复关注事件
* @param array $message 普通微信用户向公众账号发消息时,微信服务器请求的服务器携带参数 xml已转array
* @param string $message ['ToUserName'] 开发者微信号
* @param string $message ['FromUserName'] 发送方帐号一个OpenID
* @param int $message ['CreateTime'] 消息创建时间 (整型)
* @param string $message ['MsgType'] 消息类型event
* @param string $message ['Event'] 事件类型 subscribe--订阅
* @param string $message ['EventKey'] 事件KEY值qrscene_为前缀后面为二维码的参数值 该值在用户扫描带场景值二维码时才会返回
* @param string $message ['Ticket'] 二维码的ticket可用来换取二维码图片 该值在用户扫描带场景值二维码时才会返回
* @date 2020-07-27
*/
public function replySubscribe($message)
{
$weixin_param = get_weixin_config();
$wechat_user_model = new WechatUser(['uid' => UID]);
$user_class = new \tencent\wechat\weixin\User($weixin_param);
$event_key = empty($message['EventKey']) ? '' : $message['EventKey'];
$key = substr($event_key, 8); //去掉前面qrscene_前缀之后的二维码的场景值
$openid = $message['FromUserName'];
//微信接口获取用户信息
$result = $user_class->getUserInfo($openid);
platformLog($message, $result, 'wechat_get_user_info_by_openid_' . UID);
//更新用户信息
$res = $wechat_user_model->updateUser($result);
//获取关键字回复内容
$wechat_reply_model = new WechatReply();
$wechat_reply_data = $wechat_reply_model->getOneData([
['trigger_type', '=', 2]
]);
return $this->getReplyDataByKeyword($wechat_reply_data, $openid);
}
/**
* 回复取消关注事件
* @param array $message 普通微信用户向公众账号发消息时,微信服务器请求的服务器携带参数 xml已转array
* @param string $message ['ToUserName'] 开发者微信号
* @param string $message ['FromUserName'] 发送方帐号一个OpenID
* @param int $message ['CreateTime'] 消息创建时间 (整型)
* @param string $message ['MsgType'] 消息类型event
* @param string $message ['Event'] 事件类型 unsubscribe--取消订阅
* @date 2020-07-27
*/
protected function replyUnsubscribe($message)
{
$openid = $message['FromUserName'];
$wechat_user_model = new WechatUser();
//更新微信用户关注状态
$user_update_data = [
'openid' => $openid,
'subscribe' => 0,
'subscribe_time' => '',
];
//更新用户信息
$wechat_user_model->updateUser($user_update_data);
return '';
}
/**
* 回复关注事件
* @param array $message 普通微信用户向公众账号发消息时,微信服务器请求的服务器携带参数 xml已转array
* @param string $message ['ToUserName'] 开发者微信号
* @param string $message ['FromUserName'] 发送方帐号一个OpenID
* @param int $message ['CreateTime'] 消息创建时间 (整型)
* @param string $message ['MsgType'] 消息类型event
* @param string $message ['Event'] 事件类型 CLICK--点击菜单拉取消息
* @param string $message ['EventKey'] 事件KEY值与自定义菜单接口中KEY值对应
* @date 2020-07-29
*/
protected function replyClick($message)
{
$openid = $message['FromUserName'];
//获取关键字回复内容
$wechat_reply_model = new WechatReply();
$wechat_reply_data = $wechat_reply_model->getOneData([
['id', '=', $message['EventKey']]
]);
return $this->getReplyDataByKeyword($wechat_reply_data, $openid);
}
/**
* 被动回复 通过回复内容组装微信需要的格式
* @param string $wechat_kewords 需要回复的消息
* @param string $openid 用户OPENID
* @date 2020-07-27
*/
protected function getReplyDataByKeyword($wechat_reply, $openid)
{
if (empty($wechat_reply)) {
return '';
}
switch ($wechat_reply['type']) {
case 'text':
return new Text($wechat_reply['content']['text']);
break;
case 'image':
// 图片太大时5秒内执行不完 可以上传图片的时候传为永久素材获取media_id 此处仅使用
// $file = saveFileToLocal($wechat_reply['content']['image_url']);
// $result = $app->media->uploadImage($file['local_file']);
// platformLog($file['local_file'], $result, 'wechat_upload_image_uid_' . UID);
// unlink($file['local_file']);
// if (!empty($wechat_reply['content']['media_id'])) {
// return new Image($result['media_id']);
// } else {
// return '';
// }
return new Image($wechat_reply['content']['media_id']);
break;
case 'voice':
// 语音太大时5秒内执行不完 可以上传语音的时候传为永久素材获取media_id 此处仅使用
// $file = saveFileToLocal($wechat_reply['content']['voice_url']);
// $result = $app->media->uploadVoice($file['local_file']);
// platformLog($file['local_file'], $result, 'wechat_upload_voice_uid_' . UID);
// unlink($file['local_file']);
// if (!empty($result['media_id'])) {
// return new Voice($result['media_id']);
// } else {
// return '';
// }
return new Voice($wechat_reply['content']['media_id']);
break;
case 'video':
// 视频太大时5秒内执行不完 可以上传视频的时候传为永久素材获取media_id 此处仅使用
// $file = saveFileToLocal($wechat_reply['content']['video_url']);
// $result = $app->media->uploadVideo($file['local_file']);
// platformLog($file['local_file'], $result, 'wechat_upload_video_uid_' . UID);
// unlink($file['local_file']);
// if (!empty($result['media_id'])) {
// return new Video($result['media_id'], [
// 'title' => $wechat_reply['content']['title'],
// 'description' => $wechat_reply['content']['description']
// ]);
// } else {
// return '';
// }
return new Video($wechat_reply['content']['media_id'], [
'title' => $wechat_reply['content']['title'],
'description' => $wechat_reply['content']['description']
]);
break;
case 'music':
// 缩略图太大时5秒内执行不完 可以上传时候传为永久素材获取media_id 此处仅使用
// $file = saveFileToLocal($wechat_reply['content']['thumb_url']);
// $result = $app->media->uploadThumb($file['local_file']);
// platformLog($file['local_file'], $result, 'wechat_thumb_image_uid_' . UID);
// unlink($file['local_file']);
// if (!empty($result['thumb_media_id'])) {
// $reply_array = [
// 'ToUserName' => $openid,
// 'FromUserName' => $this->wechatConfig['weixin_id'],
// 'CreateTime' => time(),
// 'MsgType' => 'music',
// 'Music' => [
// 'Title' => $wechat_reply['content']['title'],
// 'Description' => $wechat_reply['content']['description'],
// 'MusicUrl' => $wechat_reply['content']['music_url'],
// 'HQMusicUrl' => $wechat_reply['content']['hq_music_url'],
// 'ThumbMediaId' => $result['thumb_media_id'], //貌似不管用 搜了几篇博客 貌似也是说微信有BUG
// ],
// ];
// $res = dataToXml($reply_array);
// return new Raw($res);
// } else {
// return '';
// }
$reply_array = [
'ToUserName' => $openid,
'FromUserName' => $this->weixinConfig['weixin_id'],
'CreateTime' => time(),
'MsgType' => 'music',
'Music' => [
'Title' => $wechat_reply['content']['title'],
'Description' => $wechat_reply['content']['description'],
'MusicUrl' => $wechat_reply['content']['music_url'],
'HQMusicUrl' => $wechat_reply['content']['hq_music_url'],
'ThumbMediaId' => $wechat_reply['content']['media_id'], //貌似不管用 搜了几篇博客 貌似也是说微信有BUG
],
];
$res = dataToXml($reply_array);
return new Raw($res);
break;
case 'news':
$wechat_news_model = new WechatNews();
$wechat_news_id = $wechat_reply['content']['news_id'];
$news_content = $wechat_news_model->getNews($wechat_news_id, $this->weixinConfig['type'], $openid);
foreach ($news_content as $k => $v) {
$items[] = new NewsItem($v);
}
return new News($items);
break;
case 'transfer':
if (!empty($wechat_reply['content']['account'])) {
return new Transfer($wechat_reply['content']['account']);
} else {
return new Transfer();
}
break;
default:
return '';
break;
}
}
}

@ -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);
}
}

@ -0,0 +1,183 @@
<?php
namespace app\base\logic;
class District extends Base
{
/**
* 获取树状三级行政区划
* @date 2022-08-11
*/
public function listDistrictTree(){
$district_model = new \app\base\model\district\District();
// 查询有效三级行政区划
$district_list = $district_model -> listDistrict();
// 更改为树状数组
$district_list = listToTree($district_list);
return $district_list;
}
/**
* 更新全部省市区三级行政区划
* @date 2021-02-04
*/
function createDistrict()
{
exit; //一般不会更新,需要更新时注释掉该行代码 需要把三个表备份一下,截断后重新写入新数据
$map_param = get_tencent_map_config(2);
$district_model = new \app\base\model\district\District();
$tencent_map_class = new \tencent\map\District($map_param);
$res = $tencent_map_class->getDistrict();
$data = $res['result']; //全部省市区三级行政区划
//更新三级行政区划
$city_id = 100;//二级行政区域ID由101起始
$area_id = 1000;//三级行政区域ID由1001起始
foreach ($data[0] as $k1 => $v1) {
$province[] = [ //省级数据
'id' => $k1 + 1,
'level' => 1,
'pid' => '',
'adcode' => $v1['id'],
'brief_name' => $v1['name'],
'name' => $v1['fullname'],
'lat' => $v1['location']['lat'],
'lng' => $v1['location']['lng'],
'pinyin' => implode(' ', $v1['pinyin']),
'create_time' => time(),
'update_time' => time()
];
$city_data = array_slice($data[1], $v1['cidx'][0], $v1['cidx'][1] - $v1['cidx'][0] + 1); //截取对应的二级行政区域数据
//判断该省是否为直辖市、香港、澳门
$is_directly_city = true; //一级是否是直辖市、香港、澳门,即省市区只有二级行政区域没有三级行政区域数据(二级延用一级,三级延用二级)
$has_directly_area = false; //一级是否含有直辖县第3、4位为90的为省直辖县二级多一个"省直辖县级行政区划",该地区所有直辖县移至该二级三级)
foreach ($city_data as $k => $v) {
if (!empty($v['cidx'])) {
$is_directly_city = false;
}
if (substr($v['id'], 2, 2) == '90') {
$has_directly_area = true;
}
}
if ($is_directly_city) { //针对于直辖市、香港、澳门
$city[] = [
'id' => ++$city_id,
'level' => 2,
'pid' => $k1 + 1,
'adcode' => $v1['id'],
'brief_name' => $v1['name'],
'name' => $v1['fullname'],
'lat' => $v1['location']['lat'],
'lng' => $v1['location']['lng'],
'pinyin' => implode(' ', $v1['pinyin']),
'create_time' => time(),
'update_time' => time(),
];
foreach ($city_data as $k2 => $v2) {
$area[] = [
'id' => ++$area_id,
'level' => 3,
'pid' => $city_id,
'adcode' => $v2['id'],
'brief_name' => $v2['name'],
'name' => $v2['fullname'],
'lat' => $v2['location']['lat'],
'lng' => $v2['location']['lng'],
'pinyin' => implode(' ', $v2['pinyin']),
'create_time' => time(),
'update_time' => time(),
];
}
} else {
$directly_area_id = 0;
foreach ($city_data as $k2 => $v2) {
if (substr($v2['id'], 2, 2) == '90') {
if (!$directly_area_id) {
$city[] = [
'id' => ++$city_id,
'level' => 2,
'pid' => $k1 + 1,
'adcode' => '',
'brief_name' => '省直辖县',
'name' => '省直辖县级行政区划',
'lat' => '',
'lng' => '',
'pinyin' => 'sheng zhi xia xian',
'create_time' => time(),
'update_time' => time(),
];
$directly_area_id = $city_id;
}
$area[] = [
'id' => ++$area_id,
'level' => 3,
'pid' => $directly_area_id,
'adcode' => $v2['id'],
'brief_name' => $v2['name'],
'name' => $v2['fullname'],
'lat' => $v2['location']['lat'],
'lng' => $v2['location']['lng'],
'pinyin' => implode(' ', $v2['pinyin']),
'create_time' => time(),
'update_time' => time(),
];
} else {
$city[] = [
'id' => ++$city_id,
'level' => 2,
'pid' => $k1 + 1,
'adcode' => $v2['id'],
'brief_name' => $v2['name'],
'name' => $v2['fullname'],
'lat' => $v2['location']['lat'],
'lng' => $v2['location']['lng'],
'pinyin' => implode(' ', $v2['pinyin']),
'create_time' => time(),
'update_time' => time(),
];
$area_data = array_slice($data[2], $v2['cidx'][0], $v2['cidx'][1] - $v2['cidx'][0] + 1); //截取对应的三级行政区域数据
foreach ($area_data as $k3 => $v3) {
$area[] = [
'id' => ++$area_id,
'level' => 3,
'pid' => $city_id,
'adcode' => $v3['id'],
'brief_name' => '',
'name' => $v3['fullname'],
'lat' => $v3['location']['lat'],
'lng' => $v3['location']['lng'],
'pinyin' => '',
'create_time' => time(),
'update_time' => time(),
];
}
}
}
}
}
//合并省市区数据
$district_data = array_merge($province, $city, $area);
$district_model->insertAll($district_data);
echo 'success';
}
}

@ -0,0 +1,102 @@
<?php
namespace app\base\logic;
class Freight extends Base
{
/**
* 获取商品的运费模板并进行计算
* @param int $freight_id 运费模板ID
* @param string $weight 单件商品重量
* @param int $number 商品数量
* @param string $price 商品价格
* @param int $province_id 配送地址省ID
* @param int $city_id 配送地址城市ID
* @param int $area_id 配送地址区ID
* @date 2022-11-22
*/
public function getFreight($freight_id = 0, $weight = '', $number = 0, $price = '', $province_id = 0, $city_id = 0, $area_id = 0)
{
$freight_model = new \app\base\model\freight\Freight();
if (empty($freight_id)) {
return 0;
}
// 获取运费
$freight = $freight_model->getOneData([
['id', '=', $freight_id]
]);
if (empty($freight)) {
return 0;
}
// 判断是否该商品免运费是否满足满X元包邮
if ($price * $number >= $freight['free_money']) {
return 0;
}
$start_standard = 0; //首件或首重
$start_fee = 0;//首费
$add_standard = 0;//续件或续重
$add_fee = 0;//续费
$standard = 0; //进行判断的标准
#TODO 可以将2种计费方式的字段统一到一个字段 运费规则是否符合标准逻辑
if ($freight['type'] == 1) { //计费方式 1--按件计费 2--按重计费
$start_standard = $freight['first_number'];
$start_fee = $freight['first_number_money'];
$add_standard = $freight['second_number'];
$add_fee = $freight['second_number_money'];
$standard = $number;
} else if ($freight['type'] == 2) {
$start_standard = $freight['first_weight'];
$start_fee = $freight['first_weight_money'];
$add_standard = $freight['second_weight'];
$add_fee = $freight['second_weight_money'];
$standard = $weight * $number;
}
if (!empty($freight['fee_conf'])) { //运费模板中运费信息对象,包含默认运费和指定地区运费
foreach ($freight['fee_conf'] as $key => $value) {
if ((!empty($province_id) && array_key_exists($province_id, $value['province_list'])) &&
(!empty($city_id) && array_key_exists($city_id, $value['city_list'])) &&
(!empty($area_id) && array_key_exists($area_id, $value['area_list']))
) {
$start_standard = $value['start_standard'];
$start_fee = $value['start_fee'];
$add_standard = $value['add_standard'];
$add_fee = $value['add_fee'];
break;
}
}
}
// 计算并返回金额
return $this->computedFreight($standard, $start_standard, $start_fee, $add_standard, $add_fee);
}
/**
* 计算并返回金额
* @param int $standard 进行判断的标准
* @param int $start_standard 首个 标准
* @param int $start_fee 首个 收费
* @param int $add_standard 续 标准
* @param int $add_fee 续 收费
* @date 2021-03-01
*/
public function computedFreight($standard = 0, $start_standard = 0, $start_fee = 0, $add_standard = 0, $add_fee = 0)
{
//小于等于首(件/重),运费=取首(件/重)费;以此类推。
if ($standard <= $start_standard) {
return $start_fee;
}
//超出首(件/重)后,超出部分小于等于续(件/重),运费=首重+续费,
return $start_fee + ceil(($standard - $start_standard) / $add_standard) * $add_fee;
}
}

@ -0,0 +1,191 @@
<?php
namespace app\base\logic;
use app\base\model\app\AppAppleUser;
use app\base\model\app\AppQqUser;
use app\base\model\app\AppSinaweiboUser;
use app\base\model\app\AppUser;
use app\base\model\app\AppWeixinUser;
use app\base\model\mpalipay\MpalipayUser;
use app\base\model\mpweixin\MpweixinUser;
use app\base\model\user\UserInfo;
use app\base\model\wechat\WechatUser;
use app\distribution\logic\Distribution;
use app\project\model\ProjectConfigUser;
class User extends Base
{
/**
* 用户登录并返回user_id
* @param string $mobile_phone 手机号
* @param array $info 其他用户信息
* @param string $last_user_id 上级USER_ID 用于绑定分销关系
* @param string $third_type APP用户端三方授权登录类型
* @param string $third_id APP用户端三方授权登录用户表用户ID
* @date 2021-02-25
*/
public function login($mobile_phone, $info, $last_user_id = '', $third_type = '', $third_id = '')
{
$config_user_model = new ProjectConfigUser();
$user_model = new \app\base\model\user\User();
$info_model = new UserInfo();
$distribution_logic = new Distribution();
// $user = $user_model->getUserByMobliePhone($mobile_phone);
$data = [
'uid' => $this->mid,
'user_agent' => $this->userAgent,
'status' => 1,
'mobile_phone' => $mobile_phone,
'is_bind_mobile' => 1,
];
//根据不同平台 生成平台用户信息及实例化相关平台模型
switch ($this->userAgent) {
case 'app': //APP
$data['app_id'] = $info['app_user_id'];
$data['app_device_id'] = $info['device_id'];
$data['is_bind_app'] = 1;
$platform_user_model = new AppUser();
$uni_where = [
['uid', '=', $this->mid],
['device_id', '=', $info['device_id']]
];
break;
case 'mp_weixin': //微信小程序
$data['mpweixin_id'] = $info['mpweixin_user_id'];
$data['mpweixin_openid'] = $info['openid'];
$data['is_bind_mpweixin'] = 1;
$platform_user_model = new MpweixinUser();
$uni_where = [
['uid', '=', $this->mid],
['openid', '=', $info['openid']]
];
break;
case 'weixin': //公众号
$data['wechat_id'] = $info['wechat_user_id'];
$data['wechat_openid'] = $info['openid'];
$data['is_bind_wechat'] = 1;
$platform_user_model = new WechatUser();
$uni_where = [
['uid', '=', $this->mid],
['openid', '=', $info['openid']]
];
break;
case 'mp_alipay': //支付宝小程序
$data['mpalipay_id'] = $info['mpalipay_user_id'];
$data['mpalipay_openid'] = $info['openid'];
$data['is_bind_mpalipay'] = 1;
$platform_user_model = new MpalipayUser();
$uni_where = [
['uid', '=', $this->mid],
['openid', '=', $info['openid']]
];
}
// 更新用户
$res = $user_model->updateUser($data);
$user_id = $res['user_id'];
$type = $res['type']; //1--注册新用户 2--之前注册过
if (!$user_id) {
return sendErrorArray(3001, '更新用户失败');
}
//更新平台用户信息
if (!empty($platform_user_model)) {
$res = $platform_user_model->dataUpdate(['user_id' => $user_id], $uni_where);
if (!$res) {
return sendErrorArray(3002, '更新平台用户失败');
}
}
if ($type == 1) {
// 获取默认头像和昵称
$config = $config_user_model->getDefaultInfo();
if (empty($config)) { //没有设置默认头像的话做如下定义
#TODO 是否要随机头像
$config['head_img_default'] = '';
$config['nick_name_default'] = '匿名';
}
// 新增用户info
$info_data = [
'uid' => UID,
'user_agent' => USER_AGENT,
'user_id' => $user_id,
'head_img' => $config['head_img_default'],
'nick_name' => $config['nick_name_default'],
];
$res = $info_model->dataUpdate($info_data);
if (!$res) {
return sendErrorArray(3002, '新增用户信息失败');
}
// 加入统计系统(新增用户)
$statistics_class = new \jucheng\tongji\Statistics();
$result = $statistics_class -> updateUserNumber(1);
//建立三级分销关系
$distribution_logic->buildRelation($user_id, $last_user_id);
}
#TODO 是否被其他用户端绑定 如果被绑定需要如何操作需要和产品确认
//有三方授权的情况更新三方授权仅限APP用户端有三方授权登录
if ($info['user_agent'] == 'app' && !empty($third_type)) {
if ($third_type == 'weixin') {
$third_platform_user_model = new AppWeixinUser();
} else if ($third_type == 'qq') {
$third_platform_user_model = new AppQqUser();
} else if ($third_type == 'sinaweibo') {
$third_platform_user_model = new AppSinaweiboUser();
} else if ($third_type == 'apple') {
$third_platform_user_model = new AppAppleUser();
}
$res = $third_platform_user_model->dataUpdate([
'id' => $third_id,
'user_id' => $user_id
]);
if (!$res) {
return sendErrorMessage(4001, '更新三方授权失败');
}
}
return sendSuccessArray(['user_id' => $user_id]);
}
/**
* 校验用户密码
* @param string $mobile_phone 手机号
* @param string $password 密码
* @date 2021-02-25
*/
public function checkPassword($mobile_phone, $password)
{
$user_model = new \app\base\model\user\User();
$user = $user_model->getUserByMobliePhone($mobile_phone);
if (empty($user)) {
return sendErrorArray(3001, '用户不存在');
}
if (empty($user['password'])) {
return sendErrorArray(3002, '未设置密码,无法登录');
}
if (md5WithKey($password) !== $user['password']) {
return sendErrorArray(3003, '密码有误');
}
return sendSuccessArray(['user_id' => $user['id']]);
}
}

@ -0,0 +1,85 @@
<?php
namespace app\base\logic;
use EasyWeChat\Factory;
class Wechat extends Base
{
protected $easyWechatConfig; //easywechat微信配置文件
protected $wechatConfig; //公众平台配置
public function __construct($data = [])
{
parent::__construct($data);
$weixin_param = get_weixin_config();
$this->wechatConfig = $weixin_param;
$this->easyWechatConfig = [
'app_id' => $weixin_param['app_id'],
'secret' => $weixin_param['app_secret'],
'token' => $weixin_param['token'],
'response_type' => 'array',
//日志 配置
'log' => [
'default' => 'dev', // 默认使用的 channel生产环境可以改为下面的 prod
'channels' => [
// 测试环境
'dev' => [
'driver' => 'daily',
'path' => root_path() . 'runtime/easywechat/easywechat.log',
'level' => 'debug',
'days' => 1
]
],
],
//OAuth 配置
'oauth' => [
'scopes' => ['snsapi_userinfo'],
// 'callback' => '/examples/oauth_callback.php',
],
];
}
/**
* 发布菜单
* @param array $classify 要发布的菜单
* @date 2020-10-21
*/
public function classifyPublish($classify)
{
$app = Factory::officialAccount($this->easyWechatConfig);
return $app->menu->create($classify);
}
/**
* 删除菜单
* @date 2020-10-21
*/
public function classifyDel()
{
$app = Factory::officialAccount($this->easyWechatConfig);
return $app->menu->delete();
}
/**
* 素材管理--获取永久素材
* @param string $media_id 微信返回媒体标识
* @param string $file_formats 文件格式 一般有jpg,gif,png,jpeg,amr,mp3,mp4
* @param string $material_type 媒体文件类型 image--图片 voice--语音2M video--视频 thumb--缩略图
* @date 2020-10-10
*/
function getPermanentMaterial($media_id)
{
$app = Factory::officialAccount($this->easyWechatConfig);
$resource = $app->material->get($media_id);
return $resource;
}
}

@ -0,0 +1,249 @@
<?php
namespace app\base\logic\app;
use app\base\logic\Base;
use app\base\model\app\AppAppleUser;
use app\base\model\app\AppQqUser;
use app\base\model\app\AppSinaweiboUser;
use app\base\model\app\AppWeixinUser;
use app\base\model\user\User;
use think\facade\Db;
class ThirdAuth extends Base
{
/**
* APP发起三方授权
*
* @param string $type 类型 weixin--微信授权 qq--QQ授权
* @param array $param 传递过来的参数
* @param string $param ['openid'] 唯一标识
* @date 2022-12-27
*/
public function updateThirdAuthInfo($type, $param)
{
$user_model = new User();
$user_logic = new \app\base\logic\User();
$jwt_class = new \jwt\Jwt();
switch ($type) {
case 'weixin':
$third_platform_user_model = new AppWeixinUser();
$data = [
'uid' => $this->mid,
'openid' => $param['openid'],
'unionid' => $param['unionid'],
'nickname' => $param['nickname'],
'headimgurl' => $param['headimgurl'],
'sex' => $param['sex'],
'province' => $param['province'],
'city' => $param['city'],
'country' => $param['country'],
'language' => $param['language']
];
break;
case 'qq':
$third_platform_user_model = new AppQqUser();
$data = [
'uid' => $this->mid,
'openid' => $param['openid'],
'nickname' => $param['nickname'],
'headimgurl' => $param['headimgurl'],
'gender' => $param['gender'],
'gender_type' => $param['gender_type'],
'year' => $param['year'],
'province' => $param['province'],
'city' => $param['city'],
'figureurl_type' => $param['figureurl_type'],
'figureurl' => $param['figureurl'],
'figureurl_qq' => $param['figureurl_qq'],
'is_lost' => $param['is_lost'],
'level' => $param['level'],
'is_yellow_vip' => $param['is_yellow_vip'],
'is_yellow_year_vip' => $param['is_yellow_year_vip'],
'yellow_vip_level' => $param['yellow_vip_level'],
'vip' => $param['vip'],
'constellation' => $param['constellation'],
];
break;
case 'sinaweibo':
$third_platform_user_model = new AppSinaweiboUser();
$data = [
'uid' => $this->mid,
'openid' => $param['openid'],
'nickname' => $param['nickname'],
'name' => $param['name'],
'headimgurl' => $param['headimgurl'],
'gender' => $param['gender'],
'province' => $param['province'],
'city' => $param['city'],
'location' => $param['location'],
'description' => $param['description'],
'url' => $param['url'],
'profile_url' => $param['profile_url'],
'domain' => $param['domain'],
'weihao' => $param['weihao'],
'followers_count' => $param['followers_count'],
'friends_count' => $param['friends_count'],
'statuses_count' => $param['statuses_count'],
'favourites_count' => $param['favourites_count'],
'created_at' => $param['created_at'],
'remark' => $param['remark'],
'language' => $param['language'],
];
break;
case 'apple':
$third_platform_user_model = new AppAppleUser();
$data = [
'uid' => $this->mid,
'openid' => $param['openid'],
'authorization_code' => $param['authorization_code'],
'identity_token' => $param['identity_token'],
'real_user_status' => $param['real_user_status'],
'scope' => $param['scope'],
'family_name' => empty($param['family_name']) ? '' : $param['family_name'],
'give_name' => empty($param['give_name']) ? '' : $param['give_name'],
'given_name' => empty($param['given_name']) ? '' : $param['given_name'],
'email' => empty($param['email']) ? '' : $param['email'],
];
break;
}
Db::startTrans();
// 更新APP三方授权用户信息openid唯一标识
$res = $third_platform_user_model->updateUser($data);
if (!$res) {
Db::rollback();
return sendErrorArray(3001, '更新授权用户信息失败');
}
// 查找APP三方授权用户信息
$third_platform_user = $third_platform_user_model->getOneData([
['openid', '=', $param['openid']]
], 'id,user_id');
// token
$token_data = TOKEN_DATA;
// token是否携带user_id
$token_user_id = $token_data['user_id'];
// 如果token携带user_id则为APP用户绑定/换绑三方授权
if ($token_user_id) {
// 三方平台已绑定其他user_id
if ($third_platform_user['user_id'] && $third_platform_user['user_id'] != $token_user_id) {
Db::rollback();
return sendErrorArray(3002, '该三方账号已绑定其他的账号,请先解绑后重试');
}
// 绑定三方平台授权信息
$res = $third_platform_user_model->dataUpdate([
'id' => $third_platform_user['id'],
'user_id' => $token_user_id
]);
if (!$res) {
Db::rollback();
return sendErrorArray(3003, '绑定授权用户失败');
}
// 换绑时,删除之前的绑定信息
$is_change_bind = $third_platform_user_model->getOneData([
['user_id', '=', $token_user_id],
['openid', '<>', $param['openid']]
]);
if (!empty($is_change_bind)) {
$res = $third_platform_user_model->dataUpdate([
'id' => $is_change_bind['id'],
'user_id' => 0
]);
if (!$res) {
Db::rollback();
return sendErrorArray(3004, '换绑失败');
}
}
$r_data = [
// 类型 1--授权注册 2--授权登录 3--授权绑定/换绑
'type' => 3,
];
} else if ($third_platform_user['user_id']) {
//查找用户信息
$user = $user_model->getOneData([
['id', '=', $third_platform_user['user_id']]
]);
//根据不同平台组合info参数
$info = TOKEN_DATA;
$info['user_agent'] = USER_AGENT;
//绑定device_id和user_id
$res = $user_logic->login($user['mobile_phone'], $info);
if ($res['code'] != 0) {
Db::rollback();
return $res;
}
// 签发token
$arr = TOKEN_DATA;
$arr['user_id'] = $user['id'];
$res_token = $jwt_class->signToken($arr);
$r_data = [
// 类型 1--授权注册 2--授权登录 3--授权绑定/换绑
'type' => 2,
'third_platform_user' => $third_platform_user,
'user_id' => $user['id'],
'access_token' => $res_token['token'],
'access_token_expire_time' => $res_token['exp'],
];
} else {
$r_data = [
// 类型 1--授权注册 2--授权登录 3--授权绑定/换绑
'type' => 1,
'third_platform_user' => $third_platform_user
];
}
Db::commit();
return sendSuccessArray($r_data);
}
/**
* 解绑授权
* @param string $type 类型 weixin--微信 qq--QQ sinaweibo--新浪微博 apple--苹果
*/
public function deleteThirdAuthInfo($type)
{
// 定义app绑定三方平台用户表
$app_third_user_model = '';
switch ($type) {
case 'weixin':
$app_third_user_model = new AppWeixinUser();
break;
case 'qq':
$app_third_user_model = new AppQqUser();
break;
case 'sinaweibo':
$app_third_user_model = new AppSinaweiboUser();
break;
case 'apple':
$app_third_user_model = new AppAppleUser();
break;
default:
break;
}
// 解除三方授权绑定
$res = $app_third_user_model->unbindAuth($this->userId);
if (!$res) {
return sendErrorArray(3001, '解绑失败');
}
return sendSuccessArray([], '解绑成功');
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save