request->token; $param = Request::only(['page'=>1,'limit'=>10,'cate'=>'','label'=>'','title'=>'','difference'=>0,'order'=>'']); $w[] = ['root_id','=',$token['root_org']]; $w[] = ['del','=',0]; $w[] = ['publish','=',1]; if ($param['cate']) { $w[] = ['cate','=',$param['cate']]; } if ($param['label']) { $w[] = ['label','=',$param['label']]; } if ($param['title']) { $w[] = ['title','like','%'.$param['title'].'%']; } if ($param['difference']) { $w[] = ['difference', '=', $param['difference']]; } $order = $param['order'] ? $param['order'].' desc' : 'id desc'; $list = CompanyStrengthModel::with(['employee'=>function($query){ $query->visible(['id','name','opt_name']); }])->where($w)->order($order)->page($param['page'],$param['limit'])->select(); foreach ($list as $k => $v) { $collect[] = [ ['content_id','=',$v->id], ['content_type','=','companyStrength'], ['user_id', '=', $token['uid']] ]; $is_collect = UserCollect::where($collect)->findOrEmpty(); $v->collect = !$is_collect->isEmpty(); unset($collect); } $count = CompanyStrengthModel::where($w)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } /** * 获取分类 */ public function get_cate() { $token = $this->request->token; $type = CompanyStrengthCate::where(['pid' => 0, 'root_id' => $token['root_org']])->select()->toArray(); $label = CompanyStrengthCate::where([['pid', '>', 0], ['root_id', '=', $token['root_org']]])->select()->toArray(); foreach ($type as &$val) { $val['sonLabel'] = []; foreach ($label as $typeVal) { if ($val['id'] == $typeVal['pid']) { $val['sonLabel'][] = $typeVal; } } } return json(['code' => 0, 'data' => $type, 'msg' => '获取成功']); // $token = $this->request->token; // $w[] = ['root_id','=',$token['root_org']]; // $w[] = ['pid','=',0]; // $cate = CompanyStrengthCate::where($w)->order('id asc')->select(); // return json(['code' => 0, 'data' => $cate, 'msg' => '获取成功']); } /** * 获取全部标签 */ public function get_all_label() { $token = $this->request->token; $label = CompanyStrengthCate::where([['pid', '>', 0], ['root_id', '=', $token['root_org']]])->select()->toArray(); return json(['code' => 0, 'data' => $label, 'msg' => '获取成功']); } /** * 详情 */ public function read() { $token = $this->request->token; $param = Request::only(['id'=>0]); $w[] = ['root_id','=',$token['root_org']]; $w[] = ['id','=',$param['id']]; $info = CompanyStrengthModel::where($w)->find(); if (empty($info)){ return json(['code' => 0, 'data' => [], 'msg' => '获取成功']); } $collect[] = [ ['content_id','=',$info->id], ['content_type','=','companyStrength'], ['user_id', '=', $token['uid']] ]; $collect = UserCollect::where($collect)->findOrEmpty(); //是否收藏 $info->collect = !$collect->isEmpty(); return json(['code' => 0, 'data' => $info, 'msg' => '获取成功']); } /* * 收藏 */ function collect() { $param = Request::only(['id'=>0]); $token = $this->request->token; $condition[] = ['id', '=', $param['id']]; $condition[] = ['root_id', '=', $token['root_org']]; $info = CompanyStrengthModel::where($condition)->findOrEmpty(); if ($info->isEmpty()) { return json(['code' => 1, 'msg' => '数据不存在']); } $w[] = [ ['content_id','=',$param['id']], ['content_type','=','companyStrength'], ['user_id', '=', $token['uid']] ]; $find = UserCollect::where($w)->findOrEmpty(); if (!$find->isEmpty()) { return json(['code' => 1, 'msg' => '已收藏']); } $save = [ 'content_id' => $param['id'], 'content_type' => 'companyStrength', 'user_id' => $token['uid'] ]; UserCollect::insertGetId($save); return json(['code' => 0, 'msg' => '收藏成功', 'data' => '收藏成功']); } /* * 取消收藏 */ function no_collect() { $param = Request::only(['id'=>0]); $token = $this->request->token; $condition[] = ['id', '=', $param['id']]; $condition[] = ['root_id', '=', $token['root_org']]; $info = CompanyStrengthModel::where($condition)->findOrEmpty(); if ($info->isEmpty()) { return json(['code' => 1, 'msg' => '数据不存在']); } $w[] = [ ['content_id','=',$param['id']], ['content_type','=','companyStrength'], ['user_id', '=', $token['uid']] ]; $find = UserCollect::where($w)->findOrEmpty(); if ($find->isEmpty()) { return json(['code' => 1, 'msg' => '没有收藏']); } UserCollect::where($w)->delete(); return json(['code' => 0, 'msg' => '取消收藏', 'data' => '取消收藏']); } }