CommonController.php 4.4 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\user\controller;

use app\user\model\CommentModel;
use cmf\controller\AdminBaseController;
use cmf\controller\UserBaseController;
use app\user\model\UserModel;
use think\Db;


class CommonController extends AdminBaseController
{



    //    中介评价
    public function comment(){
        $data = $this->request->param();
        $size = 10;
        if(empty($data['page'])){
            $data['page'] = 1;
        }
        $page = $data['page'];
        $where_comment['m.status'] = 1;
        $arr = array();
        if($data){
            $startTime = empty($data['start_time']) ? 0 : strtotime($data['start_time']);
            $endTime   = empty($data['end_time']) ? 0 : strtotime($data['end_time']);
            if ($startTime && $endTime) {
                $arr['start_time'] = $data['start_time'];
                $arr['end_time'] = $data['end_time'];
                $where_comment['c.create_time'] = array('between',"$startTime,$endTime");
                $this->assign('start_time', $data['start_time']);
                $this->assign('end_time', $data['end_time']);
            }else{
                if($startTime){
                    $arr['start_time'] = $data['start_time'];
                    $where_comment['c.create_time'] = array('egt',$startTime);
                    $this->assign('start_time', $data['start_time']);
                }
                if($endTime){
                    $arr['end_time'] = $data['end_time'];
                    $where_comment['c.create_time'] = array('elt',$endTime);
                    $this->assign('end_time', $data['end_time']);
                }
            }

            if(!empty($data['name'])){
                $arr['name'] = $data['name'];
                $where_comment['m.name'] = array('like','%'.$data['name'].'%');
                $this->assign('name', $data['name']);
            }
            if(!empty($data['tel'])){
                $arr['tel'] = $data['tel'];
                $where_comment['m.tel'] = array('like','%'.$data['tel'].'%');
                $this->assign('tel', $data['tel']);
            }
        }
        $comment_list = Db::name('Comment')->alias('c')
            ->join("Member m",'m.id=c.user_id')
            ->where($where_comment)
            ->field('m.name as user_name,m.tel as user_tel,m.id as user_id,c.*')
            ->limit($size)->page($page)
            ->select()->toArray();
        $count = Db::name('Comment')->alias('c')
            ->join("Member m",'m.id=c.user_id')
            ->where($where_comment)
            ->count();
        $all_page = ceil($count/$size);
        foreach ($comment_list as $comk=>$comv){
            $where_agency['id'] = $comv['intermediary_id'];
            $agency = Db::name('Member')->where($where_agency)->field('id,name,tel')->find();
            $comment_list[$comk]['agency_id'] = $agency['id'];
            $comment_list[$comk]['agency_name'] = $agency['name'];
            $comment_list[$comk]['agency_tel'] = $agency['tel'];
        }
        $this->assign('count', $count);
        $this->assign('page', $all_page);
        $this->assign('lists',$comment_list);
        return $this->fetch('common');
    }

//    删除中介评价
    public function agencyDel(){
        $data = $this->request->param();
        $where_com['id'] = $data['id'];
        $where_com['status'] = array('neq',9);
        $complaint = Db::name('Comment')->where($where_com)->find();
        if($complaint){
            $save['status'] = 9;
            $save['update_time'] = time();
            $update = Db::name('Comment')->where($where_com)->update($save);
            if($update){
                $this->success('删除成功');
            }else{
                $this->error('删除失败');
            }
        }else{
            $this->error('评论状态错误');
        }
    }


}