TeamModel.php 2.1 KB
<?php
/**
 * Created by PhpStorm.
 * auther: sgj
 * Date: 2020/9/26
 * Time: 16:06
 */

namespace api\common\model;


use think\Model;

class TeamModel extends Model
{
    protected $name = 'team';

    public function getPicAttr($value){
        return cmf_get_image_url($value);
    }


    /**
     * 获取地址
     * @param $order 排序方式
     * @param $field  获取字段
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getTeamList($order,$field){
        $map['status']=2;
        $info=$this->where($map)->order($order)->select()->toArray();
        return $info;
    }

    /**
     * 获取团队详情
     * @param $id id
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getTeamInfo($id){
        $map['id']=$id;
        $info=$this->where($map)->find();
        $info['create_time_attr']=date('Y-m-d',$info['create_time']);
        $info['content']=cmf_replace_content_file_url(htmlspecialchars_decode($info['content']));
        return $info;
    }

    public function joinTeamList($user_id){
         $map['user_id']=$user_id;
         $map['status']=1;
         $team_array=db('team_apply')->where($map)->column('team_id');
         if (empty($team_array)){
             return;
         }
         $team_id=implode(',',$team_array);
         $map1['id']=['in',$team_id];
         $info=$this->where($map1)->select();
         foreach ($info as $k=>$v){
             $info[$k]['pic']=cmf_get_image_url($v['pic']);
             $info[$k]['my_time']=$this->myTime($user_id,$v['id']);
         }
         return $info;
    }

    /** 我的时间
     * @param $user_id
     * @param $team_id
     * @return float|int
     */
    public function myTime($user_id,$team_id){
        $map['user_id']=$user_id;
        $map['team_id']=$team_id;
        $time=db('team_work_log')->where($map)->sum('work_time');
        return $time;
    }
}