作者 zhangwei
... ... @@ -180,31 +180,41 @@ class LoginController extends HomeBaseController
public function myCollection(){
$limit = $this->limit;
$uid = cmf_get_current_user_id();
$collectionModel = new CollectionModel();
$res = $collectionModel
->where(['uid'=>$uid])
->field('id,post_id,category_name,city_name,post_url')
->order('id desc')
// $collectionModel = new CollectionModel();
// $res = $collectionModel
// ->where(['uid'=>$uid])
// ->field('id,post_id,category_name,city_name,post_url')
// ->order('id desc')
// ->paginate($limit);
$res = Db::name('collection')
->alias('c')
->join('portal_post p','c.post_id = p.id')
->where(['c.uid'=>$uid,'p.delete_time'=>0])
->field('c.id,c.category_name,c.city_name,c.post_url,p.post_title,p.post_excerpt,p.post_favorites')
->order('c.id desc')
->paginate($limit);
$data = $res->toArray();
$page = $res->render();
$post_ids = array_unique(array_column($data['data'],'post_id'));
$data1 = Db::name('portal_post')
->whereIn('id',$post_ids)
->where('delete_time', 0)
->field('id,post_title,post_excerpt,post_favorites')
->order('weigh desc')
->select()
->toArray();
foreach($data['data'] as &$value){
foreach ($data1 as $item) {
if($value['post_id'] == $item['id']){
$value['post_title'] = $item['post_title'];
$value['post_excerpt'] = $item['post_excerpt'];
$value['post_favorites'] = $item['post_favorites'];
}
}
}
// $post_ids = array_unique(array_column($data['data'],'post_id'));
// $data1 = Db::name('portal_post')
// ->whereIn('id',$post_ids)
// ->where('delete_time', 0)
// ->field('id,post_title,post_excerpt,post_favorites')
// ->order('weigh desc')
// ->select()
// ->toArray();
// foreach($data['data'] as &$value){
// $value['post_title'] = '';
// $value['post_excerpt'] = '';
// $value['post_favorites'] = '';
// foreach ($data1 as $item) {
// if($value['post_id'] == $item['id']){
// $value['post_title'] = $item['post_title'];
// $value['post_excerpt'] = $item['post_excerpt'];
// $value['post_favorites'] = $item['post_favorites'];
// }
// }
// }
$this->assign('res',$data['data']);
$this->assign('page',$page);
return $this->fetch();
... ...