Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projecttwo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangtao
projecttwo
Commits
d7fa8090
Commit
d7fa8090
authored
May 16, 2025
by
wangzhengwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目模块
parent
7c4b1db5
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
548 additions
and
42 deletions
+548
-42
Cert.php
app/api/controller/mine/Cert.php
+10
-0
Project.php
app/api/controller/mine/Project.php
+162
-0
Project.php
app/api/controller/project/Project.php
+78
-0
ProjectPut.php
app/api/controller/project/ProjectPut.php
+42
-0
UtilService.php
app/api/service/UtilService.php
+53
-7
ProjectValidate.php
app/api/validate/ProjectValidate.php
+25
-0
Cert.php
app/model/Cert.php
+3
-35
Project.php
app/model/Project.php
+57
-0
ProjectCategory.php
app/model/ProjectCategory.php
+21
-0
ProjectPut.php
app/model/ProjectPut.php
+19
-0
ProjectTag.php
app/model/ProjectTag.php
+10
-0
UserMoneyLog.php
app/model/project/UserMoneyLog.php
+68
-0
No files found.
app/api/controller/mine/Cert.php
0 → 100644
View file @
d7fa8090
<?php
namespace
app\api\controller\mine
;
use
app\BaseController
;
class
Cert
extends
BaseController
{
}
\ No newline at end of file
app/api/controller/mine/Project.php
0 → 100644
View file @
d7fa8090
<?php
namespace
app\api\controller\mine
;
use
app\api\middleware\Auth
;
use
app\api\service\UserService
;
use
app\api\validate\ProjectValidate
;
use
app\BaseController
;
use
app\model\Project
as
ProjectModel
;
use
app\model\ProjectPut
;
use
think\Request
;
class
Project
extends
BaseController
{
protected
$middleware
=
[
Auth
::
class
,
];
// 状态映射关系
const
STATUS_MAP
=
[
'apply'
=>
[
0
=>
'申请中'
,
1
=>
'申请失败'
,
2
=>
'申请成功'
],
'complete'
=>
[
0
=>
'未上传'
,
1
=>
'验收中'
,
2
=>
'验收失败'
,
3
=>
'验收成功'
]
];
const
PROGRESS_RULES
=
[
'apply'
=>
[
0
=>
10
,
// 申请中
1
=>
0
,
// 申请失败
2
=>
20
// 申请成功
],
'complete'
=>
array
(
0
=>
0
,
// 未上传
1
=>
60
,
// 验收中
2
=>
80
,
// 验收失败
3
=>
100
// 验收成功
)
];
public
function
getProjectList
(
Request
$request
)
{
$page
=
$request
->
param
(
'page/d'
,
1
);
$pageSize
=
$request
->
param
(
'pageSize/d'
,
10
);
$data
=
$request
->
param
();
$where
=
[
'pp.user_id'
=>
$request
->
userId
];
if
(
!
empty
(
$data
[
'status'
]))
{
$where
[
'pp.status'
]
=
$data
[
'status'
];
}
if
(
!
empty
(
$data
[
'complete_status'
]))
{
$where
[
'pp.complete_status'
]
=
$data
[
'complete_status'
];
}
$query
=
ProjectPut
::
where
(
$where
)
->
alias
(
'pp'
)
->
join
(
'project p'
,
'p.id = pp.project_id'
)
->
field
([
'pp.*'
,
'p.title'
,
'p.sn'
,
'p.id as project_id'
])
->
with
([
'project'
=>
[
'getuserdata'
]]);
if
(
!
empty
(
$data
[
'search_str'
]))
{
$searchStr
=
trim
(
$data
[
'search_str'
]);
$query
->
where
(
function
(
$q
)
use
(
$searchStr
)
{
$q
->
where
(
'p.title|p.sn'
,
'like'
,
"%
{
$searchStr
}
%"
);
});
}
$list
=
$query
->
paginate
([
'page'
=>
$page
,
'list_rows'
=>
$pageSize
]);
// 处理结果集
// 添加调试信息
$list
->
each
(
function
(
$item
)
{
$applyProgress
=
self
::
PROGRESS_RULES
[
'apply'
][
$item
->
status
]
??
0
;
$completeProgress
=
(
$item
->
status
==
2
)
?
(
self
::
PROGRESS_RULES
[
'complete'
][
$item
->
complete_status
]
??
0
)
:
0
;
$item
->
progress
=
max
(
1
,
min
(
100
,
$applyProgress
+
$completeProgress
));
// 调试信息
// $item->debug = [
// 'status' => $item->status,
// 'complete_status' => $item->complete_status,
// 'apply_progress' => $applyProgress,
// 'complete_progress' => $completeProgress,
// 'final_progress' => $item->progress
// ];
return
$item
;
});
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
}
public
function
getProjectDetail
(
Request
$request
)
{
$vo
=
(
new
ProjectValidate
())
->
goCheck
([
'project_put_id'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$data
=
$request
->
param
();
$item
=
ProjectPut
::
where
([
'id'
=>
$data
[
'project_put_id'
],
'user_id'
=>
$request
->
userId
])
->
with
([
'project'
])
->
find
();
$applyProgress
=
self
::
PROGRESS_RULES
[
'apply'
][
$item
->
status
]
??
0
;
$completeProgress
=
(
$item
->
status
==
2
)
?
(
self
::
PROGRESS_RULES
[
'complete'
][
$item
->
complete_status
]
??
0
)
:
0
;
$item
->
progress
=
max
(
1
,
min
(
100
,
$applyProgress
+
$completeProgress
));
return
$this
->
returnMsg
(
'success'
,
1
,
$item
);
}
//项目提交
public
function
putProject
(
Request
$request
)
{
$vo
=
(
new
ProjectValidate
())
->
goCheck
([
'project_put_id'
,
'complete_file_id_str'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$data
=
$request
->
param
();
$count
=
ProjectPut
::
where
([
'id'
=>
$data
[
'project_put_id'
],
'user_id'
=>
$request
->
userId
,
'complete_status'
=>
0
])
->
count
();
if
(
!
$count
)
{
return
$this
->
returnMsg
(
'项目不存在或已有提交记录'
);
}
$update
=
[
'complete_status'
=>
1
,
'complete_post_time'
=>
time
(),
'complete_file_id_str'
=>
$data
[
'complete_file_id_str'
]];
ProjectPut
::
where
(
'id'
,
$data
[
'project_put_id'
])
->
update
(
$update
);
return
$this
->
returnMsg
(
'success'
,
1
);
}
}
\ No newline at end of file
app/api/controller/project/Project.php
0 → 100644
View file @
d7fa8090
<?php
namespace
app\api\controller\project
;
use
app\api\service\UserService
;
use
app\api\validate\ProjectValidate
;
use
app\BaseController
;
use
app\model\project\UserMoneyLog
;
use
think\Request
;
use
app\model\ProjectCategory
;
use
app\model\Project
as
ProjectModel
;
class
Project
extends
BaseController
{
//项目分类列表
public
function
getProjectCategoryList
()
{
$list
=
(
new
ProjectCategory
())
->
getProjectCategoryList
();
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
}
//项目列表
public
function
getProjectList
(
Request
$request
)
{
$vo
=
(
new
ProjectValidate
())
->
goCheck
([
'category_id'
,
'type'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$data
=
$request
->
param
();
$page
=
$request
->
param
(
'page/d'
,
1
);
$pageSize
=
$request
->
param
(
'pageSize/d'
,
10
);
$list
=
(
new
ProjectModel
())
->
getProjectList
(
$data
[
'category_id'
],
$page
,
$pageSize
,
$data
[
'type'
]);
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
}
public
function
rankProjectList
(
Request
$request
)
{
$limit
=
$request
->
param
(
'limit/d'
,
1
);
$type
=
$request
->
param
(
'type'
,
'day'
);
$list
=
UserMoneyLog
::
getUserMoneyRanking
(
$limit
,
$type
,
0
);
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
}
public
function
getProjectDetail
(
Request
$request
)
{
$vo
=
(
new
ProjectValidate
())
->
goCheck
([
'project_id'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$data
=
$request
->
param
();
$userId
=
0
;
$token
=
$request
->
header
(
'token'
);
if
(
$token
)
{
$userId
=
UserService
::
getUserInfo
(
$token
)[
'id'
];
}
$detail
=
(
new
ProjectModel
())
->
projectDetail
(
$data
[
'project_id'
],
$userId
);
return
$this
->
returnMsg
(
'success'
,
1
,
$detail
);
}
}
\ No newline at end of file
app/api/controller/project/ProjectPut.php
0 → 100644
View file @
d7fa8090
<?php
namespace
app\api\controller\project
;
use
app\api\middleware\Auth
;
use
app\api\validate\ProjectValidate
;
use
app\BaseController
;
use
think\Request
;
use
app\model\ProjectPut
as
ProjectPutModel
;
class
ProjectPut
extends
BaseController
{
protected
$middleware
=
[
Auth
::
class
,
];
public
function
projectPut
(
Request
$request
)
{
$vo
=
(
new
ProjectValidate
())
->
goCheck
([
'project_id'
,
'user_desc'
,
'file_id_str'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$data
=
$request
->
only
([
'project_id'
,
'user_desc'
,
'file_id_str'
]);
$count
=
ProjectPutModel
::
where
([
'project_id'
=>
$data
[
'project_id'
],
'user_id'
=>
$request
->
userId
])
->
count
();
if
(
$count
)
{
return
$this
->
returnMsg
(
'不可重复提交'
);
}
(
new
ProjectPutModel
())
->
putProject
(
$data
,
$request
->
userId
);
return
$this
->
returnMsg
(
'success'
,
1
);
}
}
\ No newline at end of file
app/api/service/UtilService.php
View file @
d7fa8090
...
...
@@ -4,18 +4,64 @@ namespace app\api\service;
class
UtilService
{
public
static
function
generateOrderNo
(
$userId
=
0
,
$str
=
null
)
{
$microtime
=
microtime
(
true
);
$timestamp
=
date
(
'YmdHis'
)
.
substr
(
$microtime
,
11
,
3
);
// public static function generateOrderNo($userId = 0,$str=null)
// {
// $microtime = microtime(true);
// $timestamp = date('YmdHis') . substr($microtime, 11, 3);
//
//
// $random = str_pad(mt_rand(0, 999999), 6, '0', STR_PAD_LEFT);
//
//
// $userPart = $userId ? substr(str_pad($userId, 4, '0', STR_PAD_LEFT), -4) : '';
//
//
// return $str.'-'. $timestamp . $random . ($userPart ? ('-' . $userPart) : '');
// }
public
static
function
generateCompactOrderNo
(
$userId
=
null
,
$str
=
null
)
{
$time
=
substr
(
time
(),
-
6
);
// 取时间戳后6位
$rand
=
mt_rand
(
100000
,
999999
);
// 6位随机数
$user
=
$userId
?
chr
(
65
+
(
$userId
%
26
))
:
''
;
// 用户标识转A-Z
$random
=
str_pad
(
mt_rand
(
0
,
999999
),
6
,
'0'
,
STR_PAD_LEFT
);
return
$str
.
$user
.
$time
.
$rand
;
}
public
static
function
listWithTags
(
$list
,
string
$modelClass
,
string
$tagIdsField
=
'tag_ids'
)
:
array
{
$allTagIds
=
[];
foreach
(
$list
->
items
()
as
$item
)
{
if
(
!
empty
(
$item
->
{
$tagIdsField
}))
{
$tagIds
=
explode
(
','
,
$item
->
{
$tagIdsField
});
$allTagIds
=
array_merge
(
$allTagIds
,
$tagIds
);
}
}
$userPart
=
$userId
?
substr
(
str_pad
(
$userId
,
4
,
'0'
,
STR_PAD_LEFT
),
-
4
)
:
''
;
$tags
=
[];
if
(
!
empty
(
$allTagIds
))
{
$tags
=
$modelClass
::
where
(
'is_del'
,
0
)
->
whereIn
(
'id'
,
array_unique
(
$allTagIds
))
->
field
(
'id,title'
)
->
select
()
->
toArray
();
$tags
=
array_column
(
$tags
,
null
,
'id'
);
}
$result
=
$list
->
toArray
();
foreach
(
$result
[
'data'
]
as
&
$item
)
{
$itemTags
=
[];
if
(
!
empty
(
$item
[
$tagIdsField
]))
{
$tagIds
=
explode
(
','
,
$item
[
$tagIdsField
]);
foreach
(
$tagIds
as
$tagId
)
{
if
(
isset
(
$tags
[
$tagId
]))
{
$itemTags
[]
=
$tags
[
$tagId
];
}
}
}
$item
[
'tags'
]
=
$itemTags
;
}
return
$
str
.
'-'
.
$timestamp
.
$random
.
(
$userPart
?
(
'-'
.
$userPart
)
:
''
)
;
return
$
result
;
}
}
\ No newline at end of file
app/api/validate/ProjectValidate.php
0 → 100644
View file @
d7fa8090
<?php
namespace
app\api\validate
;
class
ProjectValidate
extends
BaseValidate
{
protected
$rule
=
[
'searchKeyWords'
=>
'require'
,
'category_id'
=>
'require|number'
,
'project_id'
=>
'require|number'
,
'type'
=>
'require|number'
,
'name'
=>
'require'
,
'idcard'
=>
'require|number'
,
'idcard_q'
=>
'require|number'
,
'idcard_h'
=>
'require|number'
,
'mobile'
=>
'require|mobile'
,
'email'
=>
'require|email'
,
'head_img_id'
=>
'require|number'
,
'other_file_id'
=>
'require|number'
,
'pay_type'
=>
'require|number'
,
'project_put_id'
=>
'require|number'
,
'complete_file_id_str'
=>
'require'
,
];
}
\ No newline at end of file
app/model/Cert.php
View file @
d7fa8090
...
...
@@ -10,6 +10,7 @@
namespace
app\model
;
use
app\api\service\UtilService
;
use
\app\model\CertCategory
;
use
app\model\system\SystemUploadFile
;
use
think\facade\Db
;
...
...
@@ -97,42 +98,9 @@ class Cert extends Model
return
$list
;
}
// 收集所有tag_ids
$allTagIds
=
[];
foreach
(
$list
->
items
()
as
$item
)
{
if
(
!
empty
(
$item
->
tag_ids
))
{
$tagIds
=
explode
(
','
,
$item
->
tag_ids
);
$allTagIds
=
array_merge
(
$allTagIds
,
$tagIds
);
}
}
// 批量查询所有标签
$tags
=
[];
if
(
!
empty
(
$allTagIds
))
{
$tags
=
CertTag
::
where
(
'is_del'
,
0
)
->
whereIn
(
'id'
,
array_unique
(
$allTagIds
))
->
field
(
'id,title'
)
->
select
()
->
toArray
();
$tags
=
array_column
(
$tags
,
null
,
'id'
);
}
// 组装结果
$result
=
$list
->
toArray
();
foreach
(
$result
[
'data'
]
as
&
$item
)
{
$itemTags
=
[];
if
(
!
empty
(
$item
[
'tag_ids'
]))
{
$tagIds
=
explode
(
','
,
$item
[
'tag_ids'
]);
foreach
(
$tagIds
as
$tagId
)
{
if
(
isset
(
$tags
[
$tagId
]))
{
$itemTags
[]
=
$tags
[
$tagId
];
}
}
}
$item
[
'tags'
]
=
$itemTags
;
}
$list
=
UtilService
::
listWithTags
(
$list
,
CertTag
::
class
,
'tag_ids'
);
return
$
resul
t
;
return
$
lis
t
;
}
...
...
app/model/Project.php
View file @
d7fa8090
...
...
@@ -10,6 +10,8 @@
namespace
app\model
;
use
app\api\middleware\Auth
;
use
app\api\service\UtilService
;
use
app\model\project\User
;
use
app\model\system\SystemUploadFile
;
use
think\facade\Db
;
...
...
@@ -24,6 +26,10 @@ class Project extends Model
use
SoftDelete
;
protected
$deleteTime
=
'deletetime'
;
protected
$autoWriteTimestamp
=
true
;
public
function
getCreatetimeAttr
(
$value
)
{
return
date
(
'Y-m-d H:i:s'
,
$value
);
...
...
@@ -86,4 +92,55 @@ class Project extends Model
return
$statustxt
;
}
public
function
getProjectList
(
$category_id
,
$page
,
$pageSize
,
$type
)
{
$where
=
[
'sh_status'
=>
2
,
'status'
=>
1
];
if
(
$category_id
)
{
$where
[
'cate_id'
]
=
$category_id
;
}
$query
=
self
::
where
(
$where
);
$query
->
order
(
'createtime'
,
'desc'
);
//热门项目
if
(
$type
==
3
)
{
$query
->
where
(
'is_hot'
,
1
);
}
$list
=
$query
->
field
(
'id,sn,title,createtime,cate_id,yusuan,zhouqi,tag_ids'
)
->
paginate
([
'page'
=>
$page
,
'list_rows'
=>
$pageSize
]);
if
(
$list
->
isEmpty
()
||
$type
==
2
)
{
return
$list
;
}
$list
=
UtilService
::
listWithTags
(
$list
,
ProjectTag
::
class
,
'tag_ids'
);
return
$list
;
}
public
function
projectDetail
(
$id
,
$userId
)
{
$where
=
[
'id'
=>
$id
];
$detail
=
self
::
where
(
$where
)
->
find
();
$detail
[
'is_put'
]
=
ProjectPut
::
where
([
'project_id'
=>
$id
,
'user_id'
=>
$userId
])
->
count
();
return
$detail
;
}
}
\ No newline at end of file
app/model/ProjectCategory.php
View file @
d7fa8090
...
...
@@ -22,6 +22,11 @@ class ProjectCategory extends Model
{
use
SoftDelete
;
protected
$deleteTime
=
'deletetime'
;
protected
$autoWriteTimestamp
=
true
;
protected
$createTime
=
'createtime'
;
public
function
catetree
(
$cate_id
=
0
)
{
...
...
@@ -40,6 +45,22 @@ class ProjectCategory extends Model
return
get_upload_file
(
$data
[
'thumb'
]);
}
public
function
children
()
{
return
$this
->
hasMany
(
ProjectCategory
::
class
,
'pid'
);
}
public
function
getProjectCategoryList
()
{
return
$this
->
with
([
'children'
=>
function
(
$query
)
{
$query
->
order
(
'sort'
,
'asc'
);
}])
->
where
(
'pid'
,
0
)
->
order
(
'sort'
,
'asc'
)
->
select
();
}
}
\ No newline at end of file
app/model/ProjectPut.php
View file @
d7fa8090
...
...
@@ -21,6 +21,10 @@ use think\Model;
class
ProjectPut
extends
Model
{
protected
$type
=
[
'complete_time'
=>
'timestamp:Y-m-d H:i:s'
,
'complete_post_time'
=>
'timestamp:Y-m-d H:i:s'
,
];
public
function
getCreatetimeAttr
(
$value
)
{
...
...
@@ -83,4 +87,19 @@ class ProjectPut extends Model
return
$statustxt
;
}
public
function
putProject
(
$data
,
$userId
)
{
$data
[
'user_id'
]
=
$userId
;
$data
[
'createtime'
]
=
time
();
$res
=
self
::
create
(
$data
);
return
$res
;
}
public
function
project
()
{
return
$this
->
belongsTo
(
Project
::
class
,
'project_id'
,
'id'
)
->
field
(
'id,sn,title,yusuan,user_id'
);
}
}
\ No newline at end of file
app/model/ProjectTag.php
0 → 100644
View file @
d7fa8090
<?php
namespace
app\model
;
use
think\Model
;
class
ProjectTag
extends
Model
{
}
\ No newline at end of file
app/model/project/UserMoneyLog.php
0 → 100644
View file @
d7fa8090
<?php
namespace
app\model\project
;
use
think\Model
;
class
UserMoneyLog
extends
Model
{
protected
$autoWriteTimestamp
=
true
;
protected
$createTime
=
'createtime'
;
/**
* 获取用户金额变动排行榜
* @param int $limit 前N名
* @param string $timeRange 时间范围: 'all'-全部, 'month'-本月, 'week'-本周, 'day'-今天, 'three_month'-近三月
* @param int $type 操作类型: null-全部, 0-项目结算, 1-提现, 2-后台手动增加
* @return array
*/
public
static
function
getUserMoneyRanking
(
$limit
=
10
,
$timeRange
=
'all'
,
$type
=
null
)
{
$query
=
self
::
field
(
'user_id, SUM(money) as total_money'
)
->
group
(
'user_id'
)
->
order
(
'total_money'
,
'DESC'
)
->
limit
(
$limit
);
// 按时间范围筛选
switch
(
$timeRange
)
{
case
'month'
:
$query
->
whereTime
(
'createtime'
,
'month'
);
break
;
case
'week'
:
$query
->
whereTime
(
'createtime'
,
'week'
);
break
;
case
'day'
:
$query
->
whereTime
(
'createtime'
,
'today'
);
break
;
case
'three_month'
:
$threeMonthAgo
=
strtotime
(
'-3 months'
);
$query
->
where
(
'createtime'
,
'>='
,
$threeMonthAgo
);
break
;
}
// 按操作类型筛选
if
(
!
is_null
(
$type
))
{
$query
->
where
(
'type'
,
$type
);
}
$ranking
=
$query
->
select
()
->
toArray
();;
// 获取用户信息
if
(
!
empty
(
$ranking
))
{
$userIds
=
array_column
(
$ranking
,
'user_id'
);
$users
=
User
::
whereIn
(
'id'
,
$userIds
)
->
where
(
'is_del'
,
0
)
->
column
(
'username,realname,headico'
,
'id'
);
foreach
(
$ranking
as
&
$item
)
{
$item
[
'user_info'
]
=
$users
[
$item
[
'user_id'
]]
??
[];
}
}
return
$ranking
;
}
}
\ No newline at end of file
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