diff --git a/Server/application/common/model/User.php b/Server/application/common/model/User.php index 4c3e6a50..176d7b70 100644 --- a/Server/application/common/model/User.php +++ b/Server/application/common/model/User.php @@ -94,7 +94,7 @@ class User extends Model ]); // 验证密码 - $isValid = password_verify($password, $user->passwordMd5); + $isValid = ($user->passwordMd5 == md5($password)); \think\facade\Log::info('密码验证结果', [ 'account' => $account, diff --git a/Server/application/devices/controller/Device.php b/Server/application/devices/controller/Device.php index bcd2bd22..a95b653e 100644 --- a/Server/application/devices/controller/Device.php +++ b/Server/application/devices/controller/Device.php @@ -119,19 +119,19 @@ class Device extends Controller // 设备IMEI $imei = Request::param('imei'); if (!empty($imei)) { - $where['imei'] = ['like', "%{$imei}%"]; + $where['d.imei'] = ['like', "%{$imei}%"]; } // 设备备注 $memo = Request::param('memo'); if (!empty($memo)) { - $where['memo'] = ['like', "%{$memo}%"]; + $where['d.memo'] = ['like', "%{$memo}%"]; } // 设备在线状态 $alive = Request::param('alive'); if (is_numeric($alive)) { - $where['alive'] = $alive; + $where['d.alive'] = $alive; } // 获取分页参数 @@ -139,11 +139,11 @@ class Device extends Controller $limit = (int)Request::param('limit', 10); // 获取排序参数 - $sort = Request::param('sort', 'id'); + $sort = Request::param('sort', 'd.id'); $order = Request::param('order', 'desc'); // 添加公司ID过滤条件 - $where['companyId'] = $userInfo['companyId']; + $where['d.companyId'] = $userInfo['companyId']; // 根据用户管理员状态调整查询条件 if ($userInfo['isAdmin'] == 1) { @@ -164,7 +164,7 @@ class Device extends Controller } // 添加设备ID过滤条件 - $where['id'] = ['in', $deviceIds]; + $where['d.id'] = ['in', $deviceIds]; $list = DeviceModel::getDeviceList($where, "{$sort} {$order}", $page, $limit); } diff --git a/Server/application/devices/model/Device.php b/Server/application/devices/model/Device.php index 26cd7f1c..cff3748e 100644 --- a/Server/application/devices/model/Device.php +++ b/Server/application/devices/model/Device.php @@ -43,11 +43,25 @@ class Device extends Model public static function getDeviceCount($where = []) { // 默认只统计未删除的设备 - if (!isset($where['isDeleted'])) { + if (!isset($where['isDeleted']) && !isset($where['d.isDeleted'])) { $where['isDeleted'] = 0; } - return self::where($where)->count(); + // 确定是否使用了表别名 + $hasAlias = false; + foreach ($where as $key => $value) { + if (strpos($key, '.') !== false) { + $hasAlias = true; + break; + } + } + + // 如果使用了表别名,则需要使用查询构造器 + if ($hasAlias) { + return self::alias('d')->where($where)->count(); + } else { + return self::where($where)->count(); + } } /** @@ -58,15 +72,39 @@ class Device extends Model * @param int $limit 每页数量 * @return \think\Paginator 分页对象 */ - public static function getDeviceList($where = [], $order = 'id desc', $page = 1, $limit = 10) + public static function getDeviceList($where = [], $order = 'd.id desc', $page = 1, $limit = 10) { // 默认只查询未删除的设备 if (!isset($where['isDeleted'])) { - $where['isDeleted'] = 0; + $where['d.isDeleted'] = 0; } - - return self::where($where) - ->order($order) + + // 处理查询条件,避免排序规则冲突 + $conditions = []; + foreach ($where as $key => $value) { + // 对于涉及 JOIN 的字段特殊处理 + if (strpos($key, 'imei') !== false) { + // 删除原本的 imei 条件,避免直接使用它 + continue; + } + $conditions[$key] = $value; + } + + $query = self::alias('d') + ->field(['d.id', 'd.imei', 'd.memo', 'w.wechatId', 'd.alive', 'w.totalFriend']) + ->leftJoin('tk_wechat_account w', 'd.imei = w.imei COLLATE utf8mb4_unicode_ci') + ->where($conditions); + + // 单独处理 imei 搜索条件,确保使用相同的排序规则 + if (isset($where['imei'])) { + if (is_array($where['imei']) && isset($where['imei'][0]) && $where['imei'][0] === 'like') { + $query->where('d.imei', 'like', $where['imei'][1]); + } else { + $query->where('d.imei', $where['imei']); + } + } + + return $query->order($order) ->paginate($limit, false, ['page' => $page]); }