add:增加影圈功能,优化部分接口
This commit is contained in:
@@ -439,15 +439,60 @@ class User extends Common
|
||||
if (!isset($params['status'])) {
|
||||
$this->error('缺少参数:status');
|
||||
}
|
||||
$relation = Relation::get(['user_id' => $this->auth->id, 'target_id' => $params['user_id']]);
|
||||
if (empty($relation)) {
|
||||
$relation = new Relation;
|
||||
$ids = explode(',', $params['user_id']);
|
||||
if (empty($ids)) {
|
||||
$this->error('缺少参数:user_id');
|
||||
}
|
||||
$relation->allowField(true)->save([
|
||||
'target_id' => $params['user_id'],
|
||||
'user_id' => $this->auth->id,
|
||||
'status' => $params['status'],
|
||||
]);
|
||||
foreach ($ids as $id) {
|
||||
if ($id == $this->auth->id) {
|
||||
$this->error('不能设置与自己的好友关系');
|
||||
}
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$dbUserId = UserModel::where('id', 'IN', $ids)->column('id');
|
||||
if (!empty($diffId = array_diff($ids, $dbUserId))) {
|
||||
return $this->error('用户不存在:' . implode(',', $diffId));
|
||||
}
|
||||
$res = Relation::where('user_id', $this->auth->id)->where('target_id', 'IN', $ids)->update(['status' => $params['status']]);
|
||||
if ($res < count($ids)) {
|
||||
$target = Relation::where('user_id', $this->auth->id)->where('target_id', 'IN', $ids)->column("target_id");
|
||||
$_relationModel = new Relation;
|
||||
foreach ((array_diff($ids, $target)) as $id) {
|
||||
(clone $_relationModel)->allowField(true)->save([
|
||||
'user_id' => $this->auth->id,
|
||||
'target_id' => $id,
|
||||
'status' => $params['status'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->success('Success');
|
||||
}
|
||||
|
||||
// 获取关系列表
|
||||
public function list()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$query = Relation::alias('r')
|
||||
->join([UserModel::$tableName => 'u'], 'u.id=r.target_id')
|
||||
->field('r.*,u.avatar,u.gender,u.nickname')
|
||||
->where('user_id', $this->auth->id);
|
||||
if (isset($params['status'])) {
|
||||
$query->where('r.status', $params['status']);
|
||||
} else {
|
||||
$query->where('r.status', '<>', 0);
|
||||
}
|
||||
$list = $query->select();
|
||||
foreach ($list as &$l) {
|
||||
$l['content'] = json_decode($l['content'] ?? '[]', true);
|
||||
}
|
||||
|
||||
$this->success('Success', $list);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user