فهرست منبع

消息新增选择用户

王大坤 2 سال پیش
والد
کامیت
c79885e1e3

+ 4 - 1
app/Admin/Controllers/MsgController.php

xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Admin\Controllers;
 
 use App\Admin\Repositories\Msg;
+use App\Models\User;
 use Dcat\Admin\Form;
 use Dcat\Admin\Grid;
 use Dcat\Admin\Show;
@@ -71,7 +72,9 @@ class MsgController extends AdminController
             $form->display('id');
             $form->hidden('type')->default(6);
             $form->hidden('user_id')->default(0);
-            $form->hidden('to_user_id')->default(0);
+            $form->select('to_user_id')->options(function ($item){
+                return User::pluck('name','id');
+            });
             $form->hidden('title')->default("系统通知");
             $form->textarea('content');
 

+ 1 - 0
app/Admin/Controllers/ProductController.php

xqd
@@ -105,6 +105,7 @@ class ProductController extends AdminController
                         'content' => "很抱歉的告诉您,您上传的内容涉及敏感内容,我们已处理下架",
                         'user_id' => $product->user_id,
                         'to_user_id' => $product->user_id,
+                        'product_id'=> $product->id,
                     ];
                     Msg::query()->create($msg); // 添加通知消息
                 }

+ 1 - 0
app/Admin/Controllers/ProductTypeController.php

xqd
@@ -76,6 +76,7 @@ class ProductTypeController extends AdminController
             $form->text('zh_alias')->width(4);
             $form->text('ko_alias')->width(4);
             $form->textarea('describe')->width(4);
+            $form->textarea('ko_describe','描述(韩文)')->width(4);
             $form->number('sort');
             $form->switch('status')->default(1);
             $form->hidden('route_id');

+ 41 - 0
app/Helper/function.php

xqd
@@ -376,6 +376,47 @@ if (!function_exists('pages')) {
             'page' => $list->currentPage(),//当前页
         ];
     }
+    function pagesArr($list,$go){
+        $num_elements = intval(count($list['data']) / $go); //每个二维数组包含几个元素
+        $items = array_chunk($list['data'], $num_elements>0?$num_elements:1);
+        $arr1 = [];
+        $arrList = [];
+        foreach ($items as $k=>$v){
+            if($k+1 >= $go){
+                $arr1[] = $v;
+            }else{
+                $arrList[] = $v;
+            }
+        }
+        $arr3 = [];
+        if(!empty($arr1)){
+            foreach ($arr1 as $v){
+                if(!empty($v)){
+                    foreach ($v as $v1){
+                        $arr3[] = $v1;
+                    }
+                }
+            }
+        }
+        if(!empty($arr3)){
+            $arrList = array_merge($arrList,[$arr3]);
+        }
+        if($go > count($arrList)){
+            $arr = [];
+            $num = $go - count($arrList);
+            for ($i=0;$i< $num;$i++){
+                $arr[] = [];
+            }
+            $arrList = array_merge($arrList,$arr);
+        }
+        return [
+            'items' => $arrList,
+            'total' => $list['total'],   // 总数
+            'pageSize' => $list['per_page'], // 每页数据
+            'totalPage' => $list['last_page'],// 总页数
+            'page' => $list['current_page'],//当前页
+        ];
+    }
 
 }
 

+ 9 - 1
app/Http/Controllers/V1/Controller.php

xqd
@@ -91,7 +91,15 @@ class Controller extends BaseController
             'page'=>$list->currentPage(),//当前页
         ];
     }
