调整代码格式及使用常量去替换常用值
This commit is contained in:
@@ -35,7 +35,7 @@ Route::group('v1/', function () {
|
||||
// 获客场景相关
|
||||
Route::group('plan/scenes', function () {
|
||||
Route::get('', 'app\cunkebao\controller\Scene@index'); // 获取场景列表
|
||||
Route::post('create', 'app\cunkebao\controller\Plan@index'); // 获取场景列表
|
||||
Route::post('create', 'app\cunkebao\controller\Plan@index'); // 获取场景列表
|
||||
});
|
||||
|
||||
// 流量标签相关
|
||||
|
||||
@@ -85,7 +85,7 @@ class GetAddResultedDevicesController extends BaseController
|
||||
[
|
||||
'accountId' => $accountId,
|
||||
'pageIndex' => 0,
|
||||
'pageSize' => 1
|
||||
'pageSize' => 1
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
@@ -6,8 +6,10 @@ use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceTaskconf as DeviceTaskconfModel;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\DeviceWechatLogin;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\common\model\WechatFriend;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use Eison\Utils\Helper\ArrHelper;
|
||||
use library\ResponseHelper;
|
||||
|
||||
/**
|
||||
@@ -24,8 +26,8 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
protected function checkUserDevicePermission(int $deviceId): void
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId')
|
||||
];
|
||||
|
||||
@@ -65,19 +67,20 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
protected function getTaskConfig(int $deviceId): array
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
'deleteTime' => 0
|
||||
'deviceId' => $deviceId,
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
];
|
||||
|
||||
$conf = DeviceTaskconfModel::where($where)->field('autoAddFriend,autoReply,contentSync,aiChat')->find();
|
||||
$conf = DeviceTaskconfModel::alias('c')
|
||||
->field([
|
||||
'c.autoAddFriend', 'c.autoReply', 'c.contentSync', 'c.aiChat'
|
||||
])
|
||||
->where($where)
|
||||
->find();
|
||||
|
||||
return $conf ? $conf->toArray() : [
|
||||
'autoAddFriend' => 0,
|
||||
'autoReply' => 0,
|
||||
'contentSync' => 0,
|
||||
'aiChat' => 0
|
||||
];
|
||||
return $conf
|
||||
? $conf->toArray()
|
||||
: ArrHelper::getValue([], 'autoAddFriend,autoReply,contentSync,aiChat', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +93,7 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
protected function getTotalFriend(int $deviceId): int
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'deviceId' => $deviceId,
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
];
|
||||
|
||||
@@ -125,7 +128,6 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
->field([
|
||||
'd.id', 'd.imei', 'd.memo', 'd.alive', 'd.updateTime as lastUpdateTime', 'd.extra'
|
||||
])
|
||||
->where('d.deleteTime', 0)
|
||||
->find($id);
|
||||
|
||||
if (empty($device)) {
|
||||
@@ -155,7 +157,7 @@ class GetDeviceDetailV1Controller extends BaseController
|
||||
try {
|
||||
$id = $this->request->param('id/d');
|
||||
|
||||
if ($this->getUserInfo('isAdmin') != 1) {
|
||||
if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
|
||||
$this->checkUserDevicePermission($id);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace app\cunkebao\controller\device;
|
||||
|
||||
use app\common\model\DeviceHandleLog;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
|
||||
@@ -21,15 +22,15 @@ class GetDeviceHandleLogsV1Controller extends BaseController
|
||||
protected function checkUserDevicePermission(int $deviceId): void
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId')
|
||||
];
|
||||
|
||||
$hasPermission = DeviceUserModel::where($where)->count() > 0;
|
||||
|
||||
if (!$hasPermission) {
|
||||
throw new \Exception('您没有权限查看该设备', '403');
|
||||
throw new \Exception('您没有权限查看该设备', 403);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,9 +44,7 @@ class GetDeviceHandleLogsV1Controller extends BaseController
|
||||
{
|
||||
return DeviceHandleLog::alias('l')
|
||||
->field([
|
||||
'l.id',
|
||||
'l.content',
|
||||
'l.createTime',
|
||||
'l.id', 'l.content', 'l.createTime',
|
||||
'u.username'
|
||||
])
|
||||
->leftJoin('users u', 'l.userId = u.id')
|
||||
@@ -64,7 +63,7 @@ class GetDeviceHandleLogsV1Controller extends BaseController
|
||||
try {
|
||||
$deviceId = $this->request->param('id/d');
|
||||
|
||||
if ($this->getUserInfo('isAdmin') != 1) {
|
||||
if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
|
||||
$this->checkUserDevicePermission($deviceId);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace app\cunkebao\controller\device;
|
||||
|
||||
use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\common\model\WechatFriend;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
@@ -34,7 +35,6 @@ class GetDeviceListV1Controller extends BaseController
|
||||
}
|
||||
|
||||
$where['d.companyId'] = $this->getUserInfo('companyId');
|
||||
$where['d.deleteTime'] = 0;
|
||||
|
||||
return array_merge($params, $where);
|
||||
}
|
||||
@@ -72,7 +72,11 @@ class GetDeviceListV1Controller extends BaseController
|
||||
protected function getDeviceList(array $where, int $page = 1, int $limit = 10): \think\Paginator
|
||||
{
|
||||
$query = DeviceModel::alias('d')
|
||||
->field(['d.id', 'd.imei', 'd.memo', 'l.wechatId', 'd.alive', 'wa.nickname', 'wa.alias', '0 totalFriend'])
|
||||
->field([
|
||||
'd.id', 'd.imei', 'd.memo', 'd.alive',
|
||||
'l.wechatId',
|
||||
'wa.nickname', 'wa.alias', '0 totalFriend'
|
||||
])
|
||||
->leftJoin('device_wechat_login l', 'd.id = l.deviceId')
|
||||
->leftJoin('wechat_account wa', 'l.wechatId = wa.wechatId')
|
||||
->order('d.id desc');
|
||||
@@ -119,7 +123,7 @@ class GetDeviceListV1Controller extends BaseController
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
if ($this->getUserInfo('isAdmin') == 1) {
|
||||
if ($this->getUserInfo('isAdmin') == UserModel::ADMIN_STP) {
|
||||
$where = $this->makeWhere();
|
||||
$result = $this->getDeviceList($where);
|
||||
} else {
|
||||
@@ -129,7 +133,7 @@ class GetDeviceListV1Controller extends BaseController
|
||||
|
||||
return ResponseHelper::success(
|
||||
[
|
||||
'list' => $this->countFriend($result),
|
||||
'list' => $this->countFriend($result),
|
||||
'total' => $result->total(),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace app\cunkebao\controller\device;
|
||||
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\common\model\WechatAccount as WechatAccountModel;
|
||||
use app\common\model\WechatFriend;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
@@ -23,8 +24,8 @@ class GetRelatedAccountsV1Controller extends BaseController
|
||||
protected function checkUserDevicePermission(int $deviceId): void
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId')
|
||||
];
|
||||
|
||||
@@ -44,7 +45,7 @@ class GetRelatedAccountsV1Controller extends BaseController
|
||||
protected function getDeviceWechatIds(int $deviceId): array
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'deviceId' => $deviceId,
|
||||
'companyId' => $this->getUserInfo('companyId')
|
||||
];
|
||||
|
||||
@@ -148,7 +149,7 @@ class GetRelatedAccountsV1Controller extends BaseController
|
||||
try {
|
||||
$deviceId = $this->request->param('id/d');
|
||||
|
||||
if ($this->getUserInfo('isAdmin') != 1) {
|
||||
if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
|
||||
$this->checkUserDevicePermission($deviceId);
|
||||
}
|
||||
|
||||
@@ -159,7 +160,7 @@ class GetRelatedAccountsV1Controller extends BaseController
|
||||
[
|
||||
'deviceId' => $deviceId,
|
||||
'accounts' => $wechatAccounts,
|
||||
'total' => count($wechatAccounts)
|
||||
'total' => count($wechatAccounts)
|
||||
]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -25,9 +25,8 @@ class PostAddDeviceV1Controller extends BaseController
|
||||
{
|
||||
if ($this->request->param('imei')) {
|
||||
$where = [
|
||||
'imei' => $this->request->param('imei'),
|
||||
'imei' => $this->request->param('imei'),
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
'deleteTime' => 0
|
||||
];
|
||||
|
||||
$exist = DeviceModel::where($where)->count() > 0;
|
||||
@@ -72,9 +71,9 @@ class PostAddDeviceV1Controller extends BaseController
|
||||
{
|
||||
DeviceHandleLogModel::addLog(
|
||||
[
|
||||
'deviceId' => $deviceId,
|
||||
'content' => '添加设备',
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'content' => '添加设备',
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ use app\common\model\Device as DeviceModel;
|
||||
use app\common\model\DeviceHandleLog as DeviceHandleLogModel;
|
||||
use app\common\model\DeviceTaskconf;
|
||||
use app\common\model\DeviceUser as DeviceUserModel;
|
||||
use app\common\model\User as UserModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
use think\Db;
|
||||
@@ -25,9 +26,8 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
protected function checkDeviceExists(int $deviceId)
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
'deleteTime' => 0
|
||||
'deviceId' => $deviceId,
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
];
|
||||
|
||||
$device = DeviceModel::find($where);
|
||||
@@ -46,8 +46,8 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
protected function checkUserDevicePermission(int $deviceId): void
|
||||
{
|
||||
$where = [
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId')
|
||||
];
|
||||
|
||||
@@ -81,9 +81,9 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
|
||||
DeviceHandleLogModel::addLog(
|
||||
[
|
||||
'deviceId' => $deviceId,
|
||||
'content' => $content,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'deviceId' => $deviceId,
|
||||
'content' => $content,
|
||||
'userId' => $this->getUserInfo('id'),
|
||||
'companyId' => $this->getUserInfo('companyId'),
|
||||
]
|
||||
);
|
||||
@@ -119,7 +119,7 @@ class UpdateDeviceTaskConfigV1Controller extends BaseController
|
||||
|
||||
$this->checkDeviceExists($id);
|
||||
|
||||
if ($this->getUserInfo('isAdmin') != 1) {
|
||||
if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) {
|
||||
$this->checkUserDevicePermission($id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user