底层代码优化及用户管理

This commit is contained in:
Ghost
2025-03-29 17:01:56 +08:00
parent a734ae2864
commit 6ec2ceefc5
9 changed files with 155 additions and 16 deletions

View File

@@ -74,7 +74,7 @@ class DeviceController extends BaseController
private function saveDevice($item)
{
$data = [
'deviceId' => isset($item['id']) ? $item['id'] : '',
'id' => isset($item['id']) ? $item['id'] : '',
'userName' => isset($item['userName']) ? $item['userName'] : '',
'nickname' => isset($item['nickname']) ? $item['nickname'] : '',
'realName' => isset($item['realName']) ? $item['realName'] : '',
@@ -103,11 +103,25 @@ class DeviceController extends BaseController
];
// 使用imei作为唯一性判断
$device = DeviceModel::where('imei', $item['imei'])->find();
$device = DeviceModel::where('id', $item['id'])->find();
if ($device) {
$device->save($data);
} else {
// autoLike自动点赞
// momentsSync朋友圈同步
// autoCustomerDev自动开发客户
// groupMessageDeliver群消息推送
// autoGroup自动建群
$data['taskConfig'] = json_encode([
'autoLike' => true,
'momentsSync' => true,
'autoCustomerDev' => true,
'groupMessageDeliver' => true,
'autoGroup' => true,
]);
DeviceModel::create($data);
}
}

View File

@@ -112,7 +112,7 @@ class FriendTaskController extends BaseController
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : null;
$data = [
'taskId' => $item['id'],
'id' => $item['id'],
'tenantId' => $item['tenantId'],
'operatorAccountId' => $item['operatorAccountId'],
'status' => $item['status'],
@@ -134,7 +134,7 @@ class FriendTaskController extends BaseController
];
// 使用taskId作为唯一性判断
$task = FriendTaskModel::where('taskId', $item['id'])->find();
$task = FriendTaskModel::where('id', $item['id'])->find();
if ($task) {
$task->save($data);

View File

@@ -13,6 +13,7 @@ class WechatController extends BaseController
private function saveWechatAccount($item)
{
$data = [
'id' => $item['id'],
'wechatId' => $item['wechatId'],
'deviceAccountId' => $item['deviceAccountId'],
'imei' => $item['imei'],
@@ -49,7 +50,7 @@ class WechatController extends BaseController
'labels' => $item['labels']
];
$account = WechatAccountModel::where('wechatId', $item['wechatId'])->find();
$account = WechatAccountModel::where('id', $item['id'])->find();
if ($account) {
$account->save($data);
} else {

View File

@@ -68,6 +68,7 @@ class WechatFriendController extends BaseController
private function saveFriend($item)
{
$data = [
'id' => $item['id'],
'wechatAccountId' => $item['wechatAccountId'],
'alias' => $item['alias'],
'wechatId' => $item['wechatId'],
@@ -106,11 +107,7 @@ class WechatFriendController extends BaseController
];
// 使用三个字段的组合作为唯一性判断
$friend = WechatFriendModel::where([
['ownerWechatId', '=', $item['ownerWechatId']],
['wechatId', '=', $item['wechatId']],
['wechatAccountId', '=', $item['wechatAccountId']]
])->find();
$friend = WechatFriendModel::where('id',$item['id'])->find();
if ($friend) {
$friend->save($data);

View File

@@ -467,4 +467,35 @@ if (!function_exists('getUserAction')) {
'QUERY' => '查询'
];
}
}
}
if (!function_exists('exit_data')) {
/**
* 截断输出
* @param array $data
* @param string $type
* @param bool $exit
*/
function exit_data($data = [], $type = 'pr', $exit = true)
{
switch ($type) {
case 'pr':
$func = 'print_r';
break;
case 'vd':
$func = 'var_dump';
break;
default:
$func = 'print_r';
break;
}
if ($func == 'print_r') {
echo '<pre>';
}
call_user_func($func, $data);
if ($exit)
exit();
}
}

View File

@@ -18,4 +18,9 @@ Route::group('v1/store', function () {
Route::get('list', 'app\\store\\controller\\FlowPackageController@getOrderList'); // 获取订单列表
Route::get(':orderNo', 'app\\store\\controller\\FlowPackageController@getOrderDetail'); // 获取订单详情
});
})/*->middleware(['jwt'])*/;
// 客户相关路由
Route::group('customers', function () {
Route::get('list', 'app\\store\\controller\\CustomerController@getList'); // 获取客户列表
});
})->middleware(['jwt']);

View File

@@ -0,0 +1,88 @@
<?php
namespace app\store\controller;
use app\common\controller\Api;
use think\Db;
/**
* 客户管理控制器
*/
class CustomerController extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = ['*'];
/**
* 获取客户列表
*
* @return \think\Response
*/
public function getList()
{
$params = $this->request->param();
// 获取分页参数
$page = isset($params['page']) ? intval($params['page']) : 1;
$pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : 10;
$userInfo = request()->userInfo;
// 必要的查询条件
$userId = $userInfo['id'];
$companyId = $userInfo['companyId'];
if (empty($userId) || empty($companyId)) {
return errorJson('缺少必要参数');
}
// 构建查询条件
$where = [
'du.userId' => $userId,
'du.companyId' => $companyId
];
// 搜索条件
if (!empty($params['keyword'])) {
$where['wf.alias|wf.nickname|wf.wechatId'] = ['like', '%' . $params['keyword'] . '%'];
}
// if (!empty($params['email'])) {
// $where['wa.bindEmail'] = ['like', '%' . $params['email'] . '%'];
// }
// if (!empty($params['name'])) {
// $where['wa.accountRealName|wa.accountUserName|wa.nickname'] = ['like', '%' . $params['name'] . '%'];
// }
// 构建查询
$query = Db::name('device_user')
->alias('du')
->join('device d', 'd.id = du.deviceId','left')
->join('wechat_account wa', 'wa.imei = d.imei','left')
->join('wechat_friend wf', 'wf.ownerWechatId = wa.wechatId','left')
->where($where)
->field('d.id as deviceId,d.imei,wf.*')
->group('wf.wechatId'); // 防止重复数据
// 克隆查询对象,用于计算总数
$countQuery = clone $query;
$total = $countQuery->count();
// 获取分页数据
$list = $query->page($page, $pageSize)
->order('wa.id DESC')
->select();
// 格式化数据
foreach ($list as &$item) {
$item['labels'] = json_decode($item['labels'], true);
}
unset($item);
return successJson([
'list' => $list,
'total' => $total
], '获取成功');
}
}

View File

@@ -108,9 +108,10 @@ class FlowPackageController extends Api
{
$params = $this->request->param();
$userInfo = request()->userInfo;
// 获取用户ID通常应该从会话或令牌中获取
$userId = isset($params['userId']) ? intval($params['userId']) : 1;
$userId = $userInfo['id'];
if (empty($userId)) {
return errorJson('请先登录');
}
@@ -172,8 +173,9 @@ class FlowPackageController extends Api
{
$params = $this->request->param();
$userInfo = request()->userInfo;
// 获取用户ID通常应该从会话或令牌中获取
$userId = isset($params['userId']) ? intval($params['userId']) : 1;
$userId = $userInfo['id'];
if (empty($userId)) {
return errorJson('请先登录');