-
+    public function pageByArr($list){
+        return [
+            'items' =>$list['data'],
+            'total'=>$list['total'],   // 总数
+            'pageSize'=>$list['per_page'], // 每页数据
+            'totalPage'=>$list['last_page'],// 总页数
+            'page'=>$list['current_page'],//当前页
+        ];
+    }
     // 特殊处理
     public function pages($list){
         return [

+ 1 - 1
app/Http/Controllers/V1/MemberController.php

xqd
@@ -46,7 +46,7 @@ class MemberController extends Controller
         DB::beginTransaction();
         try {
             $user = User::query()->where('id',$this->userId)->first();
-            $user->update($params);
+            $user->save($params);
             DB::commit();
         } catch (\Exception $e){
             DB::rollBack();

+ 13 - 3
app/Http/Controllers/V1/MsgController.php

xqd xqd xqd
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\V1;
 
 use App\Models\Msg;
 use App\Models\MsgRead;
+use App\Models\Product;
 use Illuminate\Http\Request;
 
 class MsgController extends Controller
@@ -30,14 +31,17 @@ class MsgController extends Controller
 
         $limit = $request->get('limit',10);
 
-        $list = Msg::query()->with('user:id,name,avatar')->where('to_user_id',$this->userId)
+        $list = Msg::query()->with('user:id,name,avatar')->withCount(['read' => function($item){
+            $item->where('user_id',$this->userId);
+        }])->where('to_user_id',$this->userId)
             ->orWhere('to_user_id',0)
             ->orderByDesc("id")
             ->paginate($limit);
 
         foreach ($list as $v){
             if($v){
-                $v['is_read'] = MsgRead::query()->where('user_id',$this->userId)->where('msg_id',$v['id'])->count();
+                $v['productList'] = Product::select('id','image')->whereIn('id',explode(',',$v['product_id']))->get();
+                $v['is_read'] = $v['read_count'];
             }
         }
 
@@ -66,5 +70,11 @@ class MsgController extends Controller
         }
         return $this->success($msg);
     }
-
+    public function getNewMsgState(){
+        $read = Msg::join('msg_read','msg.id','=','msg_read.msg_id')->count();
+        $msg = Msg::where('to_user_id',$this->userId)->count();
+        return $this->success([
+            'isNewMsg' => ($msg - $read) > 0 ? 1 : 0
+        ]);
+    }
 }

+ 266 - 183
app/Http/Controllers/V1/ProductController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -9,6 +9,7 @@ use App\Models\Report;
 use App\Models\ReportLog;
 use App\Models\User;
 use App\Models\UserCollect;
+use App\Models\UserFolder;
 use App\Models\UserFollow;
 use App\Models\UserLike;
 use Illuminate\Http\Request;
@@ -31,46 +32,48 @@ class ProductController extends Controller
             auth('api')->logout();
         }
     }
+
     /**
      * @param Request $request
      * @return \Illuminate\Http\JsonResponse
      *分类数据筛选
      */
