重新编排.gitignnore规则

This commit is contained in:
柳清爽
2025-03-17 11:47:42 +08:00
parent 083813dd5e
commit 0c259b413c
1781 changed files with 113 additions and 941 deletions

View File

@@ -1,15 +0,0 @@
[app]
debug = true
trace = true
[database]
type = mysql
hostname = 127.0.0.1
database = yi_54iis_com
username = yi_54iis_com
password = c1RbMwrZCCyxF1bC
hostport = 3306
prefix = tk_
[api]
wechat_url = https://s2.siyuguanli.com:9991/

1
Server/.gitignore vendored
View File

@@ -1,4 +1,5 @@
.idea
.env
.vscode
.DS_Store
composer.lock

0
Server/.htaccess Executable file → Normal file
View File

0
Server/CHANGELOG.md Executable file → Normal file
View File

0
Server/LICENSE.txt Executable file → Normal file
View File

0
Server/README.md Executable file → Normal file
View File

0
Server/application/.htaccess Executable file → Normal file
View File

View File

0
Server/application/command.php Executable file → Normal file
View File

0
Server/application/common.php Executable file → Normal file
View File

0
Server/application/common/AliyunSMS.php Executable file → Normal file
View File

0
Server/application/common/command/BaseCommand.php Executable file → Normal file
View File

0
Server/application/common/command/TestCommand.php Executable file → Normal file
View File

View File

