ClockController.php 5.6 KB
<?php
/**
 * Created by PhpStorm.
 * auther: sgj
 * Date: 2020/10/14
 * Time: 20:13
 */

namespace app\admin\controller;


use cmf\controller\AdminBaseController;

class ClockController extends AdminBaseController
{


    /**
     * @return mixed
     */
    public function index(){
        $param=$this->request->param();
        $map=[];
        $teamId=$this->getAdminTeamId();
        if ($teamId>0){
            $map['a.team_id']=$teamId;
        }
        if(!isset($param['status'])){
            $this->assign('status','');
        }elseif($param['status']==0){
            $this->assign('status',$param['status']);
            $map['c.status']=$param['status'];
        }else{
            $map['c.status']=$param['status'];
            $this->assign('status',$param['status']);
        }


        if(!empty($param['keyword'])){
            $map['c.activity_name|c.address']=['like',"%$param[keyword]%"];
        }

        $data= db('clock')->alias('c')
            ->field('v.name as user_name,v.photo,c.*')
            ->join('user u','u.id=c.user_id')
            ->join('volunteer v','v.user_id=c.user_id')
            ->join('activity a','a.id=c.activity_id')
            ->where($map)
            ->order('c.id desc')
            ->paginate();
        $data->appends($param);
        $list=$data->items();
        $this->assign([
            'data'=>$list,
            'page'=>$data->render(),
            'keyword'=>$param['keyword']??''
            ]);

        return $this->fetch();
    }

    public function addclock(){
        $param=input();
        $teamId=$this->getAdminTeamId();
        $map['j.id']=$param['id'];
        $data= db('join')->alias('j')
            ->field('v.name as user_name,v.photo,v.sex,v.birthday,v.move_phone,v.card_number as id_card,j.*,a.activity_name,a.start_time,a.long,a.lat,a.address_name')
            ->join('user u','u.id=j.user_id')
            ->join('volunteer v','v.user_id=j.user_id')
            ->join('activity a','a.id=j.activity_id')
            ->where($map)
            ->find();

        $this->assign('data',$data);
        return $this->fetch();
    }
    public function addclocks(){
        $param=input();
        $map['id']=$param['id'];
        $data= db('activity')->where($map)->find();
        $this->assign('data',$data);
        return $this->fetch();
    }
    public function  delete(){
        $param=input();
        $map['id']=$param['id'];
        $result= db('clock')->where($map)->delete();
        if ($result){
            $this->success('操作成功!');
        }else{
            $this->error('操作失败!');
        }
    }
    /**
     *提交信息
     */
    public function addpost(){
        $update= $this->request->param();
        $teamId=$this->getAdminTeamId();
        $result=db('clock')->insert($update);
        if ($result){
            if ($teamId>0){
                $this->addTeamLog($teamId,'打卡','添加打卡',$update);
        }
            $this->success('操作成功!');
        }else{
            $this->error('操作失败!');
        }

    }

   /**
     *提交信息
     */
    public function addPostMul(){
        $update= $this->request->param();
        $teamId=$this->getAdminTeamId();
        $start_time=strtotime(input('start_date'));
        $end_time=strtotime(input('end_date'));
        $time=$start_time;
        while ($time<=$end_time){
            $date[]=date('Y-m-d',$time);
            $time=$time+3600*24;
        }
        $user_ids=input('user_id');

        $user_array=explode($user_ids,',');

        unset($update['start_date']);
        unset($update['end_date']);
        foreach ($user_array as $k=>$v) {
            foreach ($date as $k1=>$v1) {
                $update['user_id']=$v;
                $update['date']   =$v1;
                $result=db('clock')->insert($update);
                if ($teamId>0){
                    $this->addTeamLog($teamId,'打卡','添加打卡',$update);
                }
            }
        }
        if ($result){
            $this->success('操作成功!');
        }else{
            $this->error('操作失败!');
        }

    }


    public function info(){
        $param=$this->request->param();
        $map=[];

    }


    /**
     * 编辑信息
     * @return mixed
     */
    public function edit(){
        $teamId=$this->getAdminTeamId();
        $id = input('id');
        $param = $this->request->param();
        $map['c.id'] = $id;
        $data = db('clock')->alias('c')
            ->field('v.name as user_name,v.photo,c.*')
            ->join('user u','u.id=c.user_id')
            ->join('volunteer v','v.user_id=c.user_id')
            ->where($map)
            ->find();
        if(empty($data['user_start'])){
            $data['user_start']='';
        }else{
            $data['user_start']=date('Y-m-d H:i:s',$data['user_start']);
        }

        if(empty($data['user_end'])){
            $data['user_end']='';
        }else{
            $data['user_end']=date('Y-m-d H:i:s',$data['user_end']);
        }

        $this->assign('data', $data);
        return $this->fetch();
    }

    /**
     * 添加信息
     * @return mixed
     */
    public function add(){
        return $this->fetch();
    }


    public function editPost(){
        $id = input('id');
        $teamId =$this->getAdminTeamId();
        $update= $this->request->param();
        $update['user_start']=strtotime($update['user_start']);
        $update['user_end']=strtotime($update['user_end']);
        $result=db('clock')->where('id',$id)->update($update);
        if ($teamId>0){
            $this->addTeamLog($teamId,'打卡','编辑打卡',$update);
        }
        $this->success('操作成功!');
    }

}