|
|
@@ -7,22 +7,22 @@ class FollowController extends Controller
|
|
|
'table' => 'school_follow',
|
|
|
'first_id' => 'school_id',
|
|
|
'second_id' => 'contact_id',
|
|
|
- 'table1' => 'school',
|
|
|
- 'table2' => 'school_contact',
|
|
|
+ 'table1' => 'wx_school',
|
|
|
+ 'table2' => 'wx_school_contact',
|
|
|
],
|
|
|
'canteen' => [
|
|
|
'table' => 'canteen_follow',
|
|
|
'first_id' => 'school_id',
|
|
|
'second_id' => 'canteen_id',
|
|
|
- 'table1' => 'school',
|
|
|
- 'table2' => 'canteen',
|
|
|
+ 'table1' => 'wx_school',
|
|
|
+ 'table2' => 'wx_canteen',
|
|
|
],
|
|
|
'company' => [
|
|
|
'table' => 'company_follow',
|
|
|
'first_id' => 'company_id',
|
|
|
'second_id' => 'contact_id',
|
|
|
- 'table1' => 'company',
|
|
|
- 'table2' => 'company_contact',
|
|
|
+ 'table1' => 'wx_company',
|
|
|
+ 'table2' => 'wx_company_contact',
|
|
|
]
|
|
|
];
|
|
|
|
|
|
@@ -133,10 +133,17 @@ class FollowController extends Controller
|
|
|
}
|
|
|
$this->checkAuth($firstId);
|
|
|
$filter = [
|
|
|
- $this->tableArr['first_id'] => $firstId,
|
|
|
- $this->tableArr['second_id'] => Helper::getPostInt('second_id') ? : null,
|
|
|
+ 't1.' . $this->tableArr['first_id'] => $firstId,
|
|
|
+ 't1.' . $this->tableArr['second_id'] => Helper::getPostInt('second_id') ? : null,
|
|
|
];
|
|
|
$criteria = DbCriteria::simpleCompare($filter)->setOrder('id desc');
|
|
|
+ $criteria->setAlias('t1')->addCondition('t2.id > 0');
|
|
|
+ if ($this->type == 'canteen') {
|
|
|
+ $criteria->setSelect('t1.*,t2.name,t2.weixin,t2.phone');
|
|
|
+ } else {
|
|
|
+ $criteria->setSelect('t1.*,t2.name,t2.weixin,t2.phone,t2.position');
|
|
|
+ }
|
|
|
+ $criteria->join = "left join {$this->tableArr['table2']} t2 on t2.id = t1.{$this->tableArr['second_id']} and t2.is_del = 0";
|
|
|
$data = DB::getListWithCriteria($this->tableArr['table'], $criteria);
|
|
|
$data['records'] = $this->formatFollowList($data['records']);
|
|
|
Helper::ok($data['records']);
|
|
|
@@ -192,26 +199,35 @@ class FollowController extends Controller
|
|
|
$schoolArr = Helper::getArrParam($_POST, 'school', Helper::PARAM_KEY_TYPE['array_int']);
|
|
|
if ($schoolArr) {
|
|
|
$filter = [
|
|
|
- $this->tableArr['first_id'] => $schoolArr[0]? : null,
|
|
|
- $this->tableArr['second_id'] => $schoolArr[1]? : null,
|
|
|
+ 't1.' . $this->tableArr['first_id'] => $schoolArr[0]? : null,
|
|
|
+ 't1.' . $this->tableArr['second_id'] => $schoolArr[1]? : null,
|
|
|
];
|
|
|
} else {
|
|
|
$filter = [
|
|
|
- $this->tableArr['first_id'] => Helper::getPostInt('first_id')? : null,
|
|
|
- $this->tableArr['second_id'] => Helper::getPostInt('second_id')? : null,
|
|
|
+ 't1.' . $this->tableArr['first_id'] => Helper::getPostInt('first_id')? : null,
|
|
|
+ 't1.' . $this->tableArr['second_id'] => Helper::getPostInt('second_id')? : null,
|
|
|
];
|
|
|
}
|
|
|
- if (empty($filter[$this->tableArr['first_id']])) {
|
|
|
- $filter[$this->tableArr['first_id']] = $this->type == 'company' ? $this->getCompanyFilter() : $this->getSchoolFilter();
|
|
|
+ if (empty($filter['t1.' .$this->tableArr['first_id']])) {
|
|
|
+ $filter['t1.' . $this->tableArr['first_id']] = $this->type == 'company' ? $this->getCompanyFilter() : $this->getSchoolFilter();
|
|
|
+ } else {
|
|
|
+ $this->checkAuth($filter['t1.' .$this->tableArr['first_id']]);
|
|
|
}
|
|
|
if ($phone = Helper::getPostString('phone')) {
|
|
|
$rs = Helper::arrayColumn(DB::getListWithCriteria($this->tableArr['table2'], DbCriteria::simpleCompare(['phone' => $phone])->setSelect('id')), 'id');
|
|
|
- $filter[$this->tableArr['second_id']] = $rs?: [-1];
|
|
|
+ $filter['t1.' . $this->tableArr['second_id']] = $rs?: [-1];
|
|
|
}
|
|
|
$criteria = DbCriteria::simpleCompareWithPage($filter)->setOrder('id desc');
|
|
|
if ($date = Helper::getPostDate('date')) {
|
|
|
- $criteria->addBetweenCondition('create_date', $date, $date . ' 23:59:59');
|
|
|
+ $criteria->addBetweenCondition('t1.create_date', $date, $date . ' 23:59:59');
|
|
|
}
|
|
|
+ $criteria->setAlias('t1')->addCondition('t2.id > 0');
|
|
|
+ if ($this->type == 'canteen') {
|
|
|
+ $criteria->setSelect('t1.*,t2.name as second_name,t2.weixin,t2.phone');
|
|
|
+ } else {
|
|
|
+ $criteria->setSelect('t1.*,t2.name as second_name,t2.weixin,t2.phone,t2.position');
|
|
|
+ }
|
|
|
+ $criteria->join = "left join {$this->tableArr['table2']} t2 on t2.id = t1.{$this->tableArr['second_id']} and t2.is_del = 0";
|
|
|
$data = DB::getListWithCriteria($this->tableArr['table'], $criteria);
|
|
|
$data['records'] = $this->formatFollowList($data['records']);
|
|
|
Helper::ok($data);
|
|
|
@@ -238,16 +254,6 @@ class FollowController extends Controller
|
|
|
$cri = DbCriteria::simpleCompare(['id' => $firstIds])->setSelect('id,name');
|
|
|
$firsts = Helper::arrayColumn(DB::getListWithCriteria($this->tableArr['table1'], $cri), 'name', 'id');
|
|
|
}
|
|
|
- // 关系人
|
|
|
- $secondIds = array_unique(array_filter(array_column($list, $field2)));
|
|
|
- $seconds = [];
|
|
|
- if ($secondIds) {
|
|
|
- $cri = DbCriteria::simpleCompare(['id' => $secondIds])->setSelect('id,name,position,weixin,phone');
|
|
|
- if ($this->type == 'canteen') {
|
|
|
- $cri->setSelect('id,name,weixin,phone');
|
|
|
- }
|
|
|
- $seconds = Helper::arrayColumn(DB::getListWithCriteria($this->tableArr['table2'], $cri), null, 'id');
|
|
|
- }
|
|
|
foreach ($list as &$item) {
|
|
|
$uid = $item['user_id'];
|
|
|
$f1 = $item[$field1];
|
|
|
@@ -257,10 +263,7 @@ class FollowController extends Controller
|
|
|
$item['user_name'] = $users[$uid]['username'] ?? '';
|
|
|
$item['avatar'] = $users[$uid]['avatar'] ? Helper::getImageUrl($users[$uid]['avatar']) : '';
|
|
|
$item['first_name'] = $firsts[$f1] ?? '';
|
|
|
- $item['second_name'] = $seconds[$f2]['name'] ?? '';
|
|
|
- $item['position'] = $seconds[$f2]['position'] ?? '';
|
|
|
- $item['weixin'] = $seconds[$f2]['weixin'] ?? '';
|
|
|
- $item['phone'] = $seconds[$f2]['phone'] ?? '';
|
|
|
+ $item['position'] = $item['position'] ?? '';
|
|
|
}
|
|
|
return $list;
|
|
|
}
|