作者 jinglong
1 个管道 的构建 通过 耗费 1 秒

修改昵称图片问题

... ... @@ -64,8 +64,8 @@ class Order extends Backend
->select();
foreach ($list as $row) {
$row->getRelation('user')->visible(['nickname','avatar']);
$row->user->nickname = \app\admin\model\User::emoji_decode($row->user->nickname);
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
... ...
... ... @@ -52,6 +52,7 @@ class User extends Backend
->select();
foreach ($list as $k => $v) {
$v->hidden(['password', 'salt']);
$v->nickname = \app\admin\model\User::emoji_decode($v->nickname);
}
$result = array("total" => $total, "rows" => $list);
... ...
... ... @@ -191,6 +191,9 @@ trait Backend
}
$this->error(__('Parameter %s can not be empty', ''));
}
if(isset($row->nickname) && !empty($row->nickname)){
$row->nickname = \app\admin\model\User::emoji_decode($row->nickname);
}
$this->view->assign("row", $row);
return $this->view->fetch();
}
... ...
... ... @@ -101,4 +101,12 @@ class User extends Model
return $this->belongsTo('UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
//字符转表情
public static function emoji_decode($str){
$strDecode = preg_replace_callback('|\[\[EMOJI:(.*?)\]\]|', function ($matches) {
return rawurldecode($matches[1]);
}, $str);
return $strDecode;
}
}
... ...
... ... @@ -143,8 +143,8 @@
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
<!--<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>-->
<!--<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>-->
</div>
</div>
</form>
... ...
... ... @@ -76,6 +76,7 @@ class User extends Api
$ret = $this->auth->login($result);
if ($ret) {
$data = $this->auth->getUserinfo();
$data['nickname'] = $this->auth->emoji_decode($data['nickname']);
$this->success('登录成功', $data);
}else {
$this->error($this->auth->getError());
... ...
... ... @@ -215,6 +215,7 @@ class Auth
$userModel = new \app\admin\model\User();
$where = ['openid'=>$result['openid']];
$result['nickname'] = $this->emoji_encode($result['nickname']);
$ret = $userModel->where($where)->find();
if ($ret) {
$userModel->where($where)->update($result);
... ... @@ -650,4 +651,27 @@ class Auth
return $result;
}
//表情转字符
public function emoji_encode($str){
$strEncode = '';
$length = mb_strlen($str,'utf-8');
for ($i=0; $i < $length; $i++) {
$_tmpStr = mb_substr($str,$i,1,'utf-8');
if(strlen($_tmpStr) >= 4){
$strEncode .= '[[EMOJI:'.rawurlencode($_tmpStr).']]';
}else{
$strEncode .= $_tmpStr;
}
}
return $strEncode;
}
//字符转表情
public function emoji_decode($str){
$strDecode = preg_replace_callback('|\[\[EMOJI:(.*?)\]\]|', function ($matches) {
return rawurldecode($matches[1]);
}, $str);
return $strDecode;
}
}
... ...