123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- namespace app\api\controller;
- use think\facade\Request;
- use think\facade\View;
- use app\model\Employee;
- use app\model\Org;
- use app\model\CompanyStrength as CompanyStrengthModel;
- use app\model\CompanyStrengthCate;
- use app\model\UserCollect;
- class CompanyStrength extends Base
- {
- /**
- * 公司实力列表
- */
- public function index()
- {
- $token = $this->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' => '取消收藏']);
- }
- }
|