Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zhupu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sugar
zhupu
Commits
5e254bbe
Commit
5e254bbe
authored
Sep 23, 2023
by
wuxiaoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推荐好友
parent
0f857d33
Pipeline
#749
canceled with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
21 deletions
+58
-21
application/api/controller/Friend.php
application/api/controller/Friend.php
+57
-20
application/common/library/Auth.php
application/common/library/Auth.php
+1
-1
No files found.
application/api/controller/Friend.php
View file @
5e254bbe
...
...
@@ -12,6 +12,7 @@ use app\api\model\FriendCommentModel;
use
app\api\model\FriendLikeModel
;
use
app\api\model\HotcircleModel
;
use
app\api\model\JoinCircle
;
use
app\api\model\UsersModel
;
use
app\common\controller\Api
;
use
fast\Tree
;
use
think\Db
;
...
...
@@ -345,29 +346,65 @@ class Friend extends Api{
* 随机推荐好友
*/
public
function
getRandomFriends
(){
$where
=
[
'user_id'
=>
[
'neq'
,
$this
->
auth
->
id
]];
$total
=
Db
::
name
(
'fastim_user'
)
->
where
(
$where
)
->
count
();
$min
=
Db
::
name
(
'fastim_user'
)
->
where
(
$where
)
->
min
(
'id'
);
//统计某个字段最小数据
$num
=
30
;
if
(
$total
<
$num
){
$num
=
$min
;}
$i
=
1
;
$flag
=
0
;
$ary
=
[];
while
(
$i
<=
$num
){
$rundnum
=
rand
(
$min
,
$total
);
//抽取随机数
if
(
$flag
!=
$rundnum
){
//过滤重复
if
(
!
in_array
(
$rundnum
,
$ary
)){
$ary
[]
=
$rundnum
;
$flag
=
$rundnum
;
}
else
{
$i
--
;
$type
=
$this
->
request
->
post
(
"type"
,
1
);
if
(
$type
==
1
){
//推荐
$where
=
[
'user_id'
=>
[
'neq'
,
$this
->
auth
->
id
]];
$total
=
Db
::
name
(
'fastim_user'
)
->
where
(
$where
)
->
count
();
$min
=
Db
::
name
(
'fastim_user'
)
->
where
(
$where
)
->
min
(
'id'
);
//统计某个字段最小数据
$num
=
30
;
if
(
$total
<
$num
){
$num
=
$min
;}
$i
=
1
;
$flag
=
0
;
$ary
=
[];
while
(
$i
<=
$num
){
$rundnum
=
rand
(
$min
,
$total
);
//抽取随机数
if
(
$flag
!=
$rundnum
){
//过滤重复
if
(
!
in_array
(
$rundnum
,
$ary
)){
$ary
[]
=
$rundnum
;
$flag
=
$rundnum
;
}
else
{
$i
--
;
}
$i
++
;
}
$i
++
;
}
$map
[
'id'
]
=
[
'in'
,
$ary
];
}
else
{
if
(
$type
==
2
){
//同姓
$where
[
'surname_id'
]
=
$this
->
auth
->
surname_id
;
}
else
if
(
$type
==
3
){
//同乡
$where
[
'village_id'
]
=
$this
->
auth
->
village_id
;
}
else
if
(
$type
==
4
){
//同校
$educational
=
UsersModel
::
where
([
'id'
=>
$this
->
auth
->
id
])
->
value
(
"educational"
);
$school
=
array_column
(
json_decode
(
$educational
),
"school"
);
$where
=
''
;
foreach
(
$school
as
$k
=>
$v
){
if
(
$k
==
0
){
$where
=
" educational like '%"
.
$v
.
"%'"
;
}
else
{
$where
=
$where
.
" OR educational like '%"
.
$v
.
"%'"
;
}
}
}
else
if
(
$type
==
5
){
//同事
$work_experience
=
UsersModel
::
where
([
'id'
=>
$this
->
auth
->
id
])
->
value
(
"work_experience"
);
$company
=
array_column
(
json_decode
(
$work_experience
),
"company"
);
$where
=
''
;
foreach
(
$company
as
$k
=>
$v
){
if
(
$k
==
0
){
$where
=
" work_experience like '%"
.
$v
.
"%'"
;
}
else
{
$where
=
$where
.
" OR work_experience like '%"
.
$v
.
"%'"
;
}
}
}
$ids
=
UsersModel
::
where
(
$where
)
->
column
(
"id"
);
$map
[
'user_id'
]
=
[
'in'
,
$ids
];
}
$list
=
Db
::
name
(
'fastim_user'
)
->
where
(
$where
)
->
where
([
'id'
=>
[
'in'
,
$ary
]])
->
select
();
$this
->
success
(
'操作成功'
,[
'list'
=>
$list
]);
$list
=
Db
::
name
(
'fastim_user'
)
->
where
([
'user_id'
=>
[
'neq'
,
$this
->
auth
->
id
]])
->
where
(
$map
)
->
limit
(
30
)
->
select
();
$this
->
success
(
'操作成功'
,[
'list'
=>
$list
]);
}
}
\ No newline at end of file
application/common/library/Auth.php
View file @
5e254bbe
...
...
@@ -29,7 +29,7 @@ class Auth
//默认配置
protected
$config
=
[];
protected
$options
=
[];
protected
$allowFields
=
[
'id'
,
'username'
,
'nickname'
,
'mobile'
,
'avatar'
,
'score'
,
'prevtime'
,
'wx_openid'
,
'app_openid'
,
'unionid'
,
'money'
,
'level'
,
'is_shaikh'
,
'commission'
,
'agent_money'
,
'province_id'
,
'city_id'
,
'area_id'
,
'town_id'
,
'village_id'
];
protected
$allowFields
=
[
'id'
,
'username'
,
'surname_id'
,
'nickname'
,
'mobile'
,
'avatar'
,
'score'
,
'prevtime'
,
'wx_openid'
,
'app_openid'
,
'unionid'
,
'money'
,
'level'
,
'is_shaikh'
,
'commission'
,
'agent_money'
,
'province_id'
,
'city_id'
,
'area_id'
,
'town_id'
,
'village_id'
];
public
function
__construct
(
$options
=
[])
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment