<?php
/**
*
* @authors ZL
* @email 987968469@qq.com
* @date 2017-12-14 11:23:35
*/
namespace app\contact\model;
use think\Model;
use think\Db;
use contact\Contact as ContactName;
use Overtrue\Pinyin\Pinyin;
class Contact extends Model {
/**
* 河長(zhǎng)通訊錄
* @return bool|\think\response\Json
*/
public function getContactList(){
$data = Db::name('admin_user')->alias('au')
->join('river_level rl','au.level = rl.id','left')
->field(['au.id userId','au.user_name userName','au.mobile','rl.level_name levelName','au.department','au.position','au.department_tel'])
->where("au.status",1)
->order('CONVERT(au.user_name USING gbk)')
->select()
;//Dump($data);die;
//舊方法獲取首字母奶赠,有些字獲取不到
// $firstName = new ContactName;
// 小內(nèi)存型
$pinyin = new Pinyin(); // 默認(rèn)
// 內(nèi)存型
// $pinyin = new Pinyin('Overtrue\Pinyin\MemoryFileDictLoader');
// I/O型
// $pinyin = new Pinyin('Overtrue\Pinyin\GeneratorFileDictLoader');
$aaa = $bbb = $ccc = array();
foreach($data as $k => $v){
$firstPinYin = $pinyin->name(mb_substr(trim($v['userName']), 0,1));
$firstCharacter = strtoupper(substr($firstPinYin[0], 0, 1)) ;
//$firstCharacter = $firstName->_getFirstCharacter($v['userName']);
if(in_array($firstCharacter,$bbb)){
array_push($ccc,$v);
$bbb['contact'] = $ccc;
}else{
array_push($aaa,$bbb);
$bbb['firstPY'] = $firstCharacter;
$ccc = array();
array_push($ccc,$v);
$bbb['contact'] = $ccc;
}
}
array_push($aaa,$bbb);
array_shift($aaa);
return $aaa;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者