ClockController.php 3.2 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=[];
        if(!empty($param['keyword'])){
            $map['c.activity_name']=['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')
            ->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();
        $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')
            ->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 addpost(){
        $update= $this->request->param();
        $result=db('clock')->insert($update);
        if ($result){
            $this->success('操作成功!');
        }else{
            $this->error('操作失败!');
        }

    }


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

    }


    /**
     * 编辑信息
     * @return mixed
     */
    public function edit(){
        $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');
        $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);
        $this->success('操作成功!');
    }

}