VolunteerModel.php 5.3 KB
<?php
/**
 * Created by PhpStorm.
 * auther: sgj
 * Date: 2020/9/26
 * Time: 15:42
 */

namespace api\common\model;


use think\Model;

class VolunteerModel extends Model
{
    protected $name = 'volunteer';


    /**
     * 获取对应级别用户
     * @param $level
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function  getListByLevel($level){
        $levelModel=new LevelModel();
        $info=$levelModel->getLevelTime($level);
        $map['work_time']=['>',$info['min']];
        $map1['work_time']=['<=',$info['max']];
        $map['status']=2;
        $info=$this->where($map)->where($map1)->order('work_time','DESC')->select()->toArray();
        return $info;
    }


    /**
     * 增加工作时间
     * @param $level
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function  addWorkTime($userId,$time){
        $map['user_id']=$userId;
        $this->where($map)->setInc('work_time',$time);
        /*添加团队工时*/
    }

    public function  addStudyTime($userId,$time){
        $map['user_id']=$userId;
        $this->where($map)->setInc('study_time',$time);
        /*添加团队工时*/
    }

    /**
     * 获取用户详情
     * @param $userId
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getUserInfo($userId){
        $map['user_id']=$userId;

        $user=$this->where($map)->find();
        if (empty($user)){
            return;
        }
        $userInfo['area']=$user['province'] ;
        $userInfo['nickname']=$user['nickname'] ;
        $userInfo['avatar']=cmf_get_image_url($user['photo']);
        $userInfo['serial']=$user['serial'] ;
        $userInfo['name']=$user['name'];
        $userInfo['level']=$user['level'];
        $userInfo['work_time']=$user['work_time'];
        $userInfo['study_time']=$user['study_time'];
        $userInfo['use_time']=$user['use_time']??0;
        $userInfo['level_time']=$user['work_time']-$user['use_time'];
        $userInfo['status']=$this->getUserState($user['status'],$user['stage']);

        return $userInfo;

    }

    public function  getUserState($status,$stage){
        $name='';
        if ($status==2){
            switch ($stage){

                case 1:
                    $name='志愿者(待学习)';
                    break;
                case 2:
                    $name='志愿者(待实习)';
                    break;
                case 3:
                    $name='志愿者';
                    break;
                default:
                    $name='';
                    break;
            }
        }else{
            $name='非志愿者';
        }
        return $name;
    }




    /*
     * 获取用户状态
     * @param $userId
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getUserStatus($userId){
        $map['user_id']=$userId;
        $user=$this->where($map)->find();
        if (empty($user)){
            $return['code']=0;
            $return['remark']='待提交';
        }
        if ($user['status']==1){
            $return['code']=1;
            $return['remark']='审核中';
        }
        if ($user['status']==2){
            switch ($user['stage']){
                case 1:
                    $return['code']=2;
                    $return['remark']='志愿者(待学习)';
                    break;
                case 2:
                    $return['code']=3;
                    $return['remark']='志愿者(待实习)';
                    break;
                case 3:
                    $return['code']=4;
                    $return['remark']='志愿者';
                    break;
                default:
                    $return['code']='';
                    $return['remark']='';
                    break;
            }
//            $this->getUserStage()
//            if ($user['study_time']>=5 && $user['work_time']>10){
//                $userInfo['status']='志愿者';
//                $userInfo['user_num']=$userId.$user['create_time'];
//                $return['code']=4;
//                $return['remark']='志愿者';
//            }
//
//            if ($user['study_time']<5){
//                $userInfo['status']='志愿者(待学习)';
//                $userInfo['user_num']='';
//                $return['code']=2;
//                $return['remark']='志愿者(待学习)';
//            }
//
//            if ($user['study_time']>=5 && $user['work_time']<10){
//                $userInfo['status']='志愿者(待实习)';
//                $userInfo['user_num']='';
//
//                $return['code']=3;
//                $return['remark']='志愿者(待实习)';
//            }
        }
        if ($user['status']==3){
            $return['code']=-1;
            $return['remark']='不通过';
        }

        return $return;
    }

}