门店端优化
This commit is contained in:
@@ -27,24 +27,33 @@ class CustomerController extends Api
|
||||
$pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : 10;
|
||||
$userInfo = request()->userInfo;
|
||||
|
||||
|
||||
$where = [];
|
||||
// 必要的查询条件
|
||||
$userId = $userInfo['id'];
|
||||
$companyId = $userInfo['companyId'];
|
||||
|
||||
|
||||
if (empty($userId) || empty($companyId)) {
|
||||
return errorJson('缺少必要参数');
|
||||
}
|
||||
|
||||
// 构建查询条件
|
||||
$where = [
|
||||
'du.userId' => $userId,
|
||||
'du.companyId' => $companyId
|
||||
];
|
||||
|
||||
$deviceIds = Db::name('device_user')->where(['userId' => $userId, 'companyId' => $companyId])->order('id DESC')->column('deviceId');
|
||||
if (empty($deviceIds)) {
|
||||
return errorJson('设备不存在');
|
||||
}
|
||||
$wechatIds = [];
|
||||
foreach ($deviceIds as $deviceId) {
|
||||
$wechatIds[] = Db::name('device_wechat_login')
|
||||
->where(['deviceId' => $deviceId])
|
||||
->order('id DESC')
|
||||
->value('wechatId');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 搜索条件
|
||||
if (!empty($params['keyword'])) {
|
||||
$where['wf.alias|wf.nickname|wf.wechatId'] = ['like', '%' . $params['keyword'] . '%'];
|
||||
$where['alias|nickname|wechatId'] = ['like', '%' . $params['keyword'] . '%'];
|
||||
}
|
||||
// if (!empty($params['email'])) {
|
||||
// $where['wa.bindEmail'] = ['like', '%' . $params['email'] . '%'];
|
||||
@@ -54,14 +63,10 @@ class CustomerController extends Api
|
||||
// }
|
||||
|
||||
// 构建查询
|
||||
$query = Db::name('device_user')
|
||||
->alias('du')
|
||||
->join(['s2_device' => 'd'], 'd.id = du.deviceId','left')
|
||||
->join(['s2_wechat_account' => 'wa'], 'wa.imei = d.imei','left')
|
||||
->join(['s2_wechat_friend' => 'wf'], 'wf.ownerWechatId = wa.wechatId','left')
|
||||
$query = Db::table('s2_wechat_friend')
|
||||
->where($where)
|
||||
->field('d.id as deviceId,d.imei,wf.*')
|
||||
->group('wf.wechatId'); // 防止重复数据
|
||||
->whereIn('ownerWechatId',$wechatIds)
|
||||
->group('wechatId'); // 防止重复数据
|
||||
|
||||
// 克隆查询对象,用于计算总数
|
||||
$countQuery = clone $query;
|
||||
@@ -69,10 +74,9 @@ class CustomerController extends Api
|
||||
|
||||
// 获取分页数据
|
||||
$list = $query->page($page, $pageSize)
|
||||
->order('wa.id DESC')
|
||||
->order('id DESC')
|
||||
->select();
|
||||
|
||||
|
||||
|
||||
// 格式化数据
|
||||
foreach ($list as &$item) {
|
||||
|
||||
Reference in New Issue
Block a user