@@ -3,27 +3,8 @@
use think\facade\Route;
// 添加测试路由
Route::get('api/test', function() {
return json([
'code' => 200,
'msg' => '路由测试成功',
'data' => [
'time' => date('Y-m-d H:i:s'),
'module' => 'common'
]
]);
});
// 数据库初始化路由
Route::get('api/database/init', 'app\\common\\controller\\Database@init');
Route::get('api/database/test', 'app\\common\\controller\\Database@test');
Route::get('api/database/update-password', 'app\\common\\controller\\Database@updatePassword');
Route::get('api/database/debug-password', 'app\\common\\controller\\Database@debugPassword');
Route::get('api/database/reset-password', 'app\\common\\controller\\Database@resetPassword');
// 定义RESTful风格的API路由 - 认证相关
Route::group('api/auth', function () {
Route::group('v1/auth', function () {
// 无需认证的接口
Route::post('login', 'app\\common\\controller\\Auth@login'); // 账号密码登录
Route::post('mobile-login', 'app\\common\\controller\\Auth@mobileLogin'); // 手机号验证码登录
@@ -32,6 +13,4 @@ Route::group('api/auth', function () {
// 需要JWT认证的接口
Route::get('info', 'app\\common\\controller\\Auth@info')->middleware(['jwt']); // 获取用户信息
Route::post('refresh', 'app\\common\\controller\\Auth@refresh')->middleware(['jwt']); // 刷新令牌
});
return [];
});

View File

@@ -92,7 +92,7 @@ class Auth extends Controller
if (!$validate->scene('mobile_login')->check($params)) {
return ResponseHelper::error($validate->getError());
}
try {
// 判断验证码是否已加密
$isEncrypted = isset($params['is_encrypted']) && $params['is_encrypted'] === true;
@@ -104,6 +104,7 @@ class Auth extends Controller
Request::ip(),
$isEncrypted
);
return ResponseHelper::success($result, '登录成功');
} catch (\Exception $e) {
return ResponseHelper::error($e->getMessage());

View File

@@ -1,196 +0,0 @@
<?php
namespace app\common\controller;
use think\Controller;
use think\Db;
use think\facade\Config;
use app\common\helper\ResponseHelper;
/**
* 数据库控制器
* 用于初始化数据库
*/
class Database extends Controller
{
/**
* 初始化数据库
* @return \think\response\Json
*/
public function init()
{
try {
// 创建表结构
$createTableSql = "
CREATE TABLE IF NOT EXISTS `tk_users` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
`username` varchar(50) NOT NULL COMMENT '用户名',
`password` varchar(60) NOT NULL COMMENT '密码',
`mobile` varchar(11) DEFAULT NULL COMMENT '登录手机号',
`identity_id` int(10) DEFAULT NULL COMMENT '身份信息',
`auth_id` int(10) DEFAULT NULL COMMENT '权限id',
`create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`delete_at` timestamp NULL DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`),
UNIQUE KEY `idx_username` (`username`),
UNIQUE KEY `idx_mobile` (`mobile`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表';
";
Db::execute($createTableSql);
// 检查是否已存在admin用户
$adminExists = Db::table('tk_users')->where('username', 'admin')->find();
if (!$adminExists) {
// 生成密码的加密值
$hashedPassword = password_hash('123456', PASSWORD_BCRYPT);
// 插入测试数据
$insertDataSql = "
INSERT INTO `tk_users` (`username`, `password`, `mobile`, `identity_id`, `auth_id`) VALUES
('admin', '{$hashedPassword}', '13800138000', 1, 1);
";
Db::execute($insertDataSql);
}
return ResponseHelper::success(null, '数据库初始化完成');
} catch (\Exception $e) {
return ResponseHelper::error('数据库初始化失败: ' . $e->getMessage());
}
}
/**
* 测试数据库连接和查询
* @return \think\response\Json
*/
public function test()
{
try {
// 查询用户表中的数据
$users = Db::table('tk_users')->select();
return ResponseHelper::success([
'count' => count($users),
'users' => $users
], '数据库查询成功');
} catch (\Exception $e) {
return ResponseHelper::error('数据库查询失败: ' . $e->getMessage());
}
}
/**
* 更新用户密码
* @param string $username 用户名
* @param string $password 新密码
* @return \think\response\Json
*/
public function updatePassword($username = 'admin', $password = '123456')
{
try {
// 生成密码的加密值
$hashedPassword = password_hash($password, PASSWORD_BCRYPT);
// 更新数据库中的用户密码
$result = Db::table('tk_users')
->where('username', $username)
->update(['password' => $hashedPassword]);
if ($result) {
return ResponseHelper::success([
'username' => $username,
'password' => $password,
'hashed_password' => $hashedPassword
], '密码更新成功');
} else {
return ResponseHelper::error('用户不存在或密码未更改');
}
} catch (\Exception $e) {
return ResponseHelper::error('密码更新失败: ' . $e->getMessage());
}
}
/**
* 调试密码验证
* @param string $username 用户名
* @param string $password 密码
* @return \think\response\Json
*/
public function debugPassword($username = 'admin', $password = '123456')
{
try {
// 查询用户
$user = Db::table('tk_users')->where('username', $username)->find();
if (!$user) {
return ResponseHelper::error('用户不存在');
}
// 生成新的密码哈希
$newHash = password_hash($password, PASSWORD_BCRYPT);
// 验证密码
$isValid = password_verify($password, $user['password']);
// 更新密码(确保使用正确的哈希算法)
if (!$isValid) {
Db::table('tk_users')
->where('username', $username)
->update(['password' => $newHash]);
}
return ResponseHelper::success([
'username' => $username,
'stored_hash' => $user['password'],
'new_hash' => $newHash,
'is_valid' => $isValid,
'password_info' => password_get_info($user['password'])
], '密码验证调试信息');
} catch (\Exception $e) {
return ResponseHelper::error('密码验证调试失败: ' . $e->getMessage());
}
}
/**
* 重置用户密码
* @param string $username 用户名
* @param string $password 新密码
* @return \think\response\Json
*/
public function resetPassword($username = 'admin', $password = '123456')
{
try {
// 查询用户
$user = Db::table('tk_users')->where('username', $username)->find();
if (!$user) {
return ResponseHelper::error('用户不存在');
}
// 使用正确的哈希算法生成密码
$hashedPassword = password_hash($password, PASSWORD_BCRYPT, ['cost' => 10]);
// 更新数据库中的用户密码
$result = Db::table('tk_users')
->where('username', $username)
->update(['password' => $hashedPassword]);
if ($result) {
// 验证密码是否正确
$isValid = password_verify($password, $hashedPassword);
return ResponseHelper::success([
'username' => $username,
'password' => $password,
'hashed_password' => $hashedPassword,
'is_valid' => $isValid
], '密码重置成功');
} else {
return ResponseHelper::error('密码重置失败');
}
} catch (\Exception $e) {
return ResponseHelper::error('密码重置失败: ' . $e->getMessage());
}
}
}

View File

@@ -1,79 +0,0 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class CreateUsersTable extends Migrator
{
/**
* 创建用户表
*/
public function up()
{
$table = $this->table('users', [
'engine' => 'InnoDB',
'comment' => '用户表',
'id' => 'id',
'signed' => false,
]);
$table->addColumn('username', 'string', [
'limit' => 50,
'null' => false,
'comment' => '用户名',
])
->addColumn('password', 'string', [
'limit' => 60,
'null' => false,
'comment' => '密码',
])
->addColumn('mobile', 'string', [
'limit' => 11,
'null' => true,
'comment' => '登录手机号',
])
->addColumn('identity_id', 'integer', [
'limit' => 10,
'null' => true,
'comment' => '身份信息',
])
->addColumn('auth_id', 'integer', [
'limit' => 10,
'null' => true,
'comment' => '权限id',
])
->addColumn('create_at', 'timestamp', [
'null' => false,
'default' => 'CURRENT_TIMESTAMP',
'comment' => '创建时间',
])
->addColumn('update_at', 'timestamp', [
'null' => false,
'default' => 'CURRENT_TIMESTAMP',
'update' => 'CURRENT_TIMESTAMP',
'comment' => '修改时间',
])
->addColumn('delete_at', 'timestamp', [
'null' => true,
'default' => null,
'comment' => '删除时间',
])
->addIndex(['username'], [
'unique' => true,
'name' => 'idx_username',
])
->addIndex(['mobile'], [
'unique' => true,
'name' => 'idx_mobile',
])
->create();
}
/**
* 删除用户表
*/
public function down()
{
$this->dropTable('users');
}
}

View File

@@ -1,19 +0,0 @@
-- 创建用户表
CREATE TABLE IF NOT EXISTS `tk_users` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
`username` varchar(50) NOT NULL COMMENT '用户名',
`password` varchar(60) NOT NULL COMMENT '密码',
`mobile` varchar(11) DEFAULT NULL COMMENT '登录手机号',
`identity_id` int(10) DEFAULT NULL COMMENT '身份信息',
`auth_id` int(10) DEFAULT NULL COMMENT '权限id',
`create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`delete_at` timestamp NULL DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`),
UNIQUE KEY `idx_username` (`username`),
UNIQUE KEY `idx_mobile` (`mobile`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表';
-- 插入测试数据
INSERT INTO `tk_users` (`username`, `password`, `mobile`, `identity_id`, `auth_id`) VALUES
('admin', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '13800138000', 1, 1); -- 密码为password

View File

@@ -1,11 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
class CompanyAccountModel extends Model {
}

View File

@@ -1,11 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
class DeviceGroupModel extends Model {
}

View File

@@ -1,69 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
class DeviceModel extends Model {
const ACTIVE_TIME = 60;
const IS_ONLINE_NO = 0;
const IS_ONLINE_YES = 10;
const STATUS_ACTIVE = 0;
const STATUS_DISABLE = 99;
/**
* 获取关联数组
*
* @return array
*/
static public function assoc() {
static $assoc = NULL;
if (is_null($assoc)) {
$assoc = [];
foreach (static::where(1)
->order('id', 'DESC')
->select() as $model) {
$assoc[$model->getAttr('id')] = $model->getAttr('number')
. ($model->isOnline() ? '[在线]' : '[离线]');
}
}
return $assoc;
}
/**
* 是否在线
*
* @return string[]
*/
static public function isOnlineAssoc() {
return [
static::IS_ONLINE_YES => '在线',
static::IS_ONLINE_NO => '离线',
];
}
/**
* 获取状态
*
* @return string[]
*/
static public function statusAssoc() {
return [
static::STATUS_ACTIVE => '正常',
static::STATUS_DISABLE => '停用',
];
}
/**
* 设备是否在线
*
* @return bool
*/
public function isOnline() {
return $this->getAttr('is_online') == static::IS_ONLINE_YES
AND time() - $this->getAttr('active_time') <= static::ACTIVE_TIME;
}
}

View File

@@ -1,37 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
class ProductGroupModel extends Model {
/**
* 获取关联数组
*
* @return array
*/
static public function assoc() {
$assoc = NULL;
if (is_null($assoc)) {
$assoc = [];
foreach (static::where(1)
->order('id', 'DESC')
->select() as $model) {
$assoc[$model->getAttr('id')] = $model->getAttr('name');
}
}
return $assoc;
}
/**
* 商品数量
*
* @return ProductModel
*/
public function productNum() {
return ProductModel::where(1)
->where('group_id', $this->getAttr('id'))
->count();
}
}

View File

@@ -1,26 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
class ProductModel extends Model {
const IS_USED_NO = 0;
const IS_USED_YES = 10;
protected $json = ['cb', 'images', 'labels', 'themes', 'opts'];
protected $jsonAssoc = TRUE;
/**
* 获取是否使用
*
* @return string[]
*/
static public function isUsedAssoc() {
return [
static::IS_USED_NO => '未使用',
static::IS_USED_YES => '已使用',
];
}
}

View File

@@ -1,16 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
class TaskDetailModel extends Model {
const STATUS_AWAIT = 0;
const STATUS_RUNNING = 10;
const STATUS_SUCC = 20;
const STATUS_FAIL = 99;
protected $json = ['params', 'info'];
protected $jsonAssoc = TRUE;
}

View File

@@ -1,159 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
class TaskModel extends Model {
const PLATFORM_XIANYU = 'XIANYU';
const TYPE_PRODUCT_RELEASE = 'PRODUCT_RELEASE';
const TYPE_PRODUCT_POLISH = 'PRODUCT_POLISH';
const TYPE_PRODUCT_ON = 'PRODUCT_ON';
const TYPE_PRODUCT_OFF = 'PRODUCT_OFF';
const TYPE_COIN_SIGN = 'COIN_SIGN';
const TYPE_COIN_DEDUCT = 'COIN_DEDUCT';
const TYPE_PRICE_CUT = 'PRICE_CUT';
const TYPE_COMMENT_REMOVE = 'COMMENT_REMOVE';
const TYPE_PRODUCT_RE_RELEASE = 'PRODUCT_RE_RELEASE';
const TYPE_RAISE_XY = 'RAISE_XY';
const TYPE_RAISE_XY_TZ = 'RAISE_XY_TZ';
const TYPE_RAISE_XY_UNITY = 'RAISE_XY_UNITY';
const TYPE_SYNC_USER = 'SYNC_USER';
const TYPE_SYNC_SHOP = 'SYNC_SHOP';
const TYPE_UPDATE_USER = 'UPDATE_USER';
const TYPE_PRODUCT_WELFARE = 'PRODUCT_WELFARE';
const TYPE_MESSAGE_REPLY = 'MESSAGE_REPLY';
const RUN_TYPE_ONCE = 'ONCE';
const RUN_TYPE_TIMER = 'TIMER';
const RUN_TYPE_DAILY = 'DAILY';
const STATUS_AWAIT = 0;
const STATUS_ALLOC = 10;
const STATUS_COMPLETE = 20;
const IS_DELETED_NO = 0;
const IS_DELETED_YES = 10;
protected $json = ['params'];
protected $jsonAssoc = TRUE;
/**
* 获取类型
*
* @return string[]
*/
static public function typeAssoc() {
return [
static::TYPE_PRODUCT_RELEASE => '[闲鱼]发布商品',
static::TYPE_PRODUCT_POLISH => '[闲鱼]擦亮商品',
static::TYPE_PRODUCT_ON => '[闲鱼]上架商品',
static::TYPE_PRODUCT_OFF => '[闲鱼]下架商品',
static::TYPE_COIN_SIGN => '[闲鱼]签到鱼币',
static::TYPE_COIN_DEDUCT => '[闲鱼]鱼币抵扣',
static::TYPE_PRICE_CUT => '[闲鱼]一键降价',
static::TYPE_COMMENT_REMOVE => '[闲鱼]删除留言',
static::TYPE_PRODUCT_RE_RELEASE => '[闲鱼]编辑重复',
static::TYPE_RAISE_XY => '[闲鱼]养号',
static::TYPE_RAISE_XY_UNITY => '[闲鱼]互助养号',
static::TYPE_RAISE_XY_TZ => '[闲鱼]会玩养号',
static::TYPE_SYNC_USER => '[闲鱼]采集账号信息',
static::TYPE_SYNC_SHOP => '[闲鱼]采集店铺信息',
static::TYPE_UPDATE_USER => '[闲鱼]修改账号信息',
static::TYPE_PRODUCT_WELFARE => '[闲鱼]公益宝贝',
static::TYPE_MESSAGE_REPLY => '[闲鱼]消息回复',
];
}
/**
* 获取状态
*
* @return string[]
*/
static public function statusAssoc() {
return [
static::STATUS_AWAIT => '加入队列',
static::STATUS_ALLOC => '准备运行',
static::STATUS_COMPLETE => '运行成功',
];
}
/**
* 获取执行方式
*
* @return string[]
*/
static public function runTypeAssoc() {
return [
static::RUN_TYPE_ONCE => '立刻执行',
static::RUN_TYPE_TIMER => '定时执行',
static::RUN_TYPE_DAILY => '每天执行',
];
}
/**
* 平台
*
* @return string[]
*/
static public function platformAssoc() {
return [
static::PLATFORM_XIANYU => '闲鱼',
];
}
/**
* 任务类
*
* @return string[]
*/
static public function taskClasses() {
return [
static::TYPE_PRODUCT_RELEASE => '\app\common\task\ProductReleaseTask',
static::TYPE_PRODUCT_POLISH => '\app\common\task\ProductPolishTask',
static::TYPE_PRODUCT_ON => '\app\common\task\ProductOnTask',
static::TYPE_PRODUCT_OFF => '\app\common\task\ProductOffTask',
static::TYPE_COIN_SIGN => '\app\common\task\CoinSignTask',
static::TYPE_COIN_DEDUCT => '\app\common\task\CoinDeductTask',
static::TYPE_PRICE_CUT => '\app\common\task\PriceCutTask',
static::TYPE_COMMENT_REMOVE => '\app\common\task\CommentRemoveTask',
static::TYPE_PRODUCT_RE_RELEASE => '\app\common\task\ProductReReleaseTask',
static::TYPE_RAISE_XY => '\app\common\task\RaiseXyTask',
static::TYPE_RAISE_XY_UNITY => '\app\common\task\RaiseXyUnityTask',
static::TYPE_RAISE_XY_TZ => '\app\common\task\RaiseXyTzTask',
static::TYPE_SYNC_USER => '\app\common\task\SyncUserTask',
static::TYPE_SYNC_SHOP => '\app\common\task\SyncShopTask',
static::TYPE_UPDATE_USER => '\app\common\task\UpdateUserTask',
static::TYPE_PRODUCT_WELFARE => '\app\common\task\ProductWelfareTask',
static::TYPE_MESSAGE_REPLY => '\app\common\task\MessageReplyTask',
];
}
/**
* 分配到详情
*
* @param TaskModel $model
* @return bool
*/
static public function toDetail(TaskModel $model) {
$detail = new TaskDetailModel();
$detail->setAttr('task_id', $model->getAttr('id'));
$detail->setAttr('device_id', $model->getAttr('device_id'));
$detail->setAttr('platform', $model->getAttr('platform'));
$detail->setAttr('type', $model->getAttr('type'));
$detail->setAttr('params', $model->getAttr('params'));
$detail->setAttr('info', new \stdClass());
return $detail->save();
}
/**
* 获取设备
*
* @return DeviceModel
*/
public function device() {
return DeviceModel::get($this->getAttr('device_id'));
}
}

View File

@@ -1,39 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
class UserModel extends Model {
const STATUS_ACTIVE = 0; // 正常
const STATUS_DISABLE = 99; // 禁用
/**
* 获取状态
*
* @return string[]
*/
public static function statusAssoc() {
return [
static::STATUS_ACTIVE => '正常',
static::STATUS_DISABLE => '禁用',
];
}
/**
* 只读
*
* @var array
*/
protected $readonly = ['username'];
/**
* JSON 字段
*
* @var array
*/
protected $json = ['roles'];
protected $jsonAssoc = TRUE;
}

View File

@@ -1,9 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
class UserTokenModel extends Model {
}

View File

@@ -1,19 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
class WechatAccountModel extends Model
{
protected $table = 'wechat_account';
protected $pk = 'id';
// 自动写入时间戳
protected $autoWriteTimestamp = true;
protected $createTime = 'createTime';
protected $updateTime = 'updateTime';
// 数据表字段采用驼峰式命名
protected $convertNameToCamel = true;
}

View File

@@ -1,11 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
class WechatFriendModel extends Model {
}

View File

@@ -3,14 +3,17 @@
// | 设备管理模块路由配置
// +----------------------------------------------------------------------
return [
// 设备管理路由
'devices/count' => 'devices/index/count', // 获取设备总数
'devices/list' => 'devices/index/index', // 获取设备列表
'devices/info/:id' => 'devices/index/read', // 获取设备详情
'devices/add' => ['devices/index/save', ['method' => 'post']], // 添加设备
'devices/update/:id' => ['devices/index/update', ['method' => 'put']], // 更新设备
'devices/delete/:id' => ['devices/index/delete', ['method' => 'delete']], // 删除设备
'devices/count_by_brand' => 'devices/index/countByBrand', // 按设备品牌统计数量
'devices/count_by_status' => 'devices/index/countByStatus', // 设备在线状态统计数量
];
use think\facade\Route;
// 定义RESTful风格的API路由 - 设备管理相关
Route::group('v1/devices', function () {
// 设备列表和查询
Route::get('', 'app\\devices\\controller\\Device@index'); // 获取设备列表
Route::get('count', 'app\\devices\\controller\\Device@count'); // 获取设备总数
Route::get(':id', 'app\\devices\\controller\\Device@read'); // 获取设备详情
// 设备管理
Route::post('', 'app\\devices\\controller\\Device@save'); // 添加设备
Route::put('refresh', 'app\\devices\\controller\\Device@refresh'); // 刷新设备状态
Route::delete(':id', 'app\\devices\\controller\\Device@delete'); // 删除设备
})->middleware(['jwt']);

View File

@@ -2,14 +2,32 @@
namespace app\devices\controller;
use think\Controller;
use app\devices\model\Device;
use app\devices\model\Device as DeviceModel;
use think\facade\Request;
use app\common\util\JwtUtil;
/**
* 设备管理控制器
*/
class Index extends Controller
class Device extends Controller
{
/**
* 用户信息
* @var object
*/
protected $user;
/**
* 初始化
*/
protected function initialize()
{
parent::initialize();
// 设置时区
date_default_timezone_set('Asia/Shanghai');
}
/**
* 获取设备总数
* @return \think\response\Json
@@ -20,38 +38,20 @@ class Index extends Controller
// 获取查询条件
$where = [];
// 设备品牌
$brand = Request::param('brand');
if (!empty($brand)) {
$where['brand'] = $brand;
// 租户ID
$tenantId = Request::param('tenant_id');
if (is_numeric($tenantId)) {
$where['tenantId'] = $tenantId;
}
// 设备型号
$model = Request::param('model');
if (!empty($model)) {
$where['model'] = $model;
}
// 设备在线状态
$alive = Request::param('alive');
if (is_numeric($alive)) {
$where['alive'] = $alive;
}
// 租户ID
$tenantId = Request::param('tenant_id');
if (is_numeric($tenantId)) {
$where['tenantId'] = $tenantId;
}
// 分组ID
$groupId = Request::param('group_id');
if (is_numeric($groupId)) {
$where['groupId'] = $groupId;
}
// 获取设备总数
$count = Device::getDeviceCount($where);
$count = DeviceModel::getDeviceCount($where);
return json([
'code' => 200,
@@ -78,58 +78,34 @@ class Index extends Controller
// 获取查询条件
$where = [];
// 设备名称
$userName = Request::param('user_name');
if (!empty($userName)) {
$where['userName'] = ['like', "%{$userName}%"];
}
// 设备IMEI
$imei = Request::param('imei');
if (!empty($imei)) {
$where['imei'] = ['like', "%{$imei}%"];
}
// 设备品牌
$brand = Request::param('brand');
if (!empty($brand)) {
$where['brand'] = $brand;
// 设备备注
$memo = Request::param('memo');
if (!empty($memo)) {
$where['memo'] = ['like', "%{$memo}%"];
}
// 设备型号
$model = Request::param('model');
if (!empty($model)) {
$where['model'] = $model;
}
// 设备在线状态
$alive = Request::param('alive');
if (is_numeric($alive)) {
$where['alive'] = $alive;
}
// 租户ID
$tenantId = Request::param('tenant_id');
if (is_numeric($tenantId)) {
$where['tenantId'] = $tenantId;
}
// 分组ID
$groupId = Request::param('group_id');
if (is_numeric($groupId)) {
$where['groupId'] = $groupId;
}
// 获取分页参数
$page = Request::param('page/d', 1);
$limit = Request::param('limit/d', 10);
$page = (int)Request::param('page', 1);
$limit = (int)Request::param('limit', 10);
// 获取排序参数
$sort = Request::param('sort', 'id');
$order = Request::param('order', 'desc');
// 获取设备列表
$list = Device::getDeviceList($where, "{$sort} {$order}", $page, $limit);
$list = DeviceModel::getDeviceList($where, "{$sort} {$order}", $page, $limit);
return json([
'code' => 200,
@@ -164,7 +140,7 @@ class Index extends Controller
}
// 获取设备详情
$info = Device::getDeviceInfo($id);
$info = DeviceModel::getDeviceInfo($id);
if (empty($info)) {
return json([
'code' => 404,
@@ -184,6 +160,27 @@ class Index extends Controller
]);
}
}
/**
* 刷新设备
* @return \think\response\Json
*/
public function refresh()
{
try {
return json([
'code' => 200,
'msg' => '刷新成功',
'data' => []
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '获取失败:' . $e->getMessage()
]);
}
}
/**
* 添加设备
@@ -204,7 +201,7 @@ class Index extends Controller
}
// 验证IMEI是否已存在
$exists = Device::where('imei', $data['imei'])->where('isDeleted', 0)->find();
$exists = DeviceModel::where('imei', $data['imei'])->where('isDeleted', 0)->find();
if ($exists) {
return json([
'code' => 400,
@@ -213,7 +210,7 @@ class Index extends Controller
}
// 添加设备
$id = Device::addDevice($data);
$id = DeviceModel::addDevice($data);
return json([
'code' => 200,
@@ -229,64 +226,7 @@ class Index extends Controller
]);
}
}
/**
* 更新设备
* @return \think\response\Json
*/
public function update()
{
try {
// 获取设备ID
$id = Request::param('id/d');
if (empty($id)) {
return json([
'code' => 400,
'msg' => '参数错误'
]);
}
// 获取设备数据
$data = Request::put();
// 验证设备是否存在
$exists = Device::where('id', $id)->where('isDeleted', 0)->find();
if (!$exists) {
return json([
'code' => 404,
'msg' => '设备不存在'
]);
}
// 如果更新IMEI验证IMEI是否已存在
if (!empty($data['imei']) && $data['imei'] != $exists['imei']) {
$imeiExists = Device::where('imei', $data['imei'])->where('isDeleted', 0)->where('id', '<>', $id)->find();
if ($imeiExists) {
return json([
'code' => 400,
'msg' => '设备IMEI已存在'
]);
}
}
// 更新设备
$result = Device::updateDevice($id, $data);
return json([
'code' => 200,
'msg' => '更新成功',
'data' => [
'result' => $result
]
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '更新失败:' . $e->getMessage()
]);
}
}
/**
* 删除设备
* @return \think\response\Json
@@ -304,7 +244,7 @@ class Index extends Controller
}
// 验证设备是否存在
$exists = Device::where('id', $id)->where('isDeleted', 0)->find();
$exists = DeviceModel::where('id', $id)->where('isDeleted', 0)->find();
if (!$exists) {
return json([
'code' => 404,
@@ -313,7 +253,7 @@ class Index extends Controller
}
// 删除设备
$result = Device::deleteDevice($id);
$result = DeviceModel::deleteDevice($id);
return json([
'code' => 200,
@@ -329,50 +269,4 @@ class Index extends Controller
]);
}
}
/**
* 按设备品牌统计数量
* @return \think\response\Json
*/
public function countByBrand()
{
try {
// 获取统计数据
$data = Device::countByBrand();
return json([
'code' => 200,
'msg' => '获取成功',
'data' => $data
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '获取失败:' . $e->getMessage()
]);
}
}
/**
* 按设备在线状态统计数量
* @return \think\response\Json
*/
public function countByStatus()
{
try {
// 获取统计数据
$data = Device::countByStatus();
return json([
'code' => 200,
'msg' => '获取成功',
'data' => $data
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '获取失败:' . $e->getMessage()
]);
}
}
}

View File

@@ -10,19 +10,31 @@ use think\Db;
class Device extends Model
{
// 设置表名
protected $name = 'tk_device';
protected $name = 'device';
// 设置主键
protected $pk = 'id';
// 自动写入时间戳
protected $autoWriteTimestamp = true;
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createTime';
protected $updateTime = 'updateTime';
protected $deleteTime = 'deleteTime';
// 定义字段类型
protected $type = [
'id' => 'integer',
'createTime' => 'integer',
'updateTime' => 'integer',
'deleteTime' => 'integer',
'alive' => 'integer',
'isDeleted' => 'integer',
'tenantId' => 'integer',
'groupId' => 'integer'
];
/**
* 获取设备总数
* @param array $where 查询条件
@@ -105,7 +117,7 @@ class Device extends Model
return self::where('id', $id)
->update([
'isDeleted' => 1,
'deleteTime' => date('Y-m-d H:i:s')
'deleteTime' => date('Y-m-d H:i:s', time())
]);
}

View File

@@ -0,0 +1,11 @@
<?php
namespace app\http\middleware;
/**
* JWT中间件别名
* 解决类不存在: app\http\middleware\jwt的问题
*/
class jwt extends JwtAuth
{
// 继承JwtAuth的所有功能
}

0
Server/application/provider.php Executable file → Normal file
View File

0
Server/application/tags.php Executable file → Normal file
View File

0
Server/build.php Executable file → Normal file
View File

0
Server/composer.json Executable file → Normal file
View File

0
Server/config/app.php Executable file → Normal file
View File

0
Server/config/cache.php Executable file → Normal file
View File

0
Server/config/console.php Executable file → Normal file
View File

0
Server/config/cookie.php Executable file → Normal file
View File

0
Server/config/database.php Executable file → Normal file
View File

0
Server/config/log.php Executable file → Normal file
View File

0
Server/config/middleware.php Executable file → Normal file
View File

0
Server/config/session.php Executable file → Normal file
View File

0
Server/config/template.php Executable file → Normal file
View File

0
Server/config/trace.php Executable file → Normal file
View File

0
Server/extend/.gitignore vendored Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/.coveralls.yml Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/.gitignore vendored Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/.travis.yml Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/CHANGELOG.md Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/LICENSE.md Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/README-CN.md Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/README.md Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/autoload.php Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/build-phar.sh Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/composer.json Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/example.jpg Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

0
Server/extend/aliyun-oss-php-sdk-2.4.1/index.php Executable file → Normal file
View File

0
Server/extend/aliyun-oss-php-sdk-2.4.1/phpunit.xml Executable file → Normal file
View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

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