where(['user_id' => $user_id, 'to_user_id' => $to_user_id])->find()) { $res = $this->where('id', $info['id'])->update(['nickname_remark' => $remark, 'updatetime' => time()]); } else { $res = $this->insert(['user_id' => $user_id, 'to_user_id' => $to_user_id, 'nickname_remark' => $remark, 'updatetime' => time()]); } if (!$res) { return [false, '设置失败']; } return [true, '设置成功']; } /** * 删除备注 * @param int $user_id * @param int $to_user_id * @return array */ public function delRemark(int $user_id, int $to_user_id) { if ($info = $this->where(['user_id' => $user_id, 'to_user_id' => $to_user_id])->find()) { $res = $this->where('id', $info['id'])->update(['nickname_remark' => '', 'updatetime' => time()]); if (!$res) { return [false, '设置失败']; } } return [true, '设置成功']; } }