|
@@ -64,6 +64,8 @@ use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
use App\Model\Company;
|
|
|
use Hyperf\Paginator\Paginator;
|
|
|
+use App\Model\Project;
|
|
|
+
|
|
|
|
|
|
class NewsService implements NewsServiceInterface
|
|
|
{
|
|
@@ -6207,7 +6209,184 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
return Result::success($company);
|
|
|
}
|
|
|
+
|
|
|
+ * 获取项目列表
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getProjectList(array $data): array
|
|
|
+ {
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+
|
|
|
+ $user = User::where('id',$data['user_id'])->first();
|
|
|
+ if(empty($user)){
|
|
|
+ return Result::error('用户不存在!');
|
|
|
+ }
|
|
|
+ if($user->type_id != 10000){
|
|
|
+ array_push($where, ['project.user_id', $data['user_id']]);
|
|
|
+ }
|
|
|
+ $query = Project::query();
|
|
|
+ if(isset($data['website_id']) && !empty($data['website_id'])){
|
|
|
+ array_push($where, ['project.website_id', $data['website_id']]);
|
|
|
+ }
|
|
|
+ if(isset($data['title']) && !empty($data['title'])){
|
|
|
+ array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
|
|
|
+ }
|
|
|
+ if($data['status'] != 3){
|
|
|
+ array_push($where, ['project.status', $data['status']]);
|
|
|
+ }
|
|
|
+ $query = Project::where($where)
|
|
|
+ ->when($data['status'] == 3, function($query){
|
|
|
+ $query->whereIn('project.status', [0, 2]);
|
|
|
+ });
|
|
|
+ $count = $query->clone()
|
|
|
+ ->count();
|
|
|
+ $rows = $query->clone()
|
|
|
+ ->leftJoin('website', 'project.website_id', '=', 'website.id')
|
|
|
+ ->leftJoin('website_category', 'project.category_id', '=', 'website_category.id')
|
|
|
+ ->select('project.*','website.website_name','website_category.alias as category_name')
|
|
|
+ ->orderBy('project.updated_at', 'desc')
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get();
|
|
|
+ if($rows->isEmpty()){
|
|
|
+ return Result::error("暂无相关项目信息", 0);
|
|
|
+ }
|
|
|
+ $result = [
|
|
|
+ 'count' => $count,
|
|
|
+ 'rows' => $rows,
|
|
|
+ ];
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ * 添加项目
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function addProject(array $data): array
|
|
|
+ {
|
|
|
+ $user = User::where('id',$data['user_id'])->first();
|
|
|
+ if(empty($user)){
|
|
|
+ return Result::error("暂无相关用户信息", 0);
|
|
|
+ }
|
|
|
+ if($user->type_id == 10000){
|
|
|
+ $data['status'] = 1;
|
|
|
+ }else{
|
|
|
+ $data['status'] = 0;
|
|
|
+ }
|
|
|
+ if ($data['keyword'] == '') {
|
|
|
+
|
|
|
+ $data['keyword'] = $data['title'];
|
|
|
+
|
|
|
+ Jieba::init();
|
|
|
+ Finalseg::init();
|
|
|
+ $segList = Jieba::cut($data['keyword']);
|
|
|
+ $segList1 = array_slice($segList, 0, 8);
|
|
|
+ $data['keyword'] = implode(',', $segList1);
|
|
|
+ }
|
|
|
+ if ($data['description'] == '') {
|
|
|
+
|
|
|
+
|
|
|
+ $data['description'] = mb_substr(str_replace(' ', '', strip_tags($data['introduce'])), 0, 100);
|
|
|
+ }
|
|
|
+ $project = Project::insertGetId($data);
|
|
|
+ if(empty($project)){
|
|
|
+ return Result::error("暂无相关项目信息", 0);
|
|
|
+ }
|
|
|
+ return Result::success($project);
|
|
|
+ }
|
|
|
+
|
|
|
+ * 更新项目
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function upProject(array $data): array
|
|
|
+ {
|
|
|
+ $project = Project::where('id', $data['id'])->first();
|
|
|
+ if(empty($project)){
|
|
|
+ return Result::error("暂无相关项目信息", 0);
|
|
|
+ }
|
|
|
+ $id = $data['id'];
|
|
|
+ unset($data['id']);
|
|
|
+ $user = User::where('id',$data['user_id'])->first();
|
|
|
+ if(empty($user)){
|
|
|
+ return Result::error("暂无相关用户信息", 0);
|
|
|
+ }
|
|
|
+ if($user->type_id == 10000){
|
|
|
+ $data['status'] = 1;
|
|
|
+ }else{
|
|
|
+ $data['status'] = 0;
|
|
|
+ }
|
|
|
+ unset($data['user_id']);
|
|
|
+ if ($data['keyword'] == '') {
|
|
|
+
|
|
|
+ $data['keyword'] = $data['title'];
|
|
|
+
|
|
|
+ Jieba::init();
|
|
|
+ Finalseg::init();
|
|
|
+ $segList = Jieba::cut($data['keyword']);
|
|
|
+ $segList1 = array_slice($segList, 0, 8);
|
|
|
+ $data['keyword'] = implode(',', $segList1);
|
|
|
+ }
|
|
|
+ if ($data['description'] == '') {
|
|
|
+
|
|
|
+
|
|
|
+ $data['description'] = mb_substr(str_replace(' ', '', strip_tags($data['introduce'])), 0, 100);
|
|
|
+ }
|
|
|
+ $result = Project::where('id', $id)->update($data);
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("更新失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ * 删除项目
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ public function delProject(array $data): array
|
|
|
+ {
|
|
|
+ $user = User::where('id',$data['user_id'])->first();
|
|
|
+ if(empty($user)){
|
|
|
+ return Result::error("暂无相关用户信息", 0);
|
|
|
+ }
|
|
|
+ $project = Project::where('id', $data['id'])->first();
|
|
|
+ if(empty($project)){
|
|
|
+ return Result::error("暂无相关项目信息", 0);
|
|
|
+ }
|
|
|
+ $result = Project::where('id',$data['id'])->delete();
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("删除失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ * 审核项目
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function checkProject(array $data): array
|
|
|
+ {
|
|
|
+ $user = User::where('id',$data['user_id'])->first();
|
|
|
+ if(empty($user)){
|
|
|
+ return Result::error("暂无相关用户信息", 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($user->type_id != 10000){
|
|
|
+ if($data['status'] == 1 || $data['status'] == 2){
|
|
|
+ return Result::error("此用户权限不足", 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $project = Project::where('id', $data['id'])->first();
|
|
|
+ if(empty($project)){
|
|
|
+ return Result::error("暂无相关项目信息", 0);
|
|
|
+ }
|
|
|
+ $result = Project::where('id',$data['id'])->update(['status' => $data['status']]);
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("审核失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
}
|