重新编排.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

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 {
}