From 6ec2ceefc545aad3003a8be610352341d8e9956a Mon Sep 17 00:00:00 2001 From: Ghost <106998207@qq.com> Date: Sat, 29 Mar 2025 17:01:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=95=E5=B1=82=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=8F=8A=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- .../api/controller/DeviceController.php | 18 +++- .../api/controller/FriendTaskController.php | 4 +- .../api/controller/WechatController.php | 3 +- .../api/controller/WechatFriendController.php | 7 +- Server/application/common.php | 33 ++++++- Server/application/store/config/route.php | 7 +- .../store/controller/CustomerController.php | 88 +++++++++++++++++++ .../controller/FlowPackageController.php | 8 +- 9 files changed, 155 insertions(+), 16 deletions(-) create mode 100644 Server/application/store/controller/CustomerController.php diff --git a/.gitignore b/.gitignore index d488eb13..44131fc2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea Backend/dist -Backend/node_modules \ No newline at end of file +Backend/node_modules +vue_store/* \ No newline at end of file diff --git a/Server/application/api/controller/DeviceController.php b/Server/application/api/controller/DeviceController.php index 3bf74d74..a10a9a1d 100644 --- a/Server/application/api/controller/DeviceController.php +++ b/Server/application/api/controller/DeviceController.php @@ -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); } } diff --git a/Server/application/api/controller/FriendTaskController.php b/Server/application/api/controller/FriendTaskController.php index 0ca80ee9..5c420056 100644 --- a/Server/application/api/controller/FriendTaskController.php +++ b/Server/application/api/controller/FriendTaskController.php @@ -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); diff --git a/Server/application/api/controller/WechatController.php b/Server/application/api/controller/WechatController.php index 2523620d..f032d957 100644 --- a/Server/application/api/controller/WechatController.php +++ b/Server/application/api/controller/WechatController.php @@ -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 { diff --git a/Server/application/api/controller/WechatFriendController.php b/Server/application/api/controller/WechatFriendController.php index 92d00d9c..4e53df3f 100644 --- a/Server/application/api/controller/WechatFriendController.php +++ b/Server/application/api/controller/WechatFriendController.php @@ -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); diff --git a/Server/application/common.php b/Server/application/common.php index 29010f44..0ef158a2 100644 --- a/Server/application/common.php +++ b/Server/application/common.php @@ -467,4 +467,35 @@ if (!function_exists('getUserAction')) { 'QUERY' => '查询' ]; } -} \ No newline at end of file +} + + +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 '
';
+ }
+ call_user_func($func, $data);
+ if ($exit)
+ exit();
+ }
+}
diff --git a/Server/application/store/config/route.php b/Server/application/store/config/route.php
index bb5b769f..57212848 100644
--- a/Server/application/store/config/route.php
+++ b/Server/application/store/config/route.php
@@ -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'])*/;
\ No newline at end of file
+
+ // 客户相关路由
+ Route::group('customers', function () {
+ Route::get('list', 'app\\store\\controller\\CustomerController@getList'); // 获取客户列表
+ });
+})->middleware(['jwt']);
\ No newline at end of file
diff --git a/Server/application/store/controller/CustomerController.php b/Server/application/store/controller/CustomerController.php
new file mode 100644
index 00000000..aac4d738
--- /dev/null
+++ b/Server/application/store/controller/CustomerController.php
@@ -0,0 +1,88 @@
+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
+ ], '获取成功');
+ }
+}
\ No newline at end of file
diff --git a/Server/application/store/controller/FlowPackageController.php b/Server/application/store/controller/FlowPackageController.php
index fb7ea9d2..a4f40350 100644
--- a/Server/application/store/controller/FlowPackageController.php
+++ b/Server/application/store/controller/FlowPackageController.php
@@ -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('请先登录');