-    public function filterTypeList(Request $request){
-      $pid = $request->input('pid');
-      $map = [];
-      $maps = [];
-      if($pid){
-          $map[] = ['pid','=',$pid];
-          $maps[] = ['filter_display_pid','=',$pid];
-      }
-      $list = ProductType::query()
-          ->where('status',1)
-          ->where($map)
-          ->orWhere($maps)
-          ->orderByDesc("sort")
-          ->get();
-      $data = [];
-      foreach ($list as $v){
-          if($v['filter_display_pid'] === 0){
-              $v['pid'] = 0;
-          }elseif ($v['filter_display_pid'] > 0){
-              $v['pid'] = $v['filter_display_pid'];
-          }else{
-              $v['pid'] = $v['pid'];
-          }
-
-          $data[] = [
-              'id'                  => $v['id'],
-              'icon'                => $v['icon'],
-              'zh_name'             => $v['zh_alias'] != null?$v['zh_alias']:$v['zh_name'],
-              'ko_name'             => $v['ko_alias'] != null?$v['ko_alias']:$v['ko_name'],
-              'pid'                 => $v['pid'],
-              'is_display'          => $v['is_filter_display'],
-              'product_count'       => Product::query()->whereJsonContains('type',[$v['id']])->where('status',1)->count()
-          ];
-      }
-      return $this->success($this->recursion($data,$pid?$pid:0));
+    public function filterTypeList(Request $request)
+    {
+        $pid = $request->input('pid');
+        $map = [];
+        $maps = [];
+        if ($pid) {
+            $map[] = ['pid', '=', $pid];
+            $maps[] = ['filter_display_pid', '=', $pid];
+        }
+        $list = ProductType::query()
+            ->where('status', 1)
+            ->where($map)
+            ->orWhere($maps)
+            ->orderByDesc("sort")
+            ->get();
+        $data = [];
+        foreach ($list as $v) {
+            if ($v['filter_display_pid'] === 0) {
+                $v['pid'] = 0;
+            } elseif ($v['filter_display_pid'] > 0) {
+                $v['pid'] = $v['filter_display_pid'];
+            } else {
+                $v['pid'] = $v['pid'];
+            }
+
+            $data[] = [
+                'id' => $v['id'],
+                'icon' => $v['icon'],
+                'zh_name' => $v['zh_alias'] != null ? $v['zh_alias'] : $v['zh_name'],
+                'ko_name' => $v['ko_alias'] != null ? $v['ko_alias'] : $v['ko_name'],
+                'pid' => $v['pid'],
+                'is_display' => $v['is_filter_display'],
+                'product_count' => Product::query()->whereJsonContains('type', [$v['id']])->where('status', 1)->count()
+            ];
+        }
+        return $this->success($this->recursion($data, $pid ? $pid : 0));
     }
 
 
@@ -79,40 +82,41 @@ class ProductController extends Controller
      * @return \Illuminate\Http\JsonResponse
      * 分类数据上传
      */
-    public function uploadTypeList(Request $request){
+    public function uploadTypeList(Request $request)
+    {
         $pid = $request->input('pid');
         $map = [];
         $maps = [];
-        if($pid){
-            $map[] = ['pid','=',$pid];
-            $maps[] = ['upload_display_pid','=',$pid];
+        if ($pid) {
+            $map[] = ['pid', '=', $pid];
+            $maps[] = ['upload_display_pid', '=', $pid];
         }
         $list = ProductType::query()
-            ->where('status',1)
+            ->where('status', 1)
             ->where($map)
             ->orWhere($maps)
             ->orderByDesc("sort")
             ->get();
         $data = [];
-        foreach ($list as $v){
-            if($v['upload_display_pid'] === 0){
+        foreach ($list as $v) {
+            if ($v['upload_display_pid'] === 0) {
                 $v['pid'] = 0;
-            }elseif ($v['upload_display_pid'] > 0){
+            } elseif ($v['upload_display_pid'] > 0) {
                 $v['pid'] = $v['upload_display_pid'];
-            }else{
+            } else {
                 $v['pid'] = $v['pid'];
             }
             $data[] = [
-                'id'                  => $v['id'],
-                'icon'                => $v['icon'],
-                'zh_name'             => $v['zh_name'],
-                'ko_name'             => $v['ko_name'],
-                'describe'            => $v['describe'],
-                'pid'                 => $v['pid'],
-                'is_display'          => $v['is_upload_display']
+                'id' => $v['id'],
+                'icon' => $v['icon'],
+                'zh_name' => $v['zh_name'],
+                'ko_name' => $v['ko_name'],
+                'describe' => $v['describe'],
+                'pid' => $v['pid'],
+                'is_display' => $v['is_upload_display']
             ];
         }
-        return $this->success($this->recursion($data,$pid?$pid:0));
+        return $this->success($this->recursion($data, $pid ? $pid : 0));
     }
 
     /**
@@ -121,12 +125,13 @@ class ProductController extends Controller
      * @return array
      * 递归处理
      */
-    public function recursion($list = [],$pid = 0){
+    public function recursion($list = [], $pid = 0)
+    {
         $child = [];
         foreach ($list as $value) {
-            if($value['is_display'] != 0){
-                if ($value['pid'] == $pid ) {
-                    if($this->recursion($list, $value['id'])){
+            if ($value['is_display'] != 0) {
+                if ($value['pid'] == $pid) {
+                    if ($this->recursion($list, $value['id'])) {
                         // 递归调用,查找当前数据的子级
                         $value['child'] = $this->recursion($list, $value['id']);
                     }
@@ -142,31 +147,33 @@ class ProductController extends Controller
      * @return mixed
      * 添加产品
      */
-    public function addProduct(Request $request){
-        $params =  $request->all();
-        if(empty($params['type'])){
-           return $this->error("分类不能能为空!");
+    public function addProduct(Request $request)
+    {
+        $params = $request->all();
+        if (empty($params['type'])) {
+            return $this->error("分类不能能为空!");
         }
 
-        if(empty($params['url']) && empty($params['name']) && empty($params['content'])){
+        if (empty($params['url']) && empty($params['name']) && empty($params['content'])) {
             return $this->error("数据不能为空!");
         }
 
         $params['user_id'] = $this->userId; // 用户ID
         $res = Product::query()->create($params);
-        if(!$res){
+        if (!$res) {
             return $this->error("上传失败!");
         }
-        $follow = UserFollow::query()->where('to_user_id',$this->userId)->pluck('user_id')->toArray();
-        if(!empty($follow)){
-            $user = User::query()->where('id',$this->userId)->first();
-            foreach ($follow as $v){
+        $follow = UserFollow::query()->where('to_user_id', $this->userId)->pluck('user_id')->toArray();
+        if (!empty($follow)) {
+            $user = User::query()->where('id', $this->userId)->first();
+            foreach ($follow as $v) {
                 $msg = [
                     'type' => 5,//关注的人发了新作品
                     'title' => "关注的人发了新作品",
-                    'content' => " 您关注的".$user->name."上传了1张图片",
+                    'content' => " 您关注的" . $user->name . "上传了1张图片",
                     'user_id' => $this->userId,
                     'to_user_id' => $v,
+                    'product_id'=> $res->id,
                 ];
                 Msg::query()->create($msg); // 添加通知消息
             }
@@ -179,19 +186,20 @@ class ProductController extends Controller
      * @return void
      * 我的上传列表
      */
-    public function userProductList(Request $request){
+    public function userProductList(Request $request)
+    {
 
-        $limit = $request->get('limit',10);
-        $go = $request->get('go',6);
+        $limit = $request->get('limit', 10);
+        $go = $request->get('go', 6);
         $user_id = $request->get('user_id');
-        if(empty($user_id)){
+        if (empty($user_id)) {
             $user_id = $this->userId;
         }
-        $list = Product::query()->where('status','=',1)
-            ->where('user_id','=',$user_id)
+        $list = Product::query()->where('status', '=', 1)
+            ->where('user_id', '=', $user_id)
             ->orderByDesc('id')
             ->paginate($limit);
-       return $this->success(pages($list,$go));
+        return $this->success(pages($list, $go));
     }
 
     /**
@@ -199,66 +207,70 @@ class ProductController extends Controller
      * @return \Illuminate\Http\JsonResponse
      * 产品列表
      */
-    public function productList(Request $request){
-        $limit = $request->get('limit',10);
+    public function productList(Request $request)
+    {
+        $limit = $request->get('limit', 10);
         $type = $request->get('type');
         $keyword = $request->get('keyword');
-        $go = $request->get('go',6);
-        $query = Product::query()
-            ->with('user:id,name,nickname,avatar,company_name,company_card_color,production_project');
-        if(!empty($type)){
-            $arr = explode(',',$type);
-            foreach ($arr as $v){
-                $query->orWhereJsonContains('type',[intval($v)]);
+        $go = $request->get('go', 6);
+        $query = Product::with('user:id,name,nickname,avatar,company_name,company_card_color,production_project,member_type,follow_count')
+            ->join('users', 'users.id', '=', 'product.user_id')
+            ->select('product.id','product.type','user_id','product.name','content','image','url','product.created_at','product.updated_at');
+        if (!empty($type)) {
+            $arr = explode(',', $type);
+            foreach ($arr as $v) {
+                $query->orWhereJsonContains('type', [intval($v)]);
             }
         }
-        $query->whereHas('user',function ($q){
-            $q->where('is_stop',0);
+        $query->whereHas('user', function ($q) {
+            $q->where('is_stop', 0);
         });
-        if(!empty($keyword)){
-            $query->where('name','like','%'.$keyword.'%');
-        }
-        $list = $query->where('status',1)
-            ->orderByDesc("id")
-//            ->toSql();
-//        echo $list;
+        if (!empty($keyword)) {
+            $query->where('name', 'like', '%' . $keyword . '%');
+        }
+        $list = $query->where('product.status', 1)
+            ->orderByDesc('users.member_type')
+            ->orderByDesc('users.follow_count')
+            ->orderByDesc("product.like_count")
+            ->orderBy("product.id")
             ->paginate(intval($limit));
-        foreach ($list as $v){
+        foreach ($list as $v) {
             $v['is_collect'] = 0;
-            if(!empty($this->userId)){
-                $v['is_collect'] = UserCollect::query()->where('product_id',$v['id'])->where('user_id',$this->userId)->count();
+            if (!empty($this->userId)) {
+                $v['is_collect'] = UserCollect::query()->where('product_id', $v['id'])->where('user_id', $this->userId)->count();
             }
         }
-        return $this->success(pages($list,$go));
+        return $this->success(pages($list, $go));
     }
 
     /**
      * @return void
      * 产品详情
      */
-    public function productDetail(Request $request){
+    public function productDetail(Request $request)
+    {
 
         $data = Product::query()
             ->with('user:id,name,nickname,avatar,company_name,company_url,production_project')
-            ->where('status',1)
-            ->where('id',$request->get('id'))
-            ->whereHas('user',function ($q){
-                $q->where('is_stop',0);
+            ->where('status', 1)
+            ->where('id', $request->get('id'))
+            ->whereHas('user', function ($q) {
+                $q->where('is_stop', 0);
             })
-            ->select("id","name","user_id","content","image","type","url")->first();
-        if(!$data){
+            ->select("id", "name", "user_id", "content", "image", "type", "url")->first();
+        if (!$data) {
             return $this->error("数据不存在!");
         }
         $data['is_collect'] = 0; // 收藏
         $data['is_follow'] = 0; // 关注
         $data['is_like'] = 0; // 喜欢
-        if(!empty($this->userId)){
-            $data['is_collect'] = UserCollect::query()->where('product_id',$data['id'])->where('user_id',$this->userId)->count();
-            $data['is_follow'] = UserFollow::query()->where('to_user_id',$data['user_id'])->where('user_id',$this->userId)->count();
-            $data['is_like'] = UserLike::query()->where('product_id',$data['id'])->where('user_id',$this->userId)->count();
+        if (!empty($this->userId)) {
+            $data['is_collect'] = UserCollect::query()->where('product_id', $data['id'])->where('user_id', $this->userId)->count();
+            $data['is_follow'] = UserFollow::query()->where('to_user_id', $data['user_id'])->where('user_id', $this->userId)->count();
+            $data['is_like'] = UserLike::query()->where('product_id', $data['id'])->where('user_id', $this->userId)->count();
         }
-        if(!empty($data['user'])){
-            $data['user']['follow_count'] = UserFollow::query()->where('user_id',$data['user_id'])->count();
+        if (!empty($data['user'])) {
+            $data['user']['follow_count'] = UserFollow::query()->where('user_id', $data['user_id'])->count();
         }
         return $this->success($data);
 
@@ -270,49 +282,63 @@ class ProductController extends Controller
      * @param Request $request
      * @return \Illuminate\Http\JsonResponse
      */
-    public function getProductRecommend(Request $request){
-        $type = Product::where('id',$request->get('id'))->where('status',1)->value('type');
+    public function getProductRecommend(Request $request)
+    {
+        $limit = $request->get('limit', 10);
+        $type = $request->get('type');
+        $keyword = $request->get('keyword');
+        $go = $request->get('go', 6);
+        $type = Product::where('id', $request->get('id'))->where('status', 1)->value('type');
         $recommend = Product::with('user:id,name,nickname,avatar,company_name,company_url,production_project');
-        foreach ($type ?? []  as $v){
-            $recommend->orWhereJsonContains('type',[intval($v)]);
-        }
-        $recommend->where('status',1)
-            ->select("id","name","user_id","content","image","type","url")
-            ->where('id','<>',$request->get('id'))
-            ->whereHas('user',function ($q){
-                $q->where('is_stop',0);
+        foreach ($type ?? [] as $v) {
+            $recommend->orWhereJsonContains('type', [intval($v)]);
+        }
+        $recommend->where('status', 1)
+            ->select("id", "name", "user_id", "content", "image", "type", "url")
+            ->where('id', '<>', $request->get('id'))
+            ->whereHas('user', function ($q) {
+                $q->where('is_stop', 0);
             });
-        $data = $recommend->orderBy('id','desc')->paginate()->toArray();
-        foreach ($data['data'] ?? [] as $key => $value){
-            if ($value['id'] == $request->get('id')){
+        $data = $recommend->orderBy('id', 'desc')->paginate(intval($limit))->toArray();
+        foreach ($data['data'] ?? [] as $key => $value) {
+            if ($value['id'] == $request->get('id')) {
                 unset($data['data'][$key]);
             }
         }
         $data['data'] = array_values($data['data']);
-        if (empty($data['data'])){
+        if (empty($data['data'])) {
             $data = Product::with('user:id,name,nickname,avatar,company_name,company_url,production_project')
-                ->where('status',1)
-                ->where('id','<>',$request->get('id'))
-                ->select("id","name","user_id","content","image","type","url")
-                ->whereHas('user',function ($q){
-                    $q->where('is_stop',0);
+                ->where('status', 1)
+                ->where('id', '<>', $request->get('id'))
+                ->select("id", "name", "user_id", "content", "image", "type", "url")
+                ->whereHas('user', function ($q) {
+                    $q->where('is_stop', 0);
                 })
                 ->orderByRaw('rand()')->paginate();
         }
-        return $this->success($data);
+        foreach ($data['data'] as $v) {
+            $v['is_collect'] = 0;
+            if (!empty($this->userId)) {
+                $v['is_collect'] = UserCollect::query()->where('product_id', $v['id'])->where('user_id', $this->userId)->count();
+            }
+        }
+        return $this->success(pagesArr($data, $go));
+//        return $this->success($this->pageByArr($data));
     }
+
     /**
      * @param Request $request
      * @return void
      * 删除产品
      */
-    public function delProduct(Request $request){
+    public function delProduct(Request $request)
+    {
         $id = $request->get('id');
-        if(empty($id)){
+        if (empty($id)) {
             return $this->error("缺少参数ID!");
         }
-        $product = Product::query()->where('id',$id)->first();
-        if(!$product){
+        $product = Product::query()->where('id', $id)->first();
+        if (!$product) {
             return $this->error("产品不存在!");
         }
         $product->delete();
@@ -323,44 +349,95 @@ class ProductController extends Controller
      * @return void
      * 添加收藏
      */
-    public function addCollect(Request $request){
-        $product = Product::query()->where('id',$request->get('product_id'))->first();
-        if(!$product){
+    public function addCollect(Request $request)
+    {
+        $product = Product::query()->where('id', $request->get('product_id'))->first();
+        if (!$product) {
+            return $this->error("商品不存在!");
+        }
+        $collect = UserCollect::query()->where('product_id', $product->id)->where('user_id', $this->userId)->first();
+        if ($collect) {
+            return $this->error("您已收藏过了!");
+        }
+        $data = [
+            'product_id' => $product->id,
+            'user_id' => $this->userId,
+        ];
+        $res = UserCollect::query()->create($data);
+        if (!$res) {
+            return $this->error("收藏失败!");
+        }
+        $user = User::query()->where('id', $this->userId)->first();
+        $product_type = ProductType::query()->whereIn('id', $product['type'])->select('id', 'zh_name', 'ko_name')->first();
+        $type_name = '';
+        if (!empty($product_type)) {
+            $type_name = $product_type['zh_name'];
+        }
+        $msg = [
+            'type' => 1,//下载通知
+            'title' => "收藏通知",
+            'content' => "您收藏了" . $type_name . "中的1张图片",
+            'user_id' => $this->userId,
+            'to_user_id' => $this->userId,
+            'product_id' => $product['id'],
+        ];
+        Msg::query()->create($msg); // 添加通知消息
+
+        $msg1 = [
+            'type' => 1,//保存通知
+            'title' => "收藏通知",
+            'content' => $user->name . "收藏了您" . $type_name . "中的1张图片",
+            'user_id' => $this->userId,
+            'to_user_id' => $product['user_id'],
+            'product_id' => $product['id'],
+        ];
+        Msg::query()->create($msg1); // 添加通知消息
+
+        return $this->success();
+    }
+
+    public function folderAddCollect(Request $request)
+    {
+        $product = Product::query()->where('id', $request->get('product_id'))->first();
+        if (!$product) {
             return $this->error("商品不存在!");
         }
-        $collect = UserCollect::query()->where('product_id',$product->id)->where('user_id',$this->userId)->first();
-        if($collect){
-           return $this->error("您已收藏过了!");
+        $collect = UserCollect::query()->where('product_id', $product->id)->where('user_id', $this->userId)->first();
+        if ($collect) {
+            return $this->error("您已收藏过了!");
         }
-        $data =[
+        $data = [
             'product_id' => $product->id,
             'user_id' => $this->userId,
         ];
         $res = UserCollect::query()->create($data);
-        if(!$res){
+        if (!$res) {
             return $this->error("收藏失败!");
         }
-        $user = User::query()->where('id',$this->userId)->first();
-        $product_type = ProductType::query()->whereIn('id',$product['type'])->select('id','zh_name','ko_name')->first();
+        $user = User::query()->where('id', $this->userId)->first();
+        $folderName = UserFolder::where('id', $request->get('folderId'))->first();
+        $product_type = ProductType::query()->whereIn('id', $product['type'])->select('id', 'zh_name', 'ko_name')->first();
         $type_name = '';
-        if(!empty($product_type)){
+        if (!empty($product_type)) {
             $type_name = $product_type['zh_name'];
         }
         $msg = [
-            'type' => 2,//下载通知
-            'title' => "下载通知",
-            'content' => "您收藏了".$type_name."中的1张图片",
+            'type' => 1,//下载通知
+            'title' => "收藏通知",
+            'content' => "您收藏了" . $type_name . "中的1张图片",
             'user_id' => $this->userId,
             'to_user_id' => $this->userId,
+            'product_id' => $product['id'],
         ];
         Msg::query()->create($msg); // 添加通知消息
 
         $msg1 = [
-            'type' => 3,//保存通知
-            'title' => "保存通知",
-            'content' => $user->name."收藏了您".$type_name."中的1张图片",
+            'type' => 1,//保存通知
+            'title' => "收藏通知",
+            'content' => $user->name . "收藏了您" . $folderName->name . "中的1张图片",
             'user_id' => $this->userId,
             'to_user_id' => $product['user_id'],
+            'product_id' => $product['id'],
         ];
         Msg::query()->create($msg1); // 添加通知消息
 
@@ -371,13 +448,14 @@ class ProductController extends Controller
      * @return void
      * 取消收藏
      */
-    public function cancelCollect(Request $request){
-        $product = Product::query()->where('id',$request->get('product_id'))->first();
-        if(!$product){
+    public function cancelCollect(Request $request)
+    {
+        $product = Product::query()->where('id', $request->get('product_id'))->first();
+        if (!$product) {
             return $this->error("产品不存在!");
         }
-        $collect = UserCollect::query()->where('product_id',$product->id)->where('user_id',$this->userId)->first();
-        if($collect){
+        $collect = UserCollect::query()->where('product_id', $product->id)->where('user_id', $this->userId)->first();
+        if ($collect) {
             $collect->delete();
         }
         return $this->success();
@@ -387,13 +465,14 @@ class ProductController extends Controller
      * @return void
      * 添加喜欢
      */
-    public function addLike(Request $request){
-        $product = Product::query()->where('id',$request->get('product_id'))->first();
-        if(!$product){
+    public function addLike(Request $request)
+    {
+        $product = Product::query()->where('id', $request->get('product_id'))->first();
+        if (!$product) {
             return $this->error("数据不存在!");
         }
-        $collect = UserLike::query()->where('product_id',$product->id)->where('user_id',$this->userId)->first();
-        if($collect){
+        $collect = UserLike::query()->where('product_id', $product->id)->where('user_id', $this->userId)->first();
+        if ($collect) {
             return $this->error("您已点赞过了!");
         }
         $data = [
@@ -401,19 +480,20 @@ class ProductController extends Controller
             'user_id' => $this->userId,
         ];
         $res = UserLike::query()->create($data);
-        if(!$res){
+        if (!$res) {
             return $this->error("操作失败!");
         }
-        $user = User::query()->where('id',$this->userId)->first();
-        $product_type = ProductType::query()->whereIn('id',$product['type'])->select('id','zh_name','ko_name')->first();
+        Product::where('id', $request->get('product_id'))->increment('like_count');
+        $user = User::query()->where('id', $this->userId)->first();
+        $product_type = ProductType::query()->whereIn('id', $product['type'])->select('id', 'zh_name', 'ko_name')->first();
         $type_name = '';
-        if(!empty($product_type)){
+        if (!empty($product_type)) {
             $type_name = $product_type['zh_name'];
         }
         $msg = [
             'type' => 1,//喜欢通知
             'title' => "喜欢通知",
-            'content' => $user->name."点赞了您".$type_name."中的1张图片",
+            'content' => $user->name . "点赞了您" . $type_name . "中的1张图片",
             'user_id' => $this->userId,
             'to_user_id' => $product['user_id']
         ];
@@ -426,36 +506,38 @@ class ProductController extends Controller
      * @return void
      * 收藏列表
      */
-    public function collectList(Request $request){
-        $limit = $request->get('limit',10);
-        $go = $request->get('go',6);
+    public function collectList(Request $request)
+    {
+        $limit = $request->get('limit', 10);
+        $go = $request->get('go', 6);
         $user_id = $request->get('user_id');
-        if(empty($user_id)){
+        if (empty($user_id)) {
             $user_id = $this->userId;
         }
         $list = UserCollect::query()
             ->with('product:id,name,image,url')
-            ->whereHas('product',function ($query){
-                $query->where('id','>',0);
-                $query->whereHas('user',function ($q){
-                    $q->where('is_stop',0);
+            ->whereHas('product', function ($query) {
+                $query->where('id', '>', 0);
+                $query->whereHas('user', function ($q) {
+                    $q->where('is_stop', 0);
                 });
             })
-            ->where('user_id',$user_id)
-            ->where('is_arrange','=',0)
-            ->select("id","product_id")
+            ->where('user_id', $user_id)
+            ->where('is_arrange', '=', 0)
+            ->select("id", "product_id")
             ->orderByDesc("id")
             ->paginate($limit);
-        return $this->success(pages($list,$go));
+        return $this->success(pages($list, $go));
     }
 
     /**
      * @return void
      * 举报列表
      */
-    public function reportList(){
+    public function reportList()
+    {
 
-        $list = Report::query()->where('status',1)->orderByDesc("sort")->get();
+        $list = Report::query()->where('status', 1)->orderByDesc("sort")->get();
 
         return $this->success($list);
 
@@ -465,17 +547,18 @@ class ProductController extends Controller
      * @return void
      * 举报图片
      */
-    public function report(Request $request){
+    public function report(Request $request)
+    {
         $params = $request->all();
-        if(empty($params['product_id'])){
+        if (empty($params['product_id'])) {
             return $this->error("举报文件不能为空!");
         }
-        if(empty($params['report_id'])){
+        if (empty($params['report_id'])) {
             return $this->error("举报问题不能为空!");
         }
         $params['user_id'] = $this->userId;
         $res = ReportLog::query()->create($params);
-        if(!$res){
+        if (!$res) {
             return $this->error("举报失败!");
         }
         return $this->success();

+ 3 - 1
app/Http/Controllers/V1/UserController.php

xqd xqd xqd
@@ -141,6 +141,7 @@ class UserController extends Controller
         if(!$res){
             return $this->error("操作失败!");
         }
+        User::where('id',$request->get('user_id'))->increment('follow_count');
         return $this->success();
     }
 
@@ -152,7 +153,7 @@ class UserController extends Controller
      */
     public function cancelFollow(Request $request)
     {
-            $user = User::where('id',$request->get('user_id'))->first();
+        $user = User::where('id',$request->get('user_id'))->first();
         if (!$user){
             return $this->error('用户不存在!');
         }
@@ -164,6 +165,7 @@ class UserController extends Controller
         if (!$delete){
             return $this->error('取消关注失败!');
         }
+        User::where('id',$request->get('user_id'))->decrement('follow_count');
         return $this->success();
     }
 

+ 7 - 0
app/Models/Msg.php

xqd xqd
@@ -17,6 +17,7 @@ class Msg extends Model
         'to_user_id',
         'title',
         'content',
+        'product_id'
     ];
 
     public function type(){
@@ -26,4 +27,10 @@ class Msg extends Model
     public function user(){
         return $this->hasOne(User::class,'id','to_user_id');
     }
+    public function product(){
+        return $this->hasOne(Product::class,'id','product_id');
+    }
+    public function read(){
+        return $this->hasMany(MsgRead::class,'msg_id','id');
+    }
 }

+ 2 - 1
app/Models/Product.php

xqd
@@ -20,7 +20,8 @@ class Product extends Model
         'content',
         'image',
         'status',
-        'url'
+        'url',
+        'like_count'
     ];
 
     protected $casts = [

+ 1 - 0
app/Models/User.php

xqd
@@ -47,6 +47,7 @@ class User extends Authenticatable implements JWTSubject
         'member_type',
         'nickname',
         'introduce',
+        'follow_count',
     ];
     public function memberStatus(){
         return [1 => '一般会员', 2 => '企业会员'];

+ 1 - 0
routes/api.php

xqd
@@ -97,6 +97,7 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api)
         $api->group(['prefix' => 'msg'], function($api){
             $api->get('msg_list', 'MsgController@msgList');  //消息列表
             $api->get('msg_detail', 'MsgController@msgDetail');  //消息详情
+            $api->get('getNewMsgState', 'MsgController@getNewMsgState');  //消息详情
         });
         // 会员
         $api->group(['prefix' => 'member'], function($api){