底层代码优化及用户管理
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
Backend/dist
|
Backend/dist
|
||||||
Backend/node_modules
|
Backend/node_modules
|
||||||
|
vue_store/*
|
||||||
@@ -74,7 +74,7 @@ class DeviceController extends BaseController
|
|||||||
private function saveDevice($item)
|
private function saveDevice($item)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'deviceId' => isset($item['id']) ? $item['id'] : '',
|
'id' => isset($item['id']) ? $item['id'] : '',
|
||||||
'userName' => isset($item['userName']) ? $item['userName'] : '',
|
'userName' => isset($item['userName']) ? $item['userName'] : '',
|
||||||
'nickname' => isset($item['nickname']) ? $item['nickname'] : '',
|
'nickname' => isset($item['nickname']) ? $item['nickname'] : '',
|
||||||
'realName' => isset($item['realName']) ? $item['realName'] : '',
|
'realName' => isset($item['realName']) ? $item['realName'] : '',
|
||||||
@@ -103,11 +103,25 @@ class DeviceController extends BaseController
|
|||||||
];
|
];
|
||||||
|
|
||||||
// 使用imei作为唯一性判断
|
// 使用imei作为唯一性判断
|
||||||
$device = DeviceModel::where('imei', $item['imei'])->find();
|
$device = DeviceModel::where('id', $item['id'])->find();
|
||||||
|
|
||||||
if ($device) {
|
if ($device) {
|
||||||
$device->save($data);
|
$device->save($data);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
// autoLike:自动点赞
|
||||||
|
// momentsSync:朋友圈同步
|
||||||
|
// autoCustomerDev:自动开发客户
|
||||||
|
// groupMessageDeliver:群消息推送
|
||||||
|
// autoGroup:自动建群
|
||||||
|
|
||||||
|
$data['taskConfig'] = json_encode([
|
||||||
|
'autoLike' => true,
|
||||||
|
'momentsSync' => true,
|
||||||
|
'autoCustomerDev' => true,
|
||||||
|
'groupMessageDeliver' => true,
|
||||||
|
'autoGroup' => true,
|
||||||
|
]);
|
||||||
DeviceModel::create($data);
|
DeviceModel::create($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class FriendTaskController extends BaseController
|
|||||||
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : null;
|
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : null;
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'taskId' => $item['id'],
|
'id' => $item['id'],
|
||||||
'tenantId' => $item['tenantId'],
|
'tenantId' => $item['tenantId'],
|
||||||
'operatorAccountId' => $item['operatorAccountId'],
|
'operatorAccountId' => $item['operatorAccountId'],
|
||||||
'status' => $item['status'],
|
'status' => $item['status'],
|
||||||
@@ -134,7 +134,7 @@ class FriendTaskController extends BaseController
|
|||||||
];
|
];
|
||||||
|
|
||||||
// 使用taskId作为唯一性判断
|
// 使用taskId作为唯一性判断
|
||||||
$task = FriendTaskModel::where('taskId', $item['id'])->find();
|
$task = FriendTaskModel::where('id', $item['id'])->find();
|
||||||
|
|
||||||
if ($task) {
|
if ($task) {
|
||||||
$task->save($data);
|
$task->save($data);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class WechatController extends BaseController
|
|||||||
private function saveWechatAccount($item)
|
private function saveWechatAccount($item)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
|
'id' => $item['id'],
|
||||||
'wechatId' => $item['wechatId'],
|
'wechatId' => $item['wechatId'],
|
||||||
'deviceAccountId' => $item['deviceAccountId'],
|
'deviceAccountId' => $item['deviceAccountId'],
|
||||||
'imei' => $item['imei'],
|
'imei' => $item['imei'],
|
||||||
@@ -49,7 +50,7 @@ class WechatController extends BaseController
|
|||||||
'labels' => $item['labels']
|
'labels' => $item['labels']
|
||||||
];
|
];
|
||||||
|
|
||||||
$account = WechatAccountModel::where('wechatId', $item['wechatId'])->find();
|
$account = WechatAccountModel::where('id', $item['id'])->find();
|
||||||
if ($account) {
|
if ($account) {
|
||||||
$account->save($data);
|
$account->save($data);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class WechatFriendController extends BaseController
|
|||||||
private function saveFriend($item)
|
private function saveFriend($item)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
|
'id' => $item['id'],
|
||||||
'wechatAccountId' => $item['wechatAccountId'],
|
'wechatAccountId' => $item['wechatAccountId'],
|
||||||
'alias' => $item['alias'],
|
'alias' => $item['alias'],
|
||||||
'wechatId' => $item['wechatId'],
|
'wechatId' => $item['wechatId'],
|
||||||
@@ -106,11 +107,7 @@ class WechatFriendController extends BaseController
|
|||||||
];
|
];
|
||||||
|
|
||||||
// 使用三个字段的组合作为唯一性判断
|
// 使用三个字段的组合作为唯一性判断
|
||||||
$friend = WechatFriendModel::where([
|
$friend = WechatFriendModel::where('id',$item['id'])->find();
|
||||||
['ownerWechatId', '=', $item['ownerWechatId']],
|
|
||||||
['wechatId', '=', $item['wechatId']],
|
|
||||||
['wechatAccountId', '=', $item['wechatAccountId']]
|
|
||||||
])->find();
|
|
||||||
|
|
||||||
if ($friend) {
|
if ($friend) {
|
||||||
$friend->save($data);
|
$friend->save($data);
|
||||||
|
|||||||
@@ -467,4 +467,35 @@ if (!function_exists('getUserAction')) {
|
|||||||
'QUERY' => '查询'
|
'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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,4 +18,9 @@ Route::group('v1/store', function () {
|
|||||||
Route::get('list', 'app\\store\\controller\\FlowPackageController@getOrderList'); // 获取订单列表
|
Route::get('list', 'app\\store\\controller\\FlowPackageController@getOrderList'); // 获取订单列表
|
||||||
Route::get(':orderNo', 'app\\store\\controller\\FlowPackageController@getOrderDetail'); // 获取订单详情
|
Route::get(':orderNo', 'app\\store\\controller\\FlowPackageController@getOrderDetail'); // 获取订单详情
|
||||||
});
|
});
|
||||||
})/*->middleware(['jwt'])*/;
|
|
||||||
|
// 客户相关路由
|
||||||
|
Route::group('customers', function () {
|
||||||
|
Route::get('list', 'app\\store\\controller\\CustomerController@getList'); // 获取客户列表
|
||||||
|
});
|
||||||
|
})->middleware(['jwt']);
|
||||||
88
Server/application/store/controller/CustomerController.php
Normal file
88
Server/application/store/controller/CustomerController.php
Normal 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
|
||||||
|
], '获取成功');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -108,9 +108,10 @@ class FlowPackageController extends Api
|
|||||||
{
|
{
|
||||||
$params = $this->request->param();
|
$params = $this->request->param();
|
||||||
|
|
||||||
|
$userInfo = request()->userInfo;
|
||||||
// 获取用户ID,通常应该从会话或令牌中获取
|
// 获取用户ID,通常应该从会话或令牌中获取
|
||||||
$userId = isset($params['userId']) ? intval($params['userId']) : 1;
|
$userId = $userInfo['id'];
|
||||||
|
|
||||||
if (empty($userId)) {
|
if (empty($userId)) {
|
||||||
return errorJson('请先登录');
|
return errorJson('请先登录');
|
||||||
}
|
}
|
||||||
@@ -172,8 +173,9 @@ class FlowPackageController extends Api
|
|||||||
{
|
{
|
||||||
$params = $this->request->param();
|
$params = $this->request->param();
|
||||||
|
|
||||||
|
$userInfo = request()->userInfo;
|
||||||
// 获取用户ID,通常应该从会话或令牌中获取
|
// 获取用户ID,通常应该从会话或令牌中获取
|
||||||
$userId = isset($params['userId']) ? intval($params['userId']) : 1;
|
$userId = $userInfo['id'];
|
||||||
|
|
||||||
if (empty($userId)) {
|
if (empty($userId)) {
|
||||||
return errorJson('请先登录');
|
return errorJson('请先登录');
|
||||||
|
|||||||
Reference in New Issue
Block a user