Пример #1
0
 public function actionContactlist()
 {
     die;
     $user_id = Commonmodel::getOrganID();
     $sql = "select a.id,a.contact_user_id,a.customertype,\n\t\t   a.cooperationtype,a.name,a.sex,\n\t\t   a.companyname,a.phone,a.province,a.city,a.area,a.email,\n\t\t   a.weixin,a.QQ,a.create_time,a.Status,a.jiapart_ID,a.update_time,\n\t\t   \tcustomercategory as customercategorys ,\n\t\t   (select b.category from tbl_customer_category b where a.customercategory=b.id and a.user_id={$user_id}) as customercategory\n\t\t   from tbl_business_contacts a where \n\t\t   user_id='{$user_id}' and Status=0 ";
     if ($_POST) {
         $search['name'] = $_POST['name'];
         $search['phone'] = $_POST['phone'];
         $search['keyword'] = $_POST['keyword'];
         $search['group'] = $_POST['group'];
         if ($search) {
             if ($search['name']) {
                 $sql .= " and name like'%{$search['name']}%'";
             }
             if ($search['phone']) {
                 $sql .= " and phone like '%{$search['phone']}%'";
             }
             if ($search['keyword']) {
                 $sql .= " and (companyname like '%{$search['keyword']}%') ";
             }
             if ($search['group']) {
                 $sql .= " and id in(select ContactsID from tbl_business_contacts_relation where GroupID='{$search['group']}')";
             }
         }
     }
     $sql .= "order by create_time desc";
     $criteria = new CDbCriteria();
     // 		$criteria->addCondition("user_id = $user_id and  Status=0");
     // 		$criteria->order = "id DESC, update_time DESC";
     // 		//$pages->pageSize = 5;
     // 		$pages->applyLimit($criteria);
     // 		$models = BusinessContacts::model()->findAll($criteria);
     $models = Yii::app()->db->createCommand($sql)->queryAll();
     $count = count($models);
     $pages = new CPagination($count);
     $pages->pageSize = intval($_GET['rows']);
     $pages->applylimit($criteria);
     $models = Yii::app()->db->createCommand($sql . " LIMIT :offset,:limit");
     $models->bindValue(':offset', $pages->currentPage * $pages->pageSize);
     $models->bindValue(':limit', $pages->pageSize);
     $models = $models->queryAll();
     foreach ($models as $key => $value) {
         $iden = User::model()->findByPk($value['contact_user_id']);
         $data[$key]['organ'] = $iden['identity'];
         switch ($iden['identity']) {
             case 1:
                 $data[$key]['organ'] = '生产商';
                 $organName = MakeOrgan::getMakeName($value['contact_user_id']);
                 break;
             case 2:
                 $data[$key]['organ'] = '经销商';
                 $organName = Dealer::dealername($value['contact_user_id']);
                 break;
             case 3:
                 $data[$key]['organ'] = '修理厂';
                 $organName = Service::getservicename($value['contact_user_id']);
                 break;
             default:
                 $organName = '';
         }
         $data[$key]['id'] = $value['id'];
         $data[$key]['companyID'] = $value['contact_user_id'];
         $data[$key]['customertype'] = $value['customertype'];
         $data[$key]['cooperationtype'] = $value['cooperationtype'];
         $data[$key]['customercategory'] = $value['customercategory'];
         $data[$key]['customercategorys'] = $value['customercategorys'];
         $data[$key]['name'] = $value['name'];
         $data[$key]['sex'] = $value['sex'];
         if ($value['contact_user_id'] && $organName) {
             $data[$key]['companyname2'] = F::msubstr($organName);
             $data[$key]['companyname'] = $organName;
         } else {
             $data[$key]['companyname2'] = F::msubstr($value['companyname']);
             $data[$key]['companyname'] = $value['companyname'];
         }
         $data[$key]['phone'] = $value['phone'];
         $data[$key]['province'] = $value['province'];
         $data[$key]['city'] = $value['city'];
         $data[$key]['area'] = $value['area'];
         $data[$key]['address'] = F::msubstr(Area::getCity($value['province']) . Area::getCity($value['city']) . Area::getCity($value['area']));
         $data[$key]['email'] = $value['email'];
         $data[$key]['weixin'] = $value['weixin'];
         $data[$key]['QQ'] = $value['QQ'];
         $data[$key]['create_time'] = $value['create_time'];
         $data[$key]['Status'] = $value['Status'];
         $data[$key]['jiapart_ID'] = $value['jiapart_ID'];
         $data[$key]['update_time'] = $value['update_time'];
         //$data[$key]['checked']=true;
     }
     $rs = array('total' => $count, 'rows' => !empty($data) ? $data : array());
     echo json_encode($rs);
 }