no message

This commit is contained in:
kuaifan 2022-11-21 14:00:19 +08:00
parent 542e3b9a49
commit 66c8a4db23
8 changed files with 45 additions and 24 deletions

View File

@ -503,7 +503,7 @@ class DialogController extends AbstractController
$user = User::auth();
//
$id = Request::input('id');
$ids = Base::arrayRetainInt(is_array($id) ? $id : Base::explodeInt($id));
$ids = Base::explodeInt($id);
//
WebSocketDialogMsg::whereIn('id', $ids)->chunkById(20, function($list) use ($user) {
/** @var WebSocketDialogMsg $item */

View File

@ -497,7 +497,7 @@ class ReportController extends AbstractController
}
if (is_string($ids)) {
$ids = explode(",", $ids);
$ids = Base::explodeInt($ids);
}
$data = Report::with(["receivesUser" => function (BelongsToMany $query) use ($user) {

View File

@ -214,6 +214,7 @@ class UsersController extends AbstractController
{
"userid": 1,
"identity": [ ],
"department": [ ],
"az": "",
"email": "admin@admin.com",
"nickname": "admin",
@ -234,6 +235,7 @@ class UsersController extends AbstractController
//
$data = $user->toArray();
$data['nickname_original'] = $user->getRawOriginal('nickname');
$data['department_name'] = $user->getDepartmentName();
return Base::retSuccess('success', $data);
}
@ -638,6 +640,9 @@ class UsersController extends AbstractController
if (!is_array($data['department'])) {
$data['department'] = [];
}
if (count($data['department']) > 10) {
return Base::retError('最多只可加入10个部门');
}
foreach ($data['department'] as $id) {
if (!UserDepartment::whereId($id)->exists()) {
return Base::retError('修改部门不存在');
@ -791,7 +796,7 @@ class UsersController extends AbstractController
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据(同"获取我的信息"接口)
* @apiSuccess {Object} data 返回数据
*/
public function email__verification()
{
@ -839,7 +844,7 @@ class UsersController extends AbstractController
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据(同"获取我的信息"接口)
* @apiSuccess {Object} data 返回数据
*/
public function umeng__alias()
{

View File

@ -145,7 +145,24 @@ class User extends AbstractModel
if (empty($value)) {
return [];
}
return array_filter(is_array($value) ? $value : explode(",", trim($value, ",")));
return array_filter(is_array($value) ? $value : Base::explodeInt($value));
}
/**
* 获取所属部门名称
* @return string
*/
public function getDepartmentName()
{
if (empty($this->department)) {
return "";
}
$list = UserDepartment::select(['id', 'owner_userid', 'name'])->whereIn('id', $this->department)->take(10)->get();
$array = [];
foreach ($list as $item) {
$array[] = $item->name . ($item->owner_userid === $this->userid ? '(M)' : '');
}
return implode(', ', $array);
}
/**
@ -213,7 +230,9 @@ class User extends AbstractModel
'userid' => $this->userid,
'email' => $this->email,
'reason' => $reason,
'cache' => $this->getRawOriginal()
'cache' => array_merge($this->getRawOriginal(), [
'department_name' => $this->getDepartmentName()
])
]);
$userDelete->save();
// 删除未读
@ -478,12 +497,7 @@ class User extends AbstractModel
$userInfo = self::whereUserid($userid)->select(User::$basicField)->first();
if ($userInfo) {
$userInfo->online = $userInfo->getOnlineStatus();
$departments = [];
$list = UserDepartment::select(['id', 'owner_userid', 'name'])->whereIn('id', $userInfo->department)->get();
foreach ($list as $item) {
$departments[] = $item->name . ($item->owner_userid === $userid ? '(M)' : '');
}
$userInfo->department_name = implode(', ', $departments);
$userInfo->department_name = $userInfo->getDepartmentName();
}
return $_A["__static_userid2basic_" . $userid] = ($userInfo ?: []);
}

View File

@ -53,6 +53,8 @@ class UserDelete extends AbstractModel
$name = ($value['userid'] - 1) % 21 + 1;
$value['userimg'] = url("images/avatar/default_{$name}.png");
}
// 部门
$value['department'] = array_filter(is_array($value['department']) ? $value['department'] : Base::explodeInt($value['department']));
}
return $value;
}
@ -69,9 +71,8 @@ class UserDelete extends AbstractModel
return null;
}
$cache = $row->cache;
$cache = array_intersect_key($cache, array_flip(User::$basicField));
$cache = array_intersect_key($cache, array_flip(array_merge(User::$basicField, ['department_name'])));
$cache['delete_at'] = $row->created_at->format($row->dateFormat ?: 'Y-m-d H:i:s');
$cache['department_name'] = $cache['department'] ? UserDepartment::whereIn('id', $cache['department'])->pluck('name')->implode(',') : '';
return $cache;
}
}

View File

@ -873,30 +873,31 @@ class Base
* 打散字符串,只留为数字的项
* @param $delimiter
* @param $string
* @param bool $reInt 是否格式化值
* @return array
*/
public static function explodeInt($delimiter, $string = null)
public static function explodeInt($delimiter, $string = null, $reInt = true)
{
if ($string == null) {
$string = $delimiter;
$delimiter = ',';
}
$array = is_array($string) ? $string : explode($delimiter, $string);
return self::arrayRetainInt($array);
return self::arrayRetainInt($array, $reInt);
}
/**
* 数组只保留数字的
* @param $array
* @param bool $int 是否格式化值
* @param bool $reInt 是否格式化值
* @return array
*/
public static function arrayRetainInt($array, $int = false)
public static function arrayRetainInt($array, $reInt = false)
{
foreach ($array as $k => $v) {
if (!is_numeric($v)) {
unset($array[$k]);
} elseif ($int === true) {
} elseif ($reInt === true) {
$array[$k] = intval($v);
}
}

View File

@ -25,7 +25,7 @@ class ProjectLogsRecordUserid extends Migration
foreach ($lists as $log) {
$record = $log->record;
if (is_string($record['userid']) && str_contains($record['userid'], ",")) {
$record['userid'] = Base::explodeInt(',', $record['userid']);
$record['userid'] = Base::explodeInt($record['userid']);
$log->record = Base::array2json($record);
$log->save();
}

View File

@ -199,10 +199,10 @@
<Form :model="departmentEditData" label-width="auto" @submit.native.prevent>
<Alert type="error" style="margin-bottom:18px">{{$L(`正在进行帐号【ID:${departmentEditData.userid}${departmentEditData.nickname}】部门修改。`)}}</Alert>
<FormItem :label="$L('原部门')">
<div>{{departmentEditData.old || '-'}}</div>
<div style="line-height:24px;padding:4px 0" v-html="departmentEditData.old || '-'"></div>
</FormItem>
<FormItem :label="$L('修改部门')">
<Select v-model="departmentEditData.department" multiple :placeholder="$L('留空为默认部门')">
<Select v-model="departmentEditData.department" multiple :multiple-max="10" :placeholder="$L('留空为默认部门')">
<Option v-for="(item, index) in departmentList" :value="item.id" :key="index">{{ item.name }}</Option>
</Select>
</FormItem>
@ -718,7 +718,7 @@ export default {
row.department.some(did => {
const data = this.departmentList.find(d => d.id == did)
if (data) {
departments.push(data.name)
departments.push(data.owner_userid === row.userid ? `${data.name} (${this.$L('负责人')})` : data.name)
}
})
this.departmentEditData = {
@ -726,7 +726,7 @@ export default {
userid: row.userid,
nickname: row.nickname,
department: row.department.map(id => parseInt(id)),
old: departments.join(", ")
old: departments.join("<br/>")
};
this.departmentEditShow = true;